using System; using System.Configuration; using System.Text.RegularExpressions; using DataModel.Helpers; using static System.Configuration.ConfigurationManager; namespace DataModel { /// /// Application configuration /// public class Config { /// /// Default query timeout (in seconds) /// 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; /// /// GIW connection string /// 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; /// /// JDE connection string /// 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; /// /// JDE query repo directory /// 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; /// /// Lot finder DB /// 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; /// /// CMS DB /// 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; /// /// CMS query repo directory /// 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; } }