Files
SystemX.Web/Projects/WebClient/Web.Operation/Program.cs

107 lines
2.4 KiB
C#

using Radzen;
using SystemX.Core.Config.Model;
using SystemX.Core.DB;
using SystemX.Core.Services;
using Web.Operation.Components;
using Web.Operation.Services;
using WebClient.Library.Config;
using WebClient.Library.Model;
string configDir = @"../../Config";
string configFileName = "WebClient.Operation.Config.json";
//raed log4net configs
if (LogXnet.ReadConfig(@$"{configDir}/LogXnetConfig.json") == true)
{
LogXnet.WriteLine("LogXnet Init Success");
}
else
{
Console.WriteLine("LogXnet Init Failed");
return;
}
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRadzenComponents();
//singleton
builder.Services.AddSingleton<ConfigService<WebClientConfig>>();
//scoped
builder.Services.AddScoped<PopupService>();
builder.Services.AddScoped<CPMetaService>();
//db
builder.Services.AddSingleton<DbContextProvider>(); // Generic µî·Ï
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
//config preload, auth set
ConfigService<WebClientConfig> preloadConfig = new ConfigService<WebClientConfig>();
if (preloadConfig.OpenConfig($@"{configDir}/{configFileName}") == true)
{
var config = preloadConfig.GetConfig();
}
else
{
LogXnet.WriteLine("Config Preload Load Error.", LogXLabel.Error);
return;
}
var app = builder.Build();
//read api config and set
string serverUrl = string.Empty;
var configService = app.Services.GetService<ConfigService<WebClientConfig>>();
bool isIIS = false;
if (configService?.OpenConfig($@"{configDir}/{configFileName}") == true)
{
LogXnet.WriteLine("WebClient Config Success.");
var apiConfig = ConfigService<WebClientConfig>.Config;
if (apiConfig != null)
{
serverUrl = $"{apiConfig?.Server?.Address}:{apiConfig?.Server?.Port}";
isIIS = apiConfig!.Server.IIS;
}
}
else
{
LogXnet.WriteLine("WebClient Config Error.");
return;
}
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
if (isIIS == true)
{
app.Run();
}
else
{
LogXnet.WriteLine($"Operation Url: {serverUrl}");
app.Run($"{serverUrl}");
}