diff --git a/Projects/DLL/SystemX.Core.dll b/Projects/DLL/SystemX.Core.dll index 12d2465..fc5c005 100644 Binary files a/Projects/DLL/SystemX.Core.dll and b/Projects/DLL/SystemX.Core.dll differ diff --git a/Projects/SystemX.Core/SystemX.Core/Services/DBContextProvider.cs b/Projects/SystemX.Core/SystemX.Core/Services/DBContextProvider.cs index 07a9e43..c15cada 100644 --- a/Projects/SystemX.Core/SystemX.Core/Services/DBContextProvider.cs +++ b/Projects/SystemX.Core/SystemX.Core/Services/DBContextProvider.cs @@ -12,7 +12,7 @@ namespace SystemX.Core.Services { public class DbContextProvider { - private Dictionary DBDictionary = new Dictionary(); + public Dictionary DBDictionary { get; private set; } = new Dictionary(); public void SetDBList(IList? DBList) { @@ -40,6 +40,6 @@ namespace SystemX.Core.Services } return null; - } + } } } diff --git a/Projects/WebClient/Web.Tra/Components/Pages/TRA.razor b/Projects/WebClient/Web.Tra/Components/Pages/TRA.razor index e4b4e2a..ed1e8a9 100644 --- a/Projects/WebClient/Web.Tra/Components/Pages/TRA.razor +++ b/Projects/WebClient/Web.Tra/Components/Pages/TRA.razor @@ -1,7 +1,12 @@ @page "/tra" +@using Web.Tra.Services +@inject CPXV2LogService CPXV2LogService

TRA

@code { - + protected override async Task OnInitializedAsync() + { + CPXV2LogService.Test(); + } } diff --git a/Projects/WebClient/Web.Tra/Program.cs b/Projects/WebClient/Web.Tra/Program.cs index b33edf1..36d8ffb 100644 --- a/Projects/WebClient/Web.Tra/Program.cs +++ b/Projects/WebClient/Web.Tra/Program.cs @@ -4,6 +4,7 @@ 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; @@ -26,6 +27,9 @@ var builder = WebApplication.CreateBuilder(args); //singleton builder.Services.AddSingleton>(); +//scoped +builder.Services.AddScoped(); + //db builder.Services.AddSingleton(); // Generic µî·Ï @@ -39,7 +43,7 @@ builder.Services.AddRadzenComponents(); ConfigService preloadConfig = new ConfigService(); if (preloadConfig.OpenConfig($@"{configDir}/{configFileName}") == true) { - var config = preloadConfig.GetConfig(); + var config = preloadConfig.GetConfig(); } else { @@ -74,18 +78,30 @@ if (configService?.OpenConfig($@"{configDir}/{configFileName}") == true) var longTermDB = getDbList.Where(x => x.Name.ToLower().Contains("longterm")).ToList(); List logDb = new List(); - foreach (var db in longTermDB.Select((value,index) => (value, index))) + foreach (var db in longTermDB) { - logDb.Add(new DataBase + try { - DBID = db.index, - DBName = db.value.Name, - IP = "127.0.0.1", - Port = 1433, - UserID = "Alis", - Password = "Kefico!@34", - DBContext = "" - }); + 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); diff --git a/Projects/WebClient/Web.Tra/Services/CPXV2LogService.cs b/Projects/WebClient/Web.Tra/Services/CPXV2LogService.cs new file mode 100644 index 0000000..d66f630 --- /dev/null +++ b/Projects/WebClient/Web.Tra/Services/CPXV2LogService.cs @@ -0,0 +1,113 @@ +using Azure.Core; +using Microsoft.EntityFrameworkCore; +using System.Data; +using SystemX.Core.DB; +using SystemX.Core.Services; +using WebClient.Library.Config; + +namespace Web.Tra.Services +{ + public class CPXV2LogService + { + private readonly IServiceScopeFactory _scopeFactory; + private readonly ConfigService? _configService; + + public CPXV2LogService(IServiceProvider serviceProvider, IServiceScopeFactory scopeFactory, ConfigService configService) + { + _scopeFactory = scopeFactory; + _configService = configService; + } + public async Task Test() + { + using (var scope = _scopeFactory.CreateScope()) + { + var provider = scope.ServiceProvider.GetRequiredService(); + using (var context = GetDBContext(provider, 1)) + { + if (context is not null) + { + } + } + } + + using (var scope = _scopeFactory.CreateScope()) + { + var provider = scope.ServiceProvider.GetRequiredService(); + using (var context = GetDBContext(provider, 2023)) + { + if (context is not null) + { + } + } + } + + using (var scope = _scopeFactory.CreateScope()) + { + var provider = scope.ServiceProvider.GetRequiredService(); + using (var context = GetDBContext(provider, 2024)) + { + if (context is not null) + { + } + } + } + } + + private T? GetDBContext(DbContextProvider provider, int dbID) where T : DbContext + { + var findDB = provider.DBDictionary.Keys.First(x => x.Contains(dbID.ToString())); + if(string.IsNullOrEmpty(findDB) == false) + { + if (provider.DBDictionary.TryGetValue(findDB, out var dbContext)) + { + return provider?.GetDBContext($"{dbContext.DBName}"); + } + } + + return null; + } + + //public async Task Request_SelectUniqueKey(Request_SelectUniqueKey request, string guid = "") + //{ + // Response_SelectUniqueKy response = new Response_SelectUniqueKy(); + + // if (request != null) + // { + // response.Identity = request.Identity; + // using (var scope = _scopeFactory.CreateScope()) + // { + // var provider = scope.ServiceProvider.GetRequiredService(); + // using (var context = GetUniqueKeyDBContext(provider, 1)) + // { + // if (context is not null) + // { + // try + // { + // using (var transaction = await context.CreateTransactionAsync(IsolationLevel.ReadUncommitted)) + // { + // var data = await context.tUniqueKeyStorages.AsNoTracking().FirstOrDefaultAsync(x => x.cIdentity == request.Identity); + // await context.CloseTransactionAsync(transaction); + // if (data != null) + // { + // response.Data1 = data.cData1; + // response.Data2 = data.cData2; + // response.Data3 = data.cData3; + // response.Data4 = data.cData4; + // response.Data5 = data.cData5; + // } + // } + // } + // catch (Exception e) + // { + // LogXnet.WriteLine($"Select Unique Key Transaction Error::{guid}", LogXLabel.Error); + // LogXnet.WriteLine(e); + // } + // } + // } + // } + // } + + // return response; + //} + } +}