public static void UpdatePermanentVariable(IVariable variable) { Configuration config = Configuration.GetNewInstance(); DataRow[] result = config.PermanentVariables.Select("Name='" + variable.Name + "'"); if (result.Length < 1) { config.PermanentVariables.AddPermanentVariableRow( variable.Name, variable.Expression ?? "", (int)variable.DataType, config.ParentRowPermanentVariables); } else if (result.Length == 1) { ((DataSets.Config.PermanentVariableRow)result[0]).DataValue = variable.Expression ?? ""; ((DataSets.Config.PermanentVariableRow)result[0]).DataType = (int)variable.DataType; } else { throw new ConfigurationException(ConfigurationException.ConfigurationIssue.ContentsInvalid, "Duplicate permanent variable rows encountered."); } Configuration.Save(config); }
private static void DeletePermanentVariable(string variableName) { Configuration config = Configuration.GetNewInstance(); DataRow[] result = config.PermanentVariables.Select("Name='" + variableName + "'"); if (result.Length != 1) { throw new ConfigurationException(ConfigurationException.ConfigurationIssue.ContentsInvalid); } result[0].Delete(); Configuration.Save(config); }
private static void LoadPermanentVariables() { lock (syncLock) { MemoryRegion.permanentVariables = new VariableCollection(); Configuration config = Configuration.GetNewInstance(); foreach (Config.PermanentVariableRow row in config.PermanentVariables) { DefinePermanentVariable(new PermanentVariable(row)); } } }
public static int GetEndpointVersion() { int endpointVersion = 0; try { Configuration configuration = Configuration.GetNewInstance(); string webServiceEndpointAddress = configuration.Settings.WebServiceEndpointAddress; int endIndex = webServiceEndpointAddress.IndexOf(".svc", StringComparison.OrdinalIgnoreCase); string withoutExtension = webServiceEndpointAddress.Substring(0, endIndex); int vIndex = withoutExtension.LastIndexOf("V", StringComparison.OrdinalIgnoreCase); string version = withoutExtension.Substring(vIndex + 1); endpointVersion = int.Parse(version); } catch { } return(endpointVersion); }
private static bool EnsureLogFileExists() { Configuration config = Configuration.GetNewInstance(); try { // If the log file name is not availabe, create it. if (string.IsNullOrEmpty(logFilePath)) { string dateStamp = DateTime.Now.ToString(); dateStamp = dateStamp.Replace(StringLiterals.FORWARD_SLASH, StringLiterals.UNDER_SCORE); dateStamp = dateStamp.Replace(StringLiterals.BACKWARD_SLASH, StringLiterals.UNDER_SCORE); dateStamp = dateStamp.Replace(StringLiterals.COLON, StringLiterals.UNDER_SCORE); dateStamp = dateStamp.Replace(StringLiterals.SPACE, StringLiterals.UNDER_SCORE); string logFileName = "EpiInfo_Log_" + dateStamp + ".txt"; config = Configuration.GetNewInstance(); logFilePath = Path.Combine(config.Directories.LogDir, logFileName); } if (Directory.Exists(config.Directories.LogDir) == false) { Directory.CreateDirectory(config.Directories.LogDir); } // if log file doesn't exist, create the file. if (!File.Exists(logFilePath)) { FileStream stream = File.Create(logFilePath); stream.Close(); } return(true); } catch (Exception) { // Ignore any exceptions for now. TODO return(false); } }
/// <summary> /// Creates a globally unique identifier for a filepath. /// </summary> /// <param name="filePath">Pathname of file.</param> /// <returns>Globally unique identifier.</returns> public static Guid GetFileGuid(string filePath) { Guid guid; byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(filePath.ToLowerInvariant()); byte[] pathHash; Configuration config = Configuration.GetNewInstance(); if (config.TextEncryptionModule != null && !string.IsNullOrEmpty(config.TextEncryptionModule.FileName)) { SHA256 shaM = new SHA256Managed(); pathHash = shaM.ComputeHash(data).Take(16).ToArray(); } else { MD5 md5 = new MD5CryptoServiceProvider(); pathHash = md5.ComputeHash(data); } guid = new Guid(pathHash); return(guid); }
/// <summary> /// Constructor. /// </summary> /// <param name="row">Permanent variable <see cref="System.Data.DataRow"/>.</param> public PermanentVariable(Config.PermanentVariableRow row) : base(row.Name, (DataType)row.DataType, VariableType.Permanent) { config = Configuration.GetNewInstance(); this.Expression = row.DataValue; }
//public string Name { get; set; } /// <summary> /// Constructor. /// </summary> /// <param name="name">Variable name.</param> /// <param name="dataType">Variable data type enumeration.</param> public PermanentVariable(string name, DataType dataType) : base(name, dataType, VariableType.Permanent) { config = Configuration.GetNewInstance(); }
public Template() { templatesPath = Configuration.GetNewInstance().Directories.Templates; }