4using System.Threading.Tasks;
6using Microsoft.AspNetCore.Hosting;
7using Microsoft.AspNetCore.Server.Kestrel.Core;
8using Microsoft.Extensions.Configuration;
9using Microsoft.Extensions.DependencyInjection;
10using Microsoft.Extensions.Hosting;
11using Microsoft.Extensions.Logging;
48 IOManager = ioManager ??
throw new ArgumentNullException(nameof(ioManager));
53#pragma warning disable CA1506
54 public async ValueTask<IServer?>
CreateServer(
string[] args,
string? updatePath, CancellationToken cancellationToken)
56 ArgumentNullException.ThrowIfNull(args);
59 if (!args.Any(arg => arg.Contains(
"hostBuilder:reloadConfigOnChange", StringComparison.OrdinalIgnoreCase))
60 && String.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(
"hostBuilder__reloadConfigOnChange")))
63 args =
new string[oldArgs.Length + 1];
64 Array.Copy(oldArgs, args, oldArgs.Length);
65 args[oldArgs.Length] =
"--hostBuilder:reloadConfigOnChange=false";
68 const string AppSettingsRelocationKey = $
"--{AppSettings}-base-path=";
70 var appsettingsRelativeBasePathArgument = args.FirstOrDefault(arg => arg.StartsWith(AppSettingsRelocationKey, StringComparison.Ordinal));
72 if (appsettingsRelativeBasePathArgument !=
null)
73 basePath =
IOManager.
ResolvePath(appsettingsRelativeBasePathArgument[AppSettingsRelocationKey.Length..]);
79 Environment.SetEnvironmentVariable($
"{InternalConfiguration.Section}__{nameof(InternalConfiguration.AppSettingsBasePath)}", basePath);
81 IHostBuilder CreateDefaultBuilder() => Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
82 .ConfigureAppConfiguration((context, builder) =>
84 builder.SetBasePath(basePath);
86 builder.AddYamlFile($
"{AppSettings}.yml", optional:
true, reloadOnChange:
false)
87 .AddYamlFile($
"{AppSettings}.{context.HostingEnvironment.EnvironmentName}.yml", optional:
true, reloadOnChange:
false);
91 var environmentJsonConfig = builder.Sources[2];
92 var envConfig = builder.Sources[3];
97#error Validate this monstrosity works on current .NET
99 IConfigurationSource? cmdLineConfig;
100 IConfigurationSource baseYmlConfig, environmentYmlConfig;
101 if (args.Length == 0)
103 cmdLineConfig = null;
104 baseYmlConfig = builder.Sources[4];
105 environmentYmlConfig = builder.Sources[5];
109 cmdLineConfig = builder.Sources[4];
110 baseYmlConfig = builder.Sources[5];
111 environmentYmlConfig = builder.Sources[6];
114 builder.Sources[2] = baseYmlConfig;
115 builder.Sources[3] = environmentJsonConfig;
116 builder.Sources[4] = environmentYmlConfig;
117 builder.Sources[5] = envConfig;
119 if (cmdLineConfig !=
null)
121 builder.Sources[6] = cmdLineConfig;
125 var setupWizardHostBuilder = CreateDefaultBuilder()
129 using (var setupHost = setupWizardHostBuilder.Build())
132 await setupHost.RunAsync(cancellationToken);
136 postSetupServices.
Logger.LogInformation(
"Shutting down due to only running setup wizard.");
141 var hostBuilder = CreateDefaultBuilder()
142 .ConfigureWebHost(webHostBuilder =>
144 .UseKestrel(kestrelOptions =>
146 var serverPortProvider = kestrelOptions.ApplicationServices.GetRequiredService<
IServerPortProvider>();
147 kestrelOptions.ListenAnyIP(
148 serverPortProvider.HttpApiPort,
149 listenOptions => listenOptions.Protocols = HttpProtocols.Http1);
152 kestrelOptions.Limits.MaxRequestLineSize = 8400;
157 .SuppressStatusMessages(
true)
159 TimeSpan.FromMinutes(
162 if (updatePath !=
null)
163 hostBuilder.UseContentRoot(
167 return new Server(hostBuilder, updatePath);
169#pragma warning restore CA1506
uint RestartTimeoutMinutes
The timeout minutes for restarting the server.
SetupWizardMode SetupWizardMode
The SetupWizardMode.
Implementation of IServerFactory.
IIOManager IOManager
The IIOManager for the IServerFactory.
readonly IAssemblyInformationProvider assemblyInformationProvider
The IAssemblyInformationProvider for the ServerFactory.
async ValueTask< IServer?> CreateServer(string[] args, string? updatePath, CancellationToken cancellationToken)
Create a IServer. A ValueTask<TResult> resulting in a new IServer if it should be run,...
const string AppSettings
Name of the appsettings file.
Provides access to the server's HttpApiPort.
Interface for using filesystems.
string ResolvePath()
Retrieve the full path of the current working directory.
string GetDirectoryName(string path)
Gets the directory portion of a given path .
Set of objects needed to configure an Core.Application.
GeneralConfiguration GeneralConfiguration
The Configuration.GeneralConfiguration.
ILogger< TLoggerType > Logger
The ILogger.
SetupWizardMode
Determines if the SetupWizard will run.