Skip to content

Commit

Permalink
Merge pull request #905 from dmorgan3405/add_ability_to_set_site_id
Browse files Browse the repository at this point in the history
Added ability to optionally pass in SiteId to configure IIS Site.
  • Loading branch information
forki committed Aug 13, 2015
2 parents 9d3ca81 + 94e9e65 commit ac24498
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 23 deletions.
65 changes: 44 additions & 21 deletions src/app/Fake.IIS/IISHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,26 @@ let AddBindingToSite (bindingInformation : string) (bindingProtocol : string) (
| true -> ()
) manager

let Site (name : string) protocol binding (physicalPath : string) appPool (mgr : ServerManager) =
let mutable site = mgr.Sites.[name]
match (site) with
| null -> site <- mgr.Sites.Add(name, protocol, binding, physicalPath)
| _ ->
SetPhysicalPath "/" physicalPath name (Some mgr)
AddBindingToSite binding protocol name (Some mgr)

site.ApplicationDefaults.ApplicationPoolName <- appPool
site
let commit (mgr : ServerManager) = mgr.CommitChanges()

let Application (virtualPath : string) (physicalPath : string) (site : Site) (mgr : ServerManager) =
let app = site.Applications.[virtualPath]
match (app) with
| null -> site.Applications.Add(virtualPath, physicalPath)
| _ -> app.VirtualDirectories.[0].PhysicalPath <- physicalPath; app
type ISiteConfig = interface
abstract name : string
abstract binding : string
abstract physicalPath : string
abstract appPool : string
abstract id : int64 option
abstract protocol : string
end

let commit (mgr : ServerManager) = mgr.CommitChanges()
type SiteConfig(name : string, binding:string, physicalPath:string, appPool:string, ?id: int64, ?protocol:string) = class
interface ISiteConfig with
member this.name = name
member this.binding = binding
member this.physicalPath = physicalPath
member this.appPool = appPool
member this.id = id
member this.protocol = defaultArg protocol "http"
end

type ApplicationPoolConfig(name : string, ?runtime:string, ?allow32on64:bool, ?identity : ProcessModelIdentityType) = class
member this.name = name
Expand All @@ -67,10 +69,26 @@ type ApplicationPoolConfig(name : string, ?runtime:string, ?allow32on64:bool, ?i
end

let private MergeAppPoolProperties (appPool:ApplicationPool)(config:ApplicationPoolConfig) =
appPool.Enable32BitAppOnWin64 <- config.allow32on64
appPool.ManagedRuntimeVersion <- config.runtime
appPool.ProcessModel.IdentityType <- config.identity
appPool
appPool.Enable32BitAppOnWin64 <- config.allow32on64
appPool.ManagedRuntimeVersion <- config.runtime
appPool.ProcessModel.IdentityType <- config.identity
appPool

let private MergeSiteProperties(site:Site)(config:ISiteConfig) =
site.ApplicationDefaults.ApplicationPoolName <- config.appPool
match (config.id) with
| Some id -> site.Id <- id
| None -> ()
site

let Site (config:ISiteConfig) (mgr : ServerManager) =
let mutable site = mgr.Sites.[config.name]
match (site) with
| null -> site <- mgr.Sites.Add(config.name, config.protocol, config.binding, config.physicalPath)
| _ ->
SetPhysicalPath "/" config.physicalPath config.name (Some mgr)
AddBindingToSite config.binding config.protocol config.name (Some mgr)
MergeSiteProperties site config

let ApplicationPool (config: ApplicationPoolConfig) (mgr : ServerManager) =
let appPool = mgr.ApplicationPools.[config.name]
Expand All @@ -81,6 +99,12 @@ let ApplicationPool (config: ApplicationPoolConfig) (mgr : ServerManager) =
| _ ->
MergeAppPoolProperties appPool config

let Application (virtualPath : string) (physicalPath : string) (site : Site) (mgr : ServerManager) =
let app = site.Applications.[virtualPath]
match (app) with
| null -> site.Applications.Add(virtualPath, physicalPath)
| _ -> app.VirtualDirectories.[0].PhysicalPath <- physicalPath; app

let IIS (site : ServerManager -> Site)
(appPool : ServerManager -> ApplicationPool)
(app : (Site -> ServerManager -> Application) option) =
Expand Down Expand Up @@ -123,4 +147,3 @@ let deleteApplicationPool (name : string) =
if appPool <> null then
appPool.Delete()
commit mgr

6 changes: 4 additions & 2 deletions src/app/Fake.IIS/Script.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ let appPool = "fake.appPool"
let port = ":8081:"
let vdir = "/fakevdir"
let appDir = @"C:\Users"
let path = @"C:\inetpub\wwwroot"

UnlockSection "system.webServer/security/authentication/anonymousauthentication"

let site = SiteConfig(siteName, port, path, appPool)
let dotNetFourAppPool = ApplicationPoolConfig(siteName, allow32on64 = true, identity = Administration.ProcessModelIdentityType.LocalSystem)
let dotNetTwoAppPool = ApplicationPoolConfig(siteName, runtime = "v2.0", allow32on64 = true)

(IIS
(Site siteName "http" port @"C:\inetpub\wwwroot" appPool)
(Site site)
(ApplicationPool dotNetFourAppPool)
(Some(Application vdir appDir)))

(IIS
(Site siteName "http" port @"C:\inetpub\wwwroot" appPool)
(Site site)
(ApplicationPool dotNetTwoAppPool)
(Some(Application "/vdir2" @"C:\temp")))

Expand Down

0 comments on commit ac24498

Please sign in to comment.