2020-01-31 20:15:07 -06:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2019-05-08 20:34:17 -05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2018-02-21 19:29:23 -06:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2020-11-27 21:52:52 -06:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2023-04-05 09:54:57 -05:00
|
|
|
|
using SharedLibraryCore.Configuration;
|
2018-04-08 13:48:40 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2019-07-27 08:18:49 -05:00
|
|
|
|
using WebfrontCore.Middleware;
|
2018-02-21 19:29:23 -06:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
2018-04-08 13:48:40 -05:00
|
|
|
|
public static IManager Manager;
|
2023-04-05 09:54:57 -05:00
|
|
|
|
private static IWebHost _webHost;
|
2018-04-08 13:48:40 -05:00
|
|
|
|
|
2023-04-05 09:54:57 -05:00
|
|
|
|
public static IServiceProvider InitializeServices(Action<IServiceCollection> registerDependenciesAction, string bindUrl)
|
2018-02-21 19:29:23 -06:00
|
|
|
|
{
|
2023-04-05 09:54:57 -05:00
|
|
|
|
_webHost = BuildWebHost(registerDependenciesAction, bindUrl);
|
|
|
|
|
Manager = _webHost.Services.GetRequiredService<IManager>();
|
|
|
|
|
return _webHost.Services;
|
2018-04-08 01:44:42 -05:00
|
|
|
|
}
|
2018-03-09 02:01:12 -06:00
|
|
|
|
|
2023-04-05 09:54:57 -05:00
|
|
|
|
public static Task GetWebHostTask(CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var config = _webHost.Services.GetRequiredService<ApplicationConfiguration>();
|
|
|
|
|
Manager.MiddlewareActionHandler.Register(null,
|
|
|
|
|
new CustomCssAccentMiddlewareAction("#007ACC", "#fd7e14", config.WebfrontPrimaryColor,
|
|
|
|
|
config.WebfrontSecondaryColor), "custom_css_accent");
|
|
|
|
|
|
|
|
|
|
return _webHost?.RunAsync(cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IWebHost BuildWebHost(Action<IServiceCollection> registerDependenciesAction, string bindUrl)
|
2018-04-09 22:33:42 -05:00
|
|
|
|
{
|
|
|
|
|
return new WebHostBuilder()
|
2018-04-08 16:50:58 -05:00
|
|
|
|
#if DEBUG
|
|
|
|
|
.UseContentRoot(Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\..\", "WebfrontCore")))
|
|
|
|
|
#else
|
2018-10-06 15:31:05 -05:00
|
|
|
|
.UseContentRoot(SharedLibraryCore.Utilities.OperatingDirectory)
|
2018-04-08 16:50:58 -05:00
|
|
|
|
#endif
|
2023-04-05 09:54:57 -05:00
|
|
|
|
.UseUrls(bindUrl)
|
2018-04-08 01:44:42 -05:00
|
|
|
|
.UseKestrel()
|
2023-04-05 09:54:57 -05:00
|
|
|
|
.ConfigureServices(registerDependenciesAction)
|
2018-02-21 19:29:23 -06:00
|
|
|
|
.UseStartup<Startup>()
|
|
|
|
|
.Build();
|
2018-04-09 22:33:42 -05:00
|
|
|
|
}
|
2018-02-21 19:29:23 -06:00
|
|
|
|
}
|
|
|
|
|
}
|