Initial commit: JDE Scoping Tool migration project
Set up repository with legacy .NET Framework 4.8 source (OLD/), new .NET 10 Blazor solution (NEW/), OpenSpec specifications, documentation, and project configuration.
This commit is contained in:
Executable
+71
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Data.SqlClient;
|
||||
using DDTek.Oracle;
|
||||
using NLog;
|
||||
|
||||
namespace DataModel.Db
|
||||
{
|
||||
public class DbManager
|
||||
{
|
||||
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
private static readonly Dictionary<string, DbConnectionString> connectionStrings = new Dictionary<string, DbConnectionString>();
|
||||
|
||||
|
||||
public static void Initialize(List<DbConnectionString> dbConnectionStrings)
|
||||
{
|
||||
foreach (DbConnectionString dbConnectionString in dbConnectionStrings)
|
||||
{
|
||||
connectionStrings.Add(dbConnectionString.Name, dbConnectionString);
|
||||
}
|
||||
}
|
||||
|
||||
public static DbConnection GetConnection(string name)
|
||||
{
|
||||
if (!connectionStrings.TryGetValue(name, out var connectionString))
|
||||
{
|
||||
throw new Exception($"DB Connection definition for '{name}' not found.");
|
||||
}
|
||||
|
||||
DbConnection connection = connectionString.GetConnection();
|
||||
|
||||
try
|
||||
{
|
||||
connection.Open();
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
string errorMessage = $"Failed to open DB connection to '{name}': {error.Message}.";
|
||||
logger.Error(errorMessage);
|
||||
throw new Exception(errorMessage, error);
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
|
||||
public enum DbTypes { SqlServer, Oracle }
|
||||
|
||||
public class DbConnectionString
|
||||
{
|
||||
public string Environment { get; set; }
|
||||
public DbTypes DbType { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ConnectionString { get; set; }
|
||||
|
||||
public DbConnection GetConnection()
|
||||
{
|
||||
switch (DbType)
|
||||
{
|
||||
case DbTypes.Oracle:
|
||||
return new OracleConnection(ConnectionString);
|
||||
case DbTypes.SqlServer:
|
||||
return new SqlConnection(ConnectionString);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user