public async Task ConfigureAsync(string webSiteName, string webAppPath, Action <Application> configureAction, CancellationToken token = default(CancellationToken)) { if (!TryFindWebSite(webSiteName, out var webSite)) { using (var block = handle.Context.Output.WriteBlock()) { block.Write("WebSite ", ConsoleColor.DarkRed); block.Write(webSiteName, ConsoleColor.Red); block.WriteLine(" was not found!", ConsoleColor.DarkRed); } throw new Exception($"WebSite '{webSiteName}' was not found!"); } if (!TryFind(webSite, webAppPath, out var webApp)) { webSite.Applications.Add(webAppPath, DefaultPhysicalPath); await handle.CommitChangesAsync(token); if (!TryFindWebSite(webSiteName, out webSite)) { using (var block = handle.Context.Output.WriteBlock()) { block.Write("WebSite ", ConsoleColor.DarkRed); block.Write(webSiteName, ConsoleColor.Red); block.WriteLine(" was not found!", ConsoleColor.DarkRed); } throw new Exception($"WebSite '{webSiteName}' was not found!"); } if (!TryFind(webSite, webAppPath, out webApp)) { using (var block = handle.Context.Output.WriteBlock()) { block.Write("Unable to create Web Application ", ConsoleColor.DarkRed); block.Write(webAppPath, ConsoleColor.Red); block.WriteLine("!", ConsoleColor.DarkRed); } throw new Exception($"Unable to create Web Application '{webAppPath}'!"); } using (var block = handle.Context.Output.WriteBlock()) { block.Write("Created new Web Application ", ConsoleColor.DarkBlue); block.Write(webAppPath, ConsoleColor.Blue); block.Write(" under WebSite ", ConsoleColor.DarkBlue); block.Write(webSiteName, ConsoleColor.Blue); block.WriteLine(".", ConsoleColor.DarkBlue); } } configureAction(webApp); await handle.CommitChangesAsync(token); using (var block = handle.Context.Output.WriteBlock()) { block.Write("Web Application ", ConsoleColor.DarkGreen); block.Write(webAppPath, ConsoleColor.Green); block.WriteLine(" configured successfully.", ConsoleColor.DarkGreen); } }
public async Task ConfigureAsync(string websiteName, int port, Action <Site> configureAction, CancellationToken token = default(CancellationToken)) { if (!TryFind(websiteName, out var webSite)) { handle.Context.WriteTagLine($"Creating IIS WebSite '{websiteName}'...", ConsoleColor.White); try { handle.Server.Sites.Add(websiteName, DefaultPhysicalPath, port); await handle.CommitChangesAsync(token); } catch (Exception error) { handle.Context.WriteErrorBlock($"Failed to create IIS WebSite '{websiteName}'!", error.UnfoldMessages()); throw; } if (!TryFind(websiteName, out webSite)) { handle.Context.WriteErrorBlock($"Failed to create IIS WebSite '{websiteName}'!"); throw new Exception($"Failed to create IIS WebSite '{websiteName}'!"); } handle.Context.WriteTagLine($"Created IIS WebSite '{websiteName}' successfully.", ConsoleColor.White); } try { handle.Context.WriteTagLine($"Configuring IIS WebSite '{websiteName}'...", ConsoleColor.White); // TODO: Set Port //webSite.Bindings.FirstOrDefault()?.po configureAction(webSite); await handle.CommitChangesAsync(token); handle.Context.WriteTagLine($"Configured IIS WebSite '{websiteName}' successfully.", ConsoleColor.White); } catch (Exception error) { handle.Context.WriteErrorBlock($"Failed to configure IIS WebSite '{websiteName}'!", error.UnfoldMessages()); throw; } }
public async Task ConfigureAsync(string appPoolName, Action <ApplicationPool> configureAction, CancellationToken token = default(CancellationToken)) { if (!TryFind(appPoolName, out var appPool)) { handle.Context.WriteTagLine($"Creating IIS Application Pool '{appPoolName}'...", ConsoleColor.White); try { handle.Server.ApplicationPools.Add(appPoolName); await handle.CommitChangesAsync(token); } catch (Exception error) { handle.Context.WriteErrorBlock($"Failed to create IIS Application Pool '{appPoolName}'!", error.UnfoldMessages()); throw; } if (!TryFind(appPoolName, out appPool)) { handle.Context.WriteErrorBlock($"Failed to create IIS Application Pool '{appPoolName}'!"); throw new Exception($"Unable to create IIS Application Pool '{appPoolName}'!"); } handle.Context.WriteTagLine($"Created IIS Application Pool '{appPoolName}' successfully.", ConsoleColor.White); } try { handle.Context.WriteTagLine($"Configuring IIS Application Pool '{appPoolName}'...", ConsoleColor.White); configureAction(appPool); await handle.CommitChangesAsync(token); handle.Context.WriteTagLine($"Configured IIS Application Pool '{appPoolName}' successfully.", ConsoleColor.White); } catch (Exception error) { handle.Context.WriteErrorBlock($"Failed to configure IIS Application Pool '{appPoolName}'!", error.UnfoldMessages()); throw; } }