/// <summary> /// Creates the or update application pool. /// </summary> /// <param name="applicationPool">The application pool.</param> /// <returns></returns> private void CreateOrUpdateApplicationPool(ApplicationPool applicationPool) { using (var serverManager = new ServerManager()) { var existingPool = serverManager.ApplicationPools.FirstOrDefault(pool => pool.Name == applicationPool.Name) ?? serverManager.ApplicationPools.Add(applicationPool.Name); existingPool.ManagedRuntimeVersion = applicationPool.ManagedRuntimeVersion; existingPool.AutoStart = true; existingPool.Enable32BitAppOnWin64 = applicationPool.Enable32BitAppOnWin64; existingPool.ProcessModel.IdleTimeout = new TimeSpan(0, 0, applicationPool.IdleTimeout); ProcessModelIdentityType identityType; if (ProcessModelIdentityType.TryParse(applicationPool.Identity, true, out identityType)) { existingPool.ProcessModel.IdentityType = identityType; } serverManager.CommitChanges(); } }
static void Main(string[] args) { SetConsoleCtrlHandler(ConsoleCtrlCheck, true); var siteName = ""; var port = -1; var framework = "v4.0"; var showHelp = false; var stop = false; var identityType = ProcessModelIdentityType.ApplicationPoolIdentity; string warmupURL = null; var waitForSiteToStop = true; var p = new OptionSet { { "n|name=", "name of the IIS site", v => siteName = v }, { "w|warmup=", "The URL to use for warmup (without host & port)", v => warmupURL = v }, { "s|stop", "stop the IIS site", v => stop = true }, { "p|port=", "port used by the iis site", (int v) => port = v }, { "f|framework=", "framework version used by the application pool: v2.0 or v4.0 (default)", v => framework = v }, { "h|help", "show this message and exit", v => showHelp = true }, { "d|debug", "output debug messages", v => debug = true }, { "x|exit", "exit without waiting for the site to stop (but after warmup", v => waitForSiteToStop = false }, { "i|identity=", "The IdentityType to use for Application pool", i => { if (!ProcessModelIdentityType.TryParse(i, true, out identityType)) { Console.Error.WriteLine("Cannot parse identity: {0}", i); throw new ArgumentException("identity"); } } } }; try { p.Parse(args); } catch (Exception) { p.WriteOptionDescriptions(Console.Out); return; } if (showHelp || siteName == "") { p.WriteOptionDescriptions(Console.Out); return; } if (stop) { StopSite(siteName); return; } if (port < 0) { p.WriteOptionDescriptions(Console.Out); return; } string currentPath = Directory.GetCurrentDirectory(); _newSite = CreateSite(siteName, framework, currentPath, port, identityType); if (warmupURL != null) { if (!Warmup(port, warmupURL)) { StopSite(siteName); Environment.Exit(1); } } if (waitForSiteToStop) { WatchSite(_newSite); } Environment.Exit(0); }