using Microsoft.EntityFrameworkCore.Storage; using Microsoft.JSInterop; 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>(); //scoped builder.Services.AddScoped(); builder.Services.AddScoped(); //db builder.Services.AddSingleton(); // Generic µî·Ï // Add services to the container. builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); //config preload, auth set ConfigService preloadConfig = new ConfigService(); 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>(); bool isIIS = false; if (configService?.OpenConfig($@"{configDir}/{configFileName}") == true) { LogXnet.WriteLine("WebClient Config Success."); var apiConfig = ConfigService.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(); dbProvider?.SetDBList(apiConfig?.DataBase); //log db list var dbcontext = dbProvider.GetDBContext(1); var getDbList = await dbcontext.ExecuteStoredProcedureAsync("spGetDBList"); var longTermDB = getDbList.Where(x => x.Name.ToLower().Contains("longterm")).ToList(); List logDb = new List(); 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() .AddInteractiveServerRenderMode(); if (isIIS == true) { app.Run(); } else { LogXnet.WriteLine($"Operation Url: {serverUrl}"); app.Run($"{serverUrl}"); }