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;
///
/// 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;
}
}