Files
Joseph Doherty 26ff8d9b4f 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.
2026-01-02 07:43:29 -05:00

217 lines
7.7 KiB
C#
Executable File

using System;
using System.Configuration;
using System.Text.RegularExpressions;
using DataModel.Helpers;
using static System.Configuration.ConfigurationManager;
namespace DataModel
{
/// <summary>
/// Application configuration
/// </summary>
public class Config
{
/// <summary>
/// Default query timeout (in seconds)
/// </summary>
public static int QueryTimeout
{
get
{
if (!_queryTimeout.HasValue)
{
try
{
string queryTimeoutStr = ConfigurationManager.AppSettings["querytimeout"];
_queryTimeout = int.Parse(queryTimeoutStr);
}
catch (Exception error)
{
throw new Exception("Failed to parse query timeout", error);
}
}
return _queryTimeout.Value;
}
}
private static int? _queryTimeout;
/// <summary>
/// GIW connection string
/// </summary>
public static string GIWCS
{
get
{
if (string.IsNullOrEmpty(_giwCS))
{
try
{
//Extract configured connection string
string encryptedCS = ConnectionStrings["GIW"].ConnectionString;
//Extract encrypted password and decrypt it
MatchCollection matches = Regex.Matches(encryptedCS, @"Password=([^\;;]+ {0,1})");
string encyptedPassword = matches[0].Groups[1].Value;
string decryptedPassword = EncryptionHelper.Decrypt(encyptedPassword, "JDESCOPETOOL");
//Update connection string with decyrpted password
_giwCS = encryptedCS.Replace(encyptedPassword, decryptedPassword);
}
catch (Exception error)
{
throw new Exception("Failed to parse GIW connection string", error);
}
}
return _giwCS;
}
}
private static string _giwCS;
/// <summary>
/// JDE connection string
/// </summary>
public static string JDECS
{
get
{
if (string.IsNullOrEmpty(_jdeCS))
{
try
{
//Extract configured connection string
string encryptedCS = ConnectionStrings["JDE"].ConnectionString;
//Extract encrypted password and decrypt it
MatchCollection matches = Regex.Matches(encryptedCS, @"Password=([^\;;]+ {0,1})");
string encyptedPassword = matches[0].Groups[1].Value;
string decryptedPassword = EncryptionHelper.Decrypt(encyptedPassword, "JDESCOPETOOL");
//Update connection string with decyrpted password
_jdeCS = encryptedCS.Replace(encyptedPassword, decryptedPassword);
}
catch (Exception error)
{
throw new Exception("Failed to parse JDE connection string", error);
}
}
return _jdeCS;
}
}
private static string _jdeCS;
/// <summary>
/// JDE query repo directory
/// </summary>
public static string JDEQueryRepo
{
get
{
if (string.IsNullOrEmpty(_jdeQueryRepo))
{
try
{
//Get query repo directory
_jdeQueryRepo = ConfigurationManager.AppSettings["JDE_QUERY_REPO"];
}
catch (Exception error)
{
throw new Exception("Failed to parse JDE query repo directory", error);
}
}
return _jdeQueryRepo;
}
}
private static string _jdeQueryRepo;
/// <summary>
/// Lot finder DB
/// </summary>
public static string LotFinderDBCS
{
get
{
if (string.IsNullOrEmpty(_lotFinderDBCS))
{
try
{
//Extract configured connection string
string encryptedCS = ConnectionStrings["LotFinderDB"].ConnectionString;
//Extract encrypted password and decrypt it
MatchCollection matches = Regex.Matches(encryptedCS, @"Password=([^\;;]+ {0,1})");
string encyptedPassword = matches[0].Groups[1].Value;
string decryptedPassword = EncryptionHelper.Decrypt(encyptedPassword, "JDESCOPETOOL");
//Update connection string with decyrpted password
_lotFinderDBCS = encryptedCS.Replace(encyptedPassword, decryptedPassword);
}
catch (Exception error)
{
throw new Exception("Failed to parse LotFinderDB connection string", error);
}
}
return _lotFinderDBCS;
}
}
private static string _lotFinderDBCS;
/// <summary>
/// CMS DB
/// </summary>
public static string CMSCS
{
get
{
if (string.IsNullOrEmpty(_cmsCS))
{
try
{
//Extract configured connection string
string encryptedCS = ConnectionStrings["CMS"].ConnectionString;
//Extract encrypted password and decrypt it
MatchCollection matches = Regex.Matches(encryptedCS, @"Password=([^\;;]+ {0,1})");
string encyptedPassword = matches[0].Groups[1].Value;
string decryptedPassword = EncryptionHelper.Decrypt(encyptedPassword, "JDESCOPETOOL");
//Update connection string with decyrpted password
_cmsCS = encryptedCS.Replace(encyptedPassword, decryptedPassword);
}
catch (Exception error)
{
throw new Exception("Failed to parse CMS connection string", error);
}
}
return _cmsCS;
}
}
private static string _cmsCS;
/// <summary>
/// CMS query repo directory
/// </summary>
public static string CMSQueryRepo
{
get
{
if (string.IsNullOrEmpty(_cmsQueryRepo))
{
try
{
//Get query repo directory
_cmsQueryRepo = ConfigurationManager.AppSettings["CMS_QUERY_REPO"];
}
catch (Exception error)
{
throw new Exception("Failed to parse CMS query repo directory", error);
}
}
return _cmsQueryRepo;
}
}
private static string _cmsQueryRepo;
}
}