[성현모] TRA GetDBContext 기능 추가
This commit is contained in:
Binary file not shown.
@ -12,7 +12,7 @@ namespace SystemX.Core.Services
|
|||||||
{
|
{
|
||||||
public class DbContextProvider
|
public class DbContextProvider
|
||||||
{
|
{
|
||||||
private Dictionary<string, DataBase> DBDictionary = new Dictionary<string, DataBase>();
|
public Dictionary<string, DataBase> DBDictionary { get; private set; } = new Dictionary<string, DataBase>();
|
||||||
|
|
||||||
public void SetDBList(IList<DataBase>? DBList)
|
public void SetDBList(IList<DataBase>? DBList)
|
||||||
{
|
{
|
||||||
@ -40,6 +40,6 @@ namespace SystemX.Core.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,12 @@
|
|||||||
@page "/tra"
|
@page "/tra"
|
||||||
|
@using Web.Tra.Services
|
||||||
|
@inject CPXV2LogService CPXV2LogService
|
||||||
|
|
||||||
<h3>TRA</h3>
|
<h3>TRA</h3>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
CPXV2LogService.Test();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ using SystemX.Core.Config.Model;
|
|||||||
using SystemX.Core.DB;
|
using SystemX.Core.DB;
|
||||||
using SystemX.Core.Services;
|
using SystemX.Core.Services;
|
||||||
using Web.Tra.Components;
|
using Web.Tra.Components;
|
||||||
|
using Web.Tra.Services;
|
||||||
using WebClient.Library.Config;
|
using WebClient.Library.Config;
|
||||||
using WebClient.Library.Model;
|
using WebClient.Library.Model;
|
||||||
|
|
||||||
@ -26,6 +27,9 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
//singleton
|
//singleton
|
||||||
builder.Services.AddSingleton<ConfigService<WebClientConfig>>();
|
builder.Services.AddSingleton<ConfigService<WebClientConfig>>();
|
||||||
|
|
||||||
|
//scoped
|
||||||
|
builder.Services.AddScoped<CPXV2LogService>();
|
||||||
|
|
||||||
//db
|
//db
|
||||||
builder.Services.AddSingleton<DbContextProvider>(); // Generic <20><><EFBFBD><EFBFBD>
|
builder.Services.AddSingleton<DbContextProvider>(); // Generic <20><><EFBFBD><EFBFBD>
|
||||||
|
|
||||||
@ -39,7 +43,7 @@ builder.Services.AddRadzenComponents();
|
|||||||
ConfigService<WebClientConfig> preloadConfig = new ConfigService<WebClientConfig>();
|
ConfigService<WebClientConfig> preloadConfig = new ConfigService<WebClientConfig>();
|
||||||
if (preloadConfig.OpenConfig($@"{configDir}/{configFileName}") == true)
|
if (preloadConfig.OpenConfig($@"{configDir}/{configFileName}") == true)
|
||||||
{
|
{
|
||||||
var config = preloadConfig.GetConfig();
|
var config = preloadConfig.GetConfig();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -74,18 +78,30 @@ if (configService?.OpenConfig($@"{configDir}/{configFileName}") == true)
|
|||||||
var longTermDB = getDbList.Where(x => x.Name.ToLower().Contains("longterm")).ToList();
|
var longTermDB = getDbList.Where(x => x.Name.ToLower().Contains("longterm")).ToList();
|
||||||
|
|
||||||
List<DataBase> logDb = new List<DataBase>();
|
List<DataBase> logDb = new List<DataBase>();
|
||||||
foreach (var db in longTermDB.Select((value,index) => (value, index)))
|
foreach (var db in longTermDB)
|
||||||
{
|
{
|
||||||
logDb.Add(new DataBase
|
try
|
||||||
{
|
{
|
||||||
DBID = db.index,
|
var year = db.Name.Split("_")[1];
|
||||||
DBName = db.value.Name,
|
if(Int32.TryParse(year, out var index))
|
||||||
IP = "127.0.0.1",
|
{
|
||||||
Port = 1433,
|
logDb.Add(new DataBase
|
||||||
UserID = "Alis",
|
{
|
||||||
Password = "Kefico!@34",
|
DBID = index,
|
||||||
DBContext = ""
|
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);
|
dbProvider.SetDBList(logDb);
|
||||||
|
|||||||
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