142 lines
3.9 KiB
C#
142 lines
3.9 KiB
C#
using Microsoft.EntityFrameworkCore.Storage;
|
|
using Radzen;
|
|
using SystemX.Core.Config.Model;
|
|
using SystemX.Core.DB;
|
|
using SystemX.Core.Services;
|
|
using Web.Tra.Components;
|
|
using Web.Tra.Services;
|
|
using WebClient.Library.Config;
|
|
using WebClient.Library.Model;
|
|
|
|
string configDir = @"../../Config";
|
|
string configFileName = "WebClient.Tra.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<CPXV2LogService>();
|
|
builder.Services.AddScoped<PopupService>();
|
|
|
|
//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;
|
|
|
|
using (var scoped = app.Services.CreateScope())
|
|
{
|
|
var dbProvider = scoped.ServiceProvider.GetRequiredService<DbContextProvider>();
|
|
dbProvider?.SetDBList(apiConfig?.DataBase);
|
|
|
|
//log db list
|
|
var dbcontext = dbProvider.GetDBContext<CPXV2>(1);
|
|
var getDbList = await dbcontext.ExecuteStoredProcedureAsync<CPXV2, DBList>("spGetDBList");
|
|
var longTermDB = getDbList.Where(x => x.Name.ToLower().Contains("longterm")).ToList();
|
|
|
|
List<DataBase> logDb = new List<DataBase>();
|
|
foreach (var db in longTermDB)
|
|
{
|
|
try
|
|
{
|
|
var year = db.Name.Split("_")[1];
|
|
if(Int32.TryParse(year, out var index))
|
|
{
|
|
logDb.Add(new DataBase
|
|
{
|
|
DBID = index,
|
|
DBName = db.Name,
|
|
IP = "127.0.0.1",
|
|
Port = 1433,
|
|
UserID = "Alis",
|
|
Password = "Kefico!@34",
|
|
DBContext = ""
|
|
});
|
|
}
|
|
}
|
|
catch(Exception e)
|
|
{
|
|
LogXnet.WriteLine("DB Register Exception");
|
|
LogXnet.WriteLine(e);
|
|
}
|
|
}
|
|
|
|
dbProvider.SetDBList(logDb);
|
|
}
|
|
}
|
|
}
|
|
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}");
|
|
}
|