2020-01-31 21:15:07 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2019-05-08 21:34:17 -04:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2020-11-27 22:52:52 -05:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2023-04-05 10:54:57 -04:00
|
|
|
|
using SharedLibraryCore.Configuration;
|
2018-04-08 14:48:40 -04:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
2018-04-08 14:48:40 -04:00
|
|
|
|
public static IManager Manager;
|
2023-04-05 10:54:57 -04:00
|
|
|
|
private static IWebHost _webHost;
|
2018-04-08 14:48:40 -04:00
|
|
|
|
|
2023-04-05 10:54:57 -04:00
|
|
|
|
public static IServiceProvider InitializeServices(Action<IServiceCollection> registerDependenciesAction, string bindUrl)
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
2023-04-05 10:54:57 -04:00
|
|
|
|
_webHost = BuildWebHost(registerDependenciesAction, bindUrl);
|
|
|
|
|
Manager = _webHost.Services.GetRequiredService<IManager>();
|
|
|
|
|
return _webHost.Services;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
}
|
2018-03-09 03:01:12 -05:00
|
|
|
|
|
2023-04-05 10:54:57 -04:00
|
|
|
|
public static Task GetWebHostTask(CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
return _webHost?.RunAsync(cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IWebHost BuildWebHost(Action<IServiceCollection> registerDependenciesAction, string bindUrl)
|
2018-04-09 23:33:42 -04:00
|
|
|
|
{
|
|
|
|
|
return new WebHostBuilder()
|
2018-04-08 17:50:58 -04:00
|
|
|
|
#if DEBUG
|
|
|
|
|
.UseContentRoot(Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\..\", "WebfrontCore")))
|
|
|
|
|
#else
|
2018-10-06 16:31:05 -04:00
|
|
|
|
.UseContentRoot(SharedLibraryCore.Utilities.OperatingDirectory)
|
2018-04-08 17:50:58 -04:00
|
|
|
|
#endif
|
2023-04-05 10:54:57 -04:00
|
|
|
|
.UseUrls(bindUrl)
|
2023-05-30 15:58:17 -04:00
|
|
|
|
.UseKestrel(cfg =>
|
|
|
|
|
{
|
|
|
|
|
cfg.Limits.MaxConcurrentConnections =
|
|
|
|
|
int.Parse(Environment.GetEnvironmentVariable("MaxConcurrentRequests") ?? "1");
|
|
|
|
|
cfg.Limits.KeepAliveTimeout = TimeSpan.FromSeconds(30);
|
|
|
|
|
})
|
2023-04-05 10:54:57 -04:00
|
|
|
|
.ConfigureServices(registerDependenciesAction)
|
2018-02-21 20:29:23 -05:00
|
|
|
|
.UseStartup<Startup>()
|
|
|
|
|
.Build();
|
2018-04-09 23:33:42 -04:00
|
|
|
|
}
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}
|
|
|
|
|
}
|