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; //} } }