[성현모] TRA GetDBContext 기능 추가
This commit is contained in:
113
Projects/WebClient/Web.Tra/Services/CPXV2LogService.cs
Normal file
113
Projects/WebClient/Web.Tra/Services/CPXV2LogService.cs
Normal file
@ -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<WebClientConfig>? _configService;
|
||||
|
||||
public CPXV2LogService(IServiceProvider serviceProvider, IServiceScopeFactory scopeFactory, ConfigService<WebClientConfig> configService)
|
||||
{
|
||||
_scopeFactory = scopeFactory;
|
||||
_configService = configService;
|
||||
}
|
||||
public async Task Test()
|
||||
{
|
||||
using (var scope = _scopeFactory.CreateScope())
|
||||
{
|
||||
var provider = scope.ServiceProvider.GetRequiredService<DbContextProvider>();
|
||||
using (var context = GetDBContext<CPXV2>(provider, 1))
|
||||
{
|
||||
if (context is not null)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using (var scope = _scopeFactory.CreateScope())
|
||||
{
|
||||
var provider = scope.ServiceProvider.GetRequiredService<DbContextProvider>();
|
||||
using (var context = GetDBContext<CPXV2Log>(provider, 2023))
|
||||
{
|
||||
if (context is not null)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using (var scope = _scopeFactory.CreateScope())
|
||||
{
|
||||
var provider = scope.ServiceProvider.GetRequiredService<DbContextProvider>();
|
||||
using (var context = GetDBContext<CPXV2Log>(provider, 2024))
|
||||
{
|
||||
if (context is not null)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private T? GetDBContext<T>(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<T>($"{dbContext.DBName}");
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
//public async Task<Response_SelectUniqueKy> 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<DbContextProvider>();
|
||||
// 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;
|
||||
//}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user