Big changes
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of the IConfigurationFile interface for Json file format
|
||||
/// </summary>
|
||||
public class JsonConfigurationFile : ConfigurationFileBase
|
||||
{
|
||||
|
||||
private Dictionary<string, Dictionary<string, string>> _data;
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public JsonConfigurationFile(string fileName)
|
||||
: base(fileName)
|
||||
{
|
||||
if (_configurationType != ConfigurationFileType.JSON)
|
||||
{
|
||||
throw new ArgumentException("Expecting JSON file configuration type");
|
||||
}
|
||||
|
||||
if (!_fileInfo.Exists)
|
||||
{
|
||||
using (File.Create(_fileInfo.FullName)) { }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads all available keys from given section from current configuration file
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <returns></returns>
|
||||
public override List<string> ReadAllKeys(string section)
|
||||
{
|
||||
string json = File.ReadAllText(_fileName);
|
||||
if (!string.IsNullOrEmpty(json))
|
||||
{
|
||||
_data = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(json);
|
||||
}
|
||||
else
|
||||
{
|
||||
_data = new Dictionary<string, Dictionary<string, string>>();
|
||||
}
|
||||
return _data.ContainsKey(section) ? _data[section].Keys.ToList() : new List<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads all available sections from current configuration file
|
||||
/// </summary>
|
||||
/// <returns>list of sections</returns>
|
||||
public override List<string> ReadAllSections()
|
||||
{
|
||||
string json = File.ReadAllText(_fileName);
|
||||
if (!string.IsNullOrEmpty(json))
|
||||
{
|
||||
_data = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(json);
|
||||
}
|
||||
else
|
||||
{
|
||||
_data = new Dictionary<string, Dictionary<string, string>>();
|
||||
}
|
||||
return _data.Keys.ToList();
|
||||
}
|
||||
|
||||
public override List<T> ReadList<T>(string section, string key, IList<T> defList = null)
|
||||
{
|
||||
return ReadValue(section, key, defList).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads a single value in json format
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defValue"></param>
|
||||
/// <returns>configuration value</returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public override T ReadValue<T>(string section, string key, T defValue = default)
|
||||
{
|
||||
string json = File.ReadAllText(_fileName);
|
||||
if (!string.IsNullOrEmpty(json))
|
||||
{
|
||||
_data = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(json);
|
||||
}
|
||||
else
|
||||
{
|
||||
_data = new Dictionary<string, Dictionary<string, string>>();
|
||||
}
|
||||
|
||||
if (_data.ContainsKey(section) && _data[section].ContainsKey(key))
|
||||
{
|
||||
return JsonConvert.DeserializeObject<T>(_data[section][key]);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteValue(section, key, defValue);
|
||||
return defValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads a single value in json format
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns>configuration value</returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public override string ReadValue(string section, string key)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// writes a list of values of any generic type
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="listToWrite"></param>
|
||||
public override void WriteList<T>(string section, string key, IList<T> listToWrite)
|
||||
{
|
||||
WriteValue(section, key, listToWrite);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// writes a single value
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="lineToWrite"></param>
|
||||
public override void WriteValue<T>(string section, string key, T lineToWrite)
|
||||
{
|
||||
string json = File.ReadAllText(_fileName);
|
||||
if (!string.IsNullOrEmpty(json))
|
||||
{
|
||||
_data = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(json);
|
||||
}
|
||||
else
|
||||
{
|
||||
_data = new Dictionary<string, Dictionary<string, string>>();
|
||||
}
|
||||
|
||||
if (!_data.ContainsKey(section))
|
||||
{
|
||||
_data[section] = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
_data[section][key] = JsonConvert.SerializeObject(lineToWrite);
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(_fileName, false))
|
||||
{
|
||||
writer.WriteLine(JsonConvert.SerializeObject(_data));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
// Ignore Spelling: Yaml
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
public class YamlConfigurationFile : ConfigurationFileBase
|
||||
{
|
||||
|
||||
//private Dictionary<string, Dictionary<string, string>> _data;
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public YamlConfigurationFile(string fileName)
|
||||
: base(fileName)
|
||||
{
|
||||
if (_configurationType != ConfigurationFileType.OTHER)
|
||||
{
|
||||
throw new ArgumentException("Expecting YAML file configuration type");
|
||||
}
|
||||
|
||||
if (!_fileInfo.Exists)
|
||||
{
|
||||
using (File.Create(_fileInfo.FullName)) { }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads all available keys from given section from current configuration file
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <returns></returns>
|
||||
public override List<string> ReadAllKeys(string section)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads all available sections from current configuration file
|
||||
/// </summary>
|
||||
/// <returns>list of sections</returns>
|
||||
public override List<string> ReadAllSections()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override List<T> ReadList<T>(string section, string key, IList<T> defList = null)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads a single value in yaml format
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defValue"></param>
|
||||
/// <returns>configuration value</returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public override T ReadValue<T>(string section, string key, T defValue = default)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads a single value in json format
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns>configuration value</returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public override string ReadValue(string section, string key)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// writes a list of values of any generic type
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="listToWrite"></param>
|
||||
public override void WriteList<T>(string section, string key, IList<T> listToWrite)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// writes a single value
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="lineToWrite"></param>
|
||||
public override void WriteValue<T>(string section, string key, T lineToWrite)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
public class YamlConfigurationFileFactory : ConfigurationFileFactoryBase
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public override IConfigurationFile CreateConfigurationFile(string fileName)
|
||||
{
|
||||
return new YamlConfigurationFile(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// main class to be instantiated when working with configuration files
|
||||
/// </summary>
|
||||
public class ConfigurationFile : ConfigurationFileBase
|
||||
{
|
||||
/// <summary>
|
||||
/// concrete implementation reference
|
||||
/// </summary>
|
||||
protected IConfigurationFile _configurationFile;
|
||||
|
||||
/// <summary>
|
||||
/// Raytheon.Configuration will support INI and XML file formats.
|
||||
/// For other formats have to use designated constructor
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
public ConfigurationFile(string fileName)
|
||||
: base(fileName)
|
||||
{
|
||||
if (!_fileInfo.Exists)
|
||||
{
|
||||
throw new Exception($"Can't find file: {fileName}");
|
||||
}
|
||||
var factory = GetFactory();
|
||||
_configurationFile = factory.GetConfigurationFile(fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// extension constructor, for other types based on the provided factory
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="factory"></param>
|
||||
public ConfigurationFile(string fileName, ConfigurationFileFactoryBase factory)
|
||||
: base(fileName)
|
||||
{
|
||||
if (!_fileInfo.Exists)
|
||||
{
|
||||
throw new Exception($"Can't find file: {fileName}");
|
||||
}
|
||||
_configurationFile = factory.GetConfigurationFile(fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// extension constructor, for other types based on provided type
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="type"></param>
|
||||
public ConfigurationFile(string fileName, string type)
|
||||
: base(fileName)
|
||||
{
|
||||
if (!_fileInfo.Exists)
|
||||
{
|
||||
throw new Exception($"Can't find file: {fileName}");
|
||||
}
|
||||
ConfigurationFileFactory factory = new(type);
|
||||
_configurationFile = factory.GetConfigurationFile(fileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns a factory based on file extension
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
private static ConfigurationFileFactoryBase GetFactory()
|
||||
{
|
||||
ConfigurationFileType configurationType = ConfigurationTypeFromFileExtension(_fileInfo.Extension);
|
||||
|
||||
ConfigurationFileFactoryBase factory = configurationType switch
|
||||
{
|
||||
ConfigurationFileType.INI => new IniConfigurationFileFactory(),
|
||||
ConfigurationFileType.XML => new XmlConfigurationFileFactory(),
|
||||
ConfigurationFileType.JSON => new JsonConfigurationFileFactory(),
|
||||
ConfigurationFileType.TOML => new TomlConfigurationFileFactory(),
|
||||
_ => throw new ArgumentException($"Configuration Type ({configurationType}) not supported by Configuration Manager"),
|
||||
};
|
||||
return factory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads all keys from a section of an ini file.
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <returns></returns>
|
||||
public override List<string> ReadAllKeys(string section)
|
||||
{
|
||||
return _configurationFile.ReadAllKeys(section);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of all of the sections in the ini file.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override List<string> ReadAllSections()
|
||||
{
|
||||
return _configurationFile.ReadAllSections();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads a list of values from configuration file
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defList"></param>
|
||||
/// <returns></returns>
|
||||
public override List<T> ReadList<T>(string section, string key, IList<T> defList = null)
|
||||
{
|
||||
return _configurationFile.ReadList<T>(section, key, defList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads a value from configuration file
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defValue"></param>
|
||||
/// <returns></returns>
|
||||
public override T ReadValue<T>(string section, string key, T defValue = default)
|
||||
{
|
||||
return _configurationFile.ReadValue<T>(section, key, defValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads a single value in json format
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns>configuration value</returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public override string ReadValue(string section, string key)
|
||||
{
|
||||
return _configurationFile.ReadValue(section, key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// writes a list of values to configuration file
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="listToWrite"></param>
|
||||
public override void WriteList<T>(string section, string key, IList<T> listToWrite)
|
||||
{
|
||||
_configurationFile.WriteList<T>(section, key, listToWrite);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write string value
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="lineToWrite"></param>
|
||||
public override void WriteValue<T>(string section, string key, T lineToWrite)
|
||||
{
|
||||
_configurationFile.WriteValue(section, key, lineToWrite);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public abstract class ConfigurationFileBase : IConfigurationFile
|
||||
{
|
||||
/// <summary>
|
||||
/// configuration file info
|
||||
/// </summary>
|
||||
protected static FileInfo _fileInfo;
|
||||
|
||||
/// <summary>
|
||||
/// configuration file name
|
||||
/// </summary>
|
||||
protected string _fileName;
|
||||
|
||||
/// <summary>
|
||||
/// returns file name
|
||||
/// </summary>
|
||||
public string FileName => _fileName;
|
||||
|
||||
/// <summary>
|
||||
/// configuration type derived based on file extension
|
||||
/// or by the type of the IConfigurationFile implementation
|
||||
/// </summary>
|
||||
protected ConfigurationFileType _configurationType;
|
||||
|
||||
/// <summary>
|
||||
/// returns configuration type
|
||||
/// </summary>
|
||||
public ConfigurationFileType ConfigurationFileType => _configurationType;
|
||||
|
||||
/// <summary>
|
||||
/// constructor that takes file name
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public ConfigurationFileBase(string fileName)
|
||||
{
|
||||
_fileInfo = new FileInfo(fileName);
|
||||
_fileName = _fileInfo.FullName;
|
||||
_configurationType = ConfigurationTypeFromFileExtension(_fileInfo.Extension);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns supported configuration type enum based on the file type
|
||||
/// </summary>
|
||||
/// <param name="fileExtension"></param>
|
||||
/// <returns></returns>
|
||||
protected static ConfigurationFileType ConfigurationTypeFromFileExtension(string fileExtension)
|
||||
{
|
||||
if (string.IsNullOrEmpty(fileExtension))
|
||||
{
|
||||
return ConfigurationFileType.OTHER;
|
||||
}
|
||||
return fileExtension.ToLower() switch
|
||||
{
|
||||
".ini" => ConfigurationFileType.INI,
|
||||
".xml" => ConfigurationFileType.XML,
|
||||
".json" => ConfigurationFileType.JSON,
|
||||
".toml" => ConfigurationFileType.TOML,
|
||||
".yaml" => ConfigurationFileType.YAML,
|
||||
_ => ConfigurationFileType.OTHER,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads all keys from a section of configuration file.
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <returns></returns>
|
||||
public abstract List<string> ReadAllKeys(string section);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of all of the sections in the configuration file.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public abstract List<string> ReadAllSections();
|
||||
|
||||
/// <summary>
|
||||
/// reads a list of values from configuration file
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defList"></param>
|
||||
/// <returns></returns>
|
||||
public abstract List<T> ReadList<T>(string section, string key, IList<T> defList = null);
|
||||
|
||||
/// <summary>
|
||||
/// reads a single value from configuration file by section and key
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defValue"></param>
|
||||
/// <returns></returns>
|
||||
public abstract T ReadValue<T>(string section, string key, T defValue = default);
|
||||
|
||||
/// <summary>
|
||||
/// reads a single value from configuration file by section and key
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public abstract string ReadValue(string section, string key);
|
||||
|
||||
/// <summary>
|
||||
/// writes a list of values to configuration file
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="listToWrite"></param>
|
||||
public abstract void WriteList<T>(string section, string key, IList<T> listToWrite);
|
||||
|
||||
/// <summary>
|
||||
/// Write a single value to a given section by key
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="lineToWrite"></param>
|
||||
public abstract void WriteValue<T>(string section, string key, T lineToWrite);
|
||||
|
||||
/// <summary>
|
||||
/// checks if the value exists in configuration file
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
virtual public bool ValueExists(string section, string key)
|
||||
{
|
||||
return ReadAllKeys(section).Contains(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,472 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
// Ignore Spelling: Deserialize
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.Serialization;
|
||||
using System.Xml.XPath;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// for serializing and deserializing class types
|
||||
/// </summary>
|
||||
internal static class XmlSerializerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// deserializes XML type into an object
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static T Deserialize<T>(this string value)
|
||||
{
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(T));
|
||||
using(StringReader reader = new StringReader(value))
|
||||
{
|
||||
return (T)serializer.Deserialize(reader);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// extension method to serialize XML type
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static string Serialize<T>(this T value)
|
||||
{
|
||||
if(value == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
XmlSerializer xmlSerializer = new(typeof(T));
|
||||
|
||||
using(StringWriter stringWriter = new())
|
||||
{
|
||||
using(XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { Indent = true }))
|
||||
{
|
||||
xmlSerializer.Serialize(xmlWriter, value);
|
||||
return stringWriter.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// extension method to serialize XML type without a namespace
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static string SerializeNoNamespace<T>(this T value)
|
||||
{
|
||||
if(value == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
XmlSerializerNamespaces emptyNamespaces = new(new[] { XmlQualifiedName.Empty });
|
||||
XmlSerializer serializer = new(value.GetType());
|
||||
XmlWriterSettings settings = new()
|
||||
{
|
||||
Indent = true,
|
||||
OmitXmlDeclaration = true
|
||||
};
|
||||
|
||||
using(StringWriter stream = new())
|
||||
{
|
||||
using(XmlWriter writer = XmlWriter.Create(stream, settings))
|
||||
{
|
||||
serializer.Serialize(writer, value, emptyNamespaces);
|
||||
return stream.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// type conversion utility with a special case for enums
|
||||
/// </summary>
|
||||
public static class TypeConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// special rule for enumeration when converting a type
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static T ChangeType<T>(object value)
|
||||
{
|
||||
return typeof(T).IsEnum ? (T)Enum.Parse(typeof(T), value.ToString()) : (T)ChangeType(typeof(T), value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// convert type with TypeDescriptor
|
||||
/// </summary>
|
||||
/// <param name="t"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public static object ChangeType(Type t, object value)
|
||||
{
|
||||
System.ComponentModel.TypeConverter tc = TypeDescriptor.GetConverter(t);
|
||||
return tc.ConvertFrom(value);
|
||||
}
|
||||
/// <summary>
|
||||
/// register type with the type descriptor for later conversion
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TC"></typeparam>
|
||||
public static void RegisterTypeConverter<T, TC>() where TC : System.ComponentModel.TypeConverter
|
||||
{
|
||||
TypeDescriptor.AddAttributes(typeof(T), new TypeConverterAttribute(typeof(TC)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Helper class contains extension functions for reading types other than strings from configuration,
|
||||
/// as well as reading lists of values
|
||||
/// </summary>
|
||||
public static class ConfigurationHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// template function for reading different types from configuration
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <returns></returns>
|
||||
public static T GetConfigurationValue<T>(this IConfiguration configuration, string section, string key, T defaultValue)
|
||||
{
|
||||
Type defaultType = typeof(T);
|
||||
if(!defaultType.IsValueType && defaultType != typeof(string))
|
||||
{
|
||||
string tmpResult = configuration.GetConfigurationValue(section, key, string.Empty);
|
||||
|
||||
if(!string.IsNullOrEmpty(tmpResult))
|
||||
{
|
||||
return tmpResult.Deserialize<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
configuration.SetConfigurationValue(section, key, defaultValue);
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string tmpResult = configuration.GetConfigurationValue(section, key, defaultValue.ToString());
|
||||
return !string.IsNullOrEmpty(tmpResult) ? TypeConverter.ChangeType<T>(tmpResult) : default;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets configuration value.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="valueToWrite"></param>
|
||||
public static void SetConfigurationValue<T>(this IConfiguration configuration, string section, string key, T valueToWrite)
|
||||
{
|
||||
Type defaultType = typeof(T);
|
||||
if(!defaultType.IsValueType && defaultType != typeof(string))
|
||||
{
|
||||
configuration.SetConfigurationValue(section, key, valueToWrite.SerializeNoNamespace());
|
||||
}
|
||||
else
|
||||
{
|
||||
configuration.SetConfigurationValue(section, key, valueToWrite.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns multi-value result (list of T) from configuration
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <returns></returns>
|
||||
public static List<T> GetConfigurationListValue<T>(this IConfiguration configuration, string section, string key, IList<T> defaultValue)
|
||||
{
|
||||
string tmpResult = configuration.GetXmlConfiguration(section);
|
||||
if(string.IsNullOrEmpty(tmpResult) || !ContainsSection(tmpResult, key))
|
||||
{
|
||||
SetConfigurationListValue(configuration, section, key, defaultValue);
|
||||
return new List<T>(defaultValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
var stringRes = BuildElementListFromXml(tmpResult, key);
|
||||
|
||||
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
|
||||
|
||||
List<T> result = new List<T>();
|
||||
|
||||
foreach(string item in stringRes)
|
||||
{
|
||||
if(string.IsNullOrEmpty(item))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if(item.TrimStart().StartsWith("<"))
|
||||
{
|
||||
result.Add(item.Deserialize<T>());
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(TypeConverter.ChangeType<T>(item));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes configuration list of values.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="configuration"></param>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="listToWrite"></param>
|
||||
public static void SetConfigurationListValue<T>(this IConfiguration configuration, string section, string key, IList<T> listToWrite)
|
||||
{
|
||||
StringBuilder xmlStr = new();
|
||||
string data = configuration.GetXmlConfiguration(section);
|
||||
if(ContainsSection(data, $"{key}s"))
|
||||
{
|
||||
xmlStr.Append($"<{key}s>");
|
||||
foreach(var item in listToWrite)
|
||||
{
|
||||
xmlStr.Append($"<{key}>");
|
||||
xmlStr.Append(item.ToString());
|
||||
xmlStr.Append($"</{key}>");
|
||||
}
|
||||
xmlStr.Append($"</{key}s>");
|
||||
configuration.SetXmlConfiguration(section, xmlStr.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlStr.Append($"<{key}>");
|
||||
foreach(var item in listToWrite)
|
||||
{
|
||||
xmlStr.Append(item.SerializeNoNamespace());
|
||||
}
|
||||
xmlStr.Append($"</{key}>");
|
||||
|
||||
XElement xElement = new XElement(key, XElement.Parse(xmlStr.ToString()));
|
||||
|
||||
if(string.IsNullOrEmpty(data))
|
||||
{
|
||||
data = $"<XmlConfiguration name=\"{section}\"></XmlConfiguration>";
|
||||
}
|
||||
|
||||
XDocument doc = XDocument.Parse(data);
|
||||
XElement existing = doc.Descendants(key).FirstOrDefault();
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
existing.ReplaceWith(xElement);
|
||||
|
||||
var reader = doc.CreateReader();
|
||||
reader.MoveToContent();
|
||||
string innerXml = reader.ReadInnerXml();
|
||||
|
||||
configuration.SetXmlConfiguration(section, innerXml);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
doc.Root.Add(xElement.FirstNode);
|
||||
var reader = doc.CreateReader();
|
||||
reader.MoveToContent();
|
||||
string outerXml = reader.ReadOuterXml();
|
||||
|
||||
configuration.SetXmlConfiguration(section, outerXml);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// returns values from XML section converted to string list
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
private static List<string> BuildElementListFromXml(string data, string key)
|
||||
{
|
||||
XElement doc = XElement.Parse(data);
|
||||
IEnumerable<XElement> xmlMessages;
|
||||
|
||||
if(ContainsSection(data, $"{key}s"))
|
||||
{
|
||||
xmlMessages = from m in doc.Elements($"{key}s").Elements(key)
|
||||
select m;
|
||||
|
||||
var messages = xmlMessages.Select(x => x.Value);
|
||||
return messages?.ToList();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlMessages = from m in doc.Elements($"{key}").Elements()
|
||||
select m;
|
||||
|
||||
List<string> result = new();
|
||||
|
||||
foreach(var item in xmlMessages)
|
||||
{
|
||||
var reader = item.CreateReader();
|
||||
reader.MoveToContent();
|
||||
result.Add(reader.ReadOuterXml());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ContainsSection(string xmlString, string sectionName)
|
||||
{
|
||||
if(string.IsNullOrEmpty(xmlString))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
XDocument doc = XDocument.Parse(xmlString);
|
||||
return doc.Descendants(sectionName).Any();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// From XML configuration file reads all sections under IniConfiguration root
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<string> GetAvailableConfigSections(string fileName)
|
||||
{
|
||||
List<string> sections = new();
|
||||
|
||||
FileInfo fileInfo = new(fileName);
|
||||
if(!fileInfo.Exists)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
XDocument xdocument = XDocument.Load(fileInfo.FullName);
|
||||
if(xdocument != null)
|
||||
{
|
||||
var configurationSection = xdocument.Root.Element("IniConfiguration");
|
||||
if(configurationSection != null && configurationSection.HasElements)
|
||||
{
|
||||
var sectionElements = configurationSection.Elements();
|
||||
sections.AddRange(from item in sectionElements
|
||||
let name = item?.FirstAttribute?.Value
|
||||
where !string.IsNullOrEmpty(name)
|
||||
select name);
|
||||
}
|
||||
|
||||
configurationSection = xdocument.Root.Element("XmlConfigurations");
|
||||
if(configurationSection != null && configurationSection.HasElements)
|
||||
{
|
||||
var sectionElements = configurationSection.Elements();
|
||||
sections.AddRange(from item in sectionElements
|
||||
let name = item?.FirstAttribute?.Value
|
||||
where !string.IsNullOrEmpty(name)
|
||||
select name);
|
||||
}
|
||||
}
|
||||
|
||||
return sections;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// From XML configuration file reads all keys from config sections under IniConfiguration root
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static List<string> GetAvailableConfigSectionKeys(string fileName, string sectionName)
|
||||
{
|
||||
List<string> sections = new();
|
||||
|
||||
FileInfo fileInfo = new(fileName);
|
||||
if(!fileInfo.Exists)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
XDocument xdocument = XDocument.Load(fileInfo.FullName);
|
||||
if(xdocument != null)
|
||||
{
|
||||
var configurationSection = xdocument.XPathSelectElement($"//IniConfiguration//section[@name='{sectionName}']");
|
||||
if(configurationSection != null && configurationSection.HasElements)
|
||||
{
|
||||
var sectionElements = configurationSection.Elements();
|
||||
sections.AddRange(from item in sectionElements
|
||||
let name = item?.FirstAttribute?.Value
|
||||
where !string.IsNullOrEmpty(name)
|
||||
select name);
|
||||
}
|
||||
|
||||
configurationSection = xdocument.XPathSelectElement($"//XmlConfigurations//XmlConfiguration[@name='{sectionName}']");
|
||||
if(configurationSection != null && configurationSection.HasElements)
|
||||
{
|
||||
var sectionElements = configurationSection.Elements();
|
||||
sections.AddRange(from item in sectionElements
|
||||
let name = item?.Name
|
||||
where name != null
|
||||
select name.ToString());
|
||||
}
|
||||
}
|
||||
return sections;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
using System;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Generic configuration factory based on the type
|
||||
/// </summary>
|
||||
public class ConfigurationFileFactory : ConfigurationFileFactoryBase
|
||||
{
|
||||
private readonly string _type;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
public ConfigurationFileFactory(string type)
|
||||
{
|
||||
_type = type;
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
public override IConfigurationFile CreateConfigurationFile(string fileName)
|
||||
{
|
||||
Type type = Type.GetType(_type);
|
||||
if (type == null)
|
||||
{
|
||||
throw new InvalidOperationException($"File format not supported with {_type} package.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return (IConfigurationFile)Activator.CreateInstance(type, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration file factory base class for the Factory Method pattern
|
||||
/// </summary>
|
||||
public abstract class ConfigurationFileFactoryBase
|
||||
{
|
||||
/// <summary>
|
||||
/// template method for creating configuration file
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public abstract IConfigurationFile CreateConfigurationFile(string fileName);
|
||||
|
||||
/// <summary>
|
||||
/// creates configuration file based on the overwrite of the
|
||||
/// concrete implementation of the CreateConfigurationFile method
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public IConfigurationFile GetConfigurationFile(string fileName)
|
||||
{
|
||||
IConfigurationFile configurationFile = CreateConfigurationFile(fileName);
|
||||
return configurationFile;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// IniConfigurationFile factory class
|
||||
/// </summary>
|
||||
public class IniConfigurationFileFactory : ConfigurationFileFactoryBase
|
||||
{
|
||||
/// <summary>
|
||||
/// IniConfigurationFile factory method
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public override IConfigurationFile CreateConfigurationFile(string fileName)
|
||||
{
|
||||
return new IniConfigurationFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
using System;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// JsonConfigurationFile factory class
|
||||
/// </summary>
|
||||
public class JsonConfigurationFileFactory : ConfigurationFileFactoryBase
|
||||
{
|
||||
/// <summary>
|
||||
/// JsonConfigurationFile factory method
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
public override IConfigurationFile CreateConfigurationFile(string fileName)
|
||||
{
|
||||
Type jsonType = Type.GetType("Raytheon.Common.JsonConfigurationFile, Raytheon.Configuration.Json");
|
||||
if (jsonType == null)
|
||||
{
|
||||
throw new InvalidOperationException($"JSON file format supported with Raytheon.Configuration.Json package.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return (IConfigurationFile)Activator.CreateInstance(jsonType, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
using System;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// TomlConfigurationFile factory class
|
||||
/// </summary>
|
||||
public class TomlConfigurationFileFactory : ConfigurationFileFactoryBase
|
||||
{
|
||||
/// <summary>
|
||||
/// TomlConfigurationFile factory method
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
public override IConfigurationFile CreateConfigurationFile(string fileName)
|
||||
{
|
||||
Type tomlType = Type.GetType("Raytheon.Common.TomlConfigurationFile, Raytheon.Configuration.Toml");
|
||||
if (tomlType == null)
|
||||
{
|
||||
throw new InvalidOperationException($"TOML file format supported with Raytheon.Configuration.Toml package.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return (IConfigurationFile)Activator.CreateInstance(tomlType, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// XmlConfigurationFile factory class
|
||||
/// </summary>
|
||||
public class XmlConfigurationFileFactory : ConfigurationFileFactoryBase
|
||||
{
|
||||
/// <summary>
|
||||
/// XmlConfigurationFile factory method
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public override IConfigurationFile CreateConfigurationFile(string fileName)
|
||||
{
|
||||
return new XmlConfigurationFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Read/Write to an ini file.
|
||||
/// </summary>
|
||||
public class IniConfigurationFile : ConfigurationFileBase
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
|
||||
internal static class NativeMethods
|
||||
{
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
internal static extern int GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, string lpReturnedstring, int nSize, string lpFileName);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool WritePrivateProfileString(string lpAppName, string lpKeyName, string line, string lpFileName);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool WritePrivateProfileSection(string lpAppName, string line, string lpFileName);
|
||||
|
||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||
internal static extern int GetPrivateProfileSectionNames(byte[] sections, int bufferSize, string filename);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// The constructor. It will check to make sure the file exists and throw an exception it if does not
|
||||
/// </summary>
|
||||
/// <param name="fileName">The ini file name (path).</param>
|
||||
public IniConfigurationFile(string fileName)
|
||||
: base(fileName)
|
||||
{
|
||||
if (ConfigurationFileType != ConfigurationFileType.INI)
|
||||
{
|
||||
throw new ArgumentException("Expecting INI file configuration type");
|
||||
}
|
||||
|
||||
if (!_fileInfo.Exists)
|
||||
{
|
||||
throw new Exception($"Can't find file: {fileName}");
|
||||
}
|
||||
}
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// reads a value from configuration file
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <returns></returns>
|
||||
public override T ReadValue<T>(string section, string key, T defaultValue = default)
|
||||
{
|
||||
const int BUFFER_SIZE = 1024;
|
||||
string temp = new string('\0', BUFFER_SIZE);
|
||||
int numBytes = NativeMethods.GetPrivateProfileString(section, key, "", temp, BUFFER_SIZE, _fileName);
|
||||
if (numBytes == 0)
|
||||
{
|
||||
WriteValue<T>(section, key, defaultValue);
|
||||
return defaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
temp = temp.TrimEnd('\0');
|
||||
return TypeConverter.ChangeType<T>(temp);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads a value from configuration file
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <returns></returns>
|
||||
public override string ReadValue(string section, string key)
|
||||
{
|
||||
const int BUFFER_SIZE = 1024;
|
||||
string temp = new string('\0', BUFFER_SIZE);
|
||||
|
||||
if (!ReadAllSections().Contains(section))
|
||||
throw new Exception($"Section '{section}' doesn't exist in {_fileName}");
|
||||
|
||||
if (!ReadAllKeys(section).Contains(key))
|
||||
throw new Exception($"Key '{key}' doesn't exist under section '{section}' in {_fileName}");
|
||||
|
||||
int numBytes = NativeMethods.GetPrivateProfileString(section, key, "", temp, BUFFER_SIZE, _fileName);
|
||||
if (numBytes > 0)
|
||||
{
|
||||
return temp.TrimEnd('\0');
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"The value associated with key '{key}' under section '{section}' is empty in {_fileName}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write string value
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="lineToWrite"></param>
|
||||
public override void WriteValue<T>(string section, string key, T lineToWrite)
|
||||
{
|
||||
if (!NativeMethods.WritePrivateProfileString(section, key, $"{lineToWrite}", _fileName))
|
||||
{
|
||||
throw new Exception($"IniFile::WriteValue() - WritePrivateProfileString returned false for section: {section}, key {key}, line {lineToWrite}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads a list of values from INI configuration file
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defaultList"></param>
|
||||
/// <returns></returns>
|
||||
public override List<T> ReadList<T>(string section, string key, IList<T> defaultList = null)
|
||||
{
|
||||
List<T> resultList = new();
|
||||
|
||||
string stringResult = ReadValue(section, key, string.Empty);
|
||||
|
||||
if (string.IsNullOrEmpty(stringResult))
|
||||
{
|
||||
WriteList(section, key, defaultList);
|
||||
return new List<T>(defaultList);
|
||||
}
|
||||
|
||||
foreach (string item in stringResult.Split('|'))
|
||||
{
|
||||
resultList.Add(TypeConverter.ChangeType<T>(item));
|
||||
}
|
||||
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// writes a list of values to INI configuration file
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="listToWrite"></param>
|
||||
public override void WriteList<T>(string section, string key, IList<T> listToWrite)
|
||||
{
|
||||
List<string> stringListToWrite = new(listToWrite.Select(a => a.ToString()));
|
||||
WriteValue(section, key, string.Join("|", stringListToWrite));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads all keys from a section of an ini file.
|
||||
/// </summary>
|
||||
/// <param name="section">The section.</param>
|
||||
/// <returns>A list of all keys.</returns>
|
||||
public override List<string> ReadAllKeys(string section)
|
||||
{
|
||||
const int BUFFER_SIZE = 2500;
|
||||
string temp = new('\0', BUFFER_SIZE);
|
||||
int numBytes = NativeMethods.GetPrivateProfileString(section, null, "", temp, BUFFER_SIZE, _fileName);
|
||||
|
||||
List<string> keyList = new List<string>();
|
||||
|
||||
if (numBytes == 0)
|
||||
{
|
||||
return keyList;
|
||||
}
|
||||
|
||||
temp = temp.TrimEnd('\0');
|
||||
keyList.AddRange(temp.Split('\0'));
|
||||
|
||||
return keyList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of all of the sections in the ini file.
|
||||
/// </summary>
|
||||
/// <returns>A list of all sections.</returns>
|
||||
public override List<string> ReadAllSections()
|
||||
{
|
||||
List<string> sectionList = new();
|
||||
|
||||
// allocate a 10K buffer.
|
||||
const int BUFFER_SIZE = 10240;
|
||||
// allocate a 10K buffer. Should be enough to handle plenty of power systems
|
||||
byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int numBytesReturned = NativeMethods.GetPrivateProfileSectionNames(buffer, BUFFER_SIZE, _fileName);
|
||||
|
||||
if (numBytesReturned == BUFFER_SIZE)
|
||||
{
|
||||
throw new Exception("IniFile::ReadAllSections() - returned the max buffer size. Probably have more items in config file than we can handle");
|
||||
}
|
||||
else if (numBytesReturned == 0)
|
||||
{
|
||||
return sectionList;
|
||||
}
|
||||
|
||||
// convert the buffer to a string
|
||||
string result = System.Text.Encoding.Unicode.GetString(buffer);
|
||||
// trim the end of the string
|
||||
result = result.TrimEnd('\0');
|
||||
// split the string
|
||||
string[] sectionListTemp = result.Split('\0');
|
||||
// ass the sections to a list
|
||||
|
||||
for (int i = 0; i < sectionListTemp.Length; ++i)
|
||||
{
|
||||
sectionList.Add(sectionListTemp[i]);
|
||||
}
|
||||
|
||||
return sectionList;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,385 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Implementation of the IConfiguration interface
|
||||
/// </summary>
|
||||
public class RaytheonConfiguration : IConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// returns configuration file path
|
||||
/// </summary>
|
||||
private string configFilePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.Combine(OutputPath, string.Concat(Name, ".xml"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// configuration file name
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// configuration file location
|
||||
/// </summary>
|
||||
public string OutputPath
|
||||
{
|
||||
get;
|
||||
internal set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// default constructor
|
||||
/// </summary>
|
||||
public RaytheonConfiguration()
|
||||
{
|
||||
OutputPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Raytheon", "Configuration");
|
||||
IsValidPath(OutputPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor that takes configuration file name
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
public RaytheonConfiguration(string name) : this()
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor that takes file name and location
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="outputPath"></param>
|
||||
public RaytheonConfiguration(string name, string outputPath) : this(name)
|
||||
{
|
||||
if (IsValidPath(outputPath))
|
||||
{
|
||||
OutputPath = outputPath;
|
||||
}
|
||||
}
|
||||
|
||||
private static void CreateConfigurationFile(FileInfo file)
|
||||
{
|
||||
XDocument xDocument = new XDocument();
|
||||
xDocument.Add(new XElement("Configurations"));
|
||||
xDocument.Root.Add(new XElement("IniConfiguration"));
|
||||
xDocument.Root.Add(new XElement("XmlConfigurations"));
|
||||
xDocument.Save(file.FullName);
|
||||
}
|
||||
|
||||
private FileInfo CreateFileIfMissing()
|
||||
{
|
||||
FileInfo fileInfo = new FileInfo(configFilePath);
|
||||
if (!fileInfo.Exists)
|
||||
{
|
||||
throw new Exception($"Can't find file: {configFilePath}");
|
||||
}
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
private static XElement GetConfigSection(string section, XElement iniConfiguration, string configFilePath)
|
||||
{
|
||||
XElement xElement = (
|
||||
from s in iniConfiguration.Descendants("section")
|
||||
where (string)s.Attribute("name") == section
|
||||
select s).FirstOrDefault();
|
||||
if (xElement == null)
|
||||
{
|
||||
throw new Exception($"There is no <section> tag with 'name={section}' in {configFilePath}");
|
||||
}
|
||||
return xElement;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads single string value from XML configuration file by section name and a key
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <returns></returns>
|
||||
public string GetConfigurationValue(string section, string key, string defaultValue)
|
||||
{
|
||||
FileInfo fileInfo = CreateFileIfMissing();
|
||||
XDocument xDocument = XDocument.Load(fileInfo.FullName);
|
||||
XElement xElement = xDocument.Root.Element("IniConfiguration");
|
||||
XElement configSection = GetConfigSection(section, xElement, configFilePath);
|
||||
XElement xElement1 = (
|
||||
from k in configSection.Descendants("key")
|
||||
where (string)k.Attribute("name") == key
|
||||
select k).FirstOrDefault();
|
||||
if (xElement1 == null)
|
||||
{
|
||||
XName xName = "key";
|
||||
object[] xAttribute = new object[] { new XAttribute("name", key), new XAttribute("value", defaultValue) };
|
||||
xElement1 = new XElement(xName, xAttribute);
|
||||
configSection.Add(xElement1);
|
||||
xDocument.Save(fileInfo.FullName);
|
||||
}
|
||||
XAttribute xAttribute1 = xElement1.Attribute("value");
|
||||
if (xAttribute1 == null)
|
||||
{
|
||||
xAttribute1 = new XAttribute("value", defaultValue);
|
||||
xElement1.Add(xAttribute1);
|
||||
xDocument.Save(fileInfo.FullName);
|
||||
}
|
||||
if (xAttribute1 == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return xAttribute1.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads single string value from XML configuration file by section name and a key
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <returns></returns>
|
||||
public string GetConfigurationValue(string section, string key)
|
||||
{
|
||||
FileInfo fileInfo = CreateFileIfMissing();
|
||||
XDocument xDocument = XDocument.Load(fileInfo.FullName);
|
||||
XElement xElement = xDocument.Root.Element("IniConfiguration");
|
||||
XElement configSection = GetConfigSection(section, xElement, configFilePath);
|
||||
XElement xElement1 = (
|
||||
from k in configSection.Descendants("key")
|
||||
where (string)k.Attribute("name") == key
|
||||
select k).FirstOrDefault();
|
||||
if (xElement1 == null)
|
||||
{
|
||||
throw new Exception($"There is no <key> tag with 'name={key}' under section {section} in {configFilePath}");
|
||||
}
|
||||
XAttribute xAttribute1 = xElement1.Attribute("value");
|
||||
if (xAttribute1 == null)
|
||||
{
|
||||
throw new Exception($"Attribute 'value' is missing for <key> tag with 'name={key}' under section {section} in {configFilePath}");
|
||||
}
|
||||
return xAttribute1.Value;
|
||||
}
|
||||
|
||||
private static XElement GetConfigXml(string name, XElement xmlConfigurations)
|
||||
{
|
||||
XElement xElement = (
|
||||
from s in xmlConfigurations.Descendants("XmlConfiguration")
|
||||
where (string)s.Attribute("name") == name
|
||||
select s).FirstOrDefault();
|
||||
return xElement;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads XML configuration from a file
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public string GetXmlConfiguration(string name)
|
||||
{
|
||||
XDocument xDocument = XDocument.Load(CreateFileIfMissing().FullName);
|
||||
XElement xElement = xDocument.Root.Element("XmlConfigurations");
|
||||
XElement configXml = GetConfigXml(name, xElement);
|
||||
if (configXml == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return configXml.ToString();
|
||||
}
|
||||
|
||||
internal void Initialize()
|
||||
{
|
||||
Directory.CreateDirectory(OutputPath);
|
||||
CreateFileIfMissing();
|
||||
}
|
||||
|
||||
private static bool IsValidPath(string outputPath)
|
||||
{
|
||||
bool flag;
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(outputPath);
|
||||
flag = true;
|
||||
}
|
||||
catch (PathTooLongException)
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
flag = false;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
private static void SetConfigKey(string key, string value, XElement configSection)
|
||||
{
|
||||
XElement xElement = (
|
||||
from k in configSection.Descendants("key")
|
||||
where (string)k.Attribute("name") == key
|
||||
select k).FirstOrDefault();
|
||||
if (xElement != null)
|
||||
{
|
||||
xElement.SetAttributeValue("value", value);
|
||||
return;
|
||||
}
|
||||
XName xName = "key";
|
||||
object[] xAttribute = new object[] { new XAttribute("name", key), null };
|
||||
xAttribute[1] = new XAttribute("value", value ?? string.Empty);
|
||||
xElement = new XElement(xName, xAttribute);
|
||||
configSection.Add(xElement);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// writes configuration value by section name and by key
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
public void SetConfigurationValue(string section, string key, string value)
|
||||
{
|
||||
FileInfo fileInfo = CreateFileIfMissing();
|
||||
XDocument xDocument = XDocument.Load(fileInfo.FullName);
|
||||
XElement xElement = xDocument.Root.Element("IniConfiguration");
|
||||
SetConfigKey(key, value, GetConfigSection(section, xElement, configFilePath));
|
||||
xDocument.Save(fileInfo.FullName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// saves XML string into XML file
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="xml"></param>
|
||||
public void SetXmlConfiguration(string name, string xml)
|
||||
{
|
||||
FileInfo fileInfo = CreateFileIfMissing();
|
||||
XElement xElement = XElement.Parse(xml);
|
||||
int elementCount = xElement.Elements().Count();
|
||||
|
||||
XDocument xDocument = XDocument.Load(fileInfo.FullName);
|
||||
XElement xmlConfigurations = xDocument.Root.Element("XmlConfigurations");
|
||||
XElement sectionXml = GetConfigXml(name, xmlConfigurations);
|
||||
|
||||
XName xName = "XmlConfiguration";
|
||||
object[] xAttribute = new object[1 + elementCount];
|
||||
xAttribute[0] = new XAttribute("name", name);
|
||||
if (elementCount == 1)
|
||||
{
|
||||
xAttribute[1] = xElement.FirstNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = 1;
|
||||
foreach (var item in xElement.Elements())
|
||||
{
|
||||
xAttribute[i++] = item;
|
||||
}
|
||||
}
|
||||
|
||||
if (sectionXml == null)
|
||||
{
|
||||
xmlConfigurations.Add(new XElement(xName, xAttribute));
|
||||
}
|
||||
else
|
||||
{
|
||||
sectionXml.ReplaceWith(new XElement(xName, xAttribute));
|
||||
}
|
||||
|
||||
xDocument.Save(fileInfo.FullName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// tries reading enumeration value by section and key name
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public bool TryGetEnumValue<T>(string section, string key, out T value)
|
||||
where T : struct
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(section))
|
||||
{
|
||||
throw new ArgumentException("'section' cannot be Null or Whitespace", "section");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
{
|
||||
throw new ArgumentException("'key' cannot be Null or Whitespace", "key");
|
||||
}
|
||||
if (!typeof(T).IsEnum)
|
||||
{
|
||||
throw new ArgumentException("T must be an enumerated type");
|
||||
}
|
||||
bool flag = Enum.TryParse<T>(GetConfigurationValue(section, key, string.Concat("NOT_A_VALID_", key.ToUpper())), out value);
|
||||
if (!flag)
|
||||
{
|
||||
int num = 0;
|
||||
string[] names = Enum.GetNames(typeof(T));
|
||||
for (int i = 0; i < names.Length; i++)
|
||||
{
|
||||
string str = names[i];
|
||||
int num1 = num + 1;
|
||||
num = num1;
|
||||
int num2 = num1;
|
||||
SetConfigurationValue(string.Concat("Valid_", key), num2.ToString(), str);
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// implementation of the Raytheon Configuration Manager
|
||||
/// </summary>
|
||||
[Export(typeof(IConfigurationManager))]
|
||||
public class RaytheonConfigurationManager : IConfigurationManager
|
||||
{
|
||||
private object _configLock = new();
|
||||
|
||||
private Dictionary<string, RaytheonConfiguration> _configurations = new();
|
||||
|
||||
private static readonly string DefaultStoragePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Raytheon", "InstrumentManagerService");
|
||||
|
||||
private string _storagePath;
|
||||
|
||||
/// <summary>
|
||||
/// gets or sets configuration storage path
|
||||
/// when setting the path and it does not exist will use the default value instead
|
||||
/// </summary>
|
||||
public string ConfigurationStoragePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return _storagePath;
|
||||
}
|
||||
set
|
||||
{
|
||||
string item = value;
|
||||
|
||||
if(string.IsNullOrWhiteSpace(item))
|
||||
{
|
||||
item = ConfigurationManager.AppSettings["ConfigurationPath"];
|
||||
}
|
||||
|
||||
if(!IsValidPath(item, true))
|
||||
{
|
||||
Trace.WriteLine(string.Format("The Application Setting [ConfigurationPath] '{0}' is invalid.", item));
|
||||
_storagePath = DefaultStoragePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
_storagePath = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// if path not provided will be using either app settings value or default
|
||||
/// </summary>
|
||||
public RaytheonConfigurationManager()
|
||||
{
|
||||
ConfigurationStoragePath = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor that takes configuration file path
|
||||
/// </summary>
|
||||
/// <param name="defaultPath"></param>
|
||||
public RaytheonConfigurationManager(string defaultPath) => ConfigurationStoragePath = defaultPath;
|
||||
|
||||
/// <summary>
|
||||
/// returns RaytheonConfiguration instance
|
||||
/// </summary>
|
||||
/// <param name="configurationName"></param>
|
||||
/// <returns></returns>
|
||||
public IConfiguration GetConfiguration(string configurationName)
|
||||
{
|
||||
RaytheonConfiguration item = null;
|
||||
lock(_configLock)
|
||||
{
|
||||
if(_configurations.ContainsKey(configurationName))
|
||||
{
|
||||
item = _configurations[configurationName];
|
||||
}
|
||||
else
|
||||
{
|
||||
item = new RaytheonConfiguration(configurationName, ConfigurationStoragePath);
|
||||
item.Initialize();
|
||||
_configurations.Add(configurationName, item);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// checks if the configuration storage path for config file is valid
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="allowRelativePaths"></param>
|
||||
/// <returns></returns>
|
||||
private bool IsValidPath(string path, bool allowRelativePaths = false)
|
||||
{
|
||||
if(string.IsNullOrEmpty(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isValid;
|
||||
try
|
||||
{
|
||||
string fullPath = Path.GetFullPath(path);
|
||||
|
||||
if(allowRelativePaths)
|
||||
{
|
||||
isValid = Path.IsPathRooted(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
string root = Path.GetPathRoot(path);
|
||||
isValid = string.IsNullOrEmpty(root.Trim(new char[] { '\\', '/' })) == false;
|
||||
}
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Read/Write to an XML file.
|
||||
/// </summary>
|
||||
public class XmlConfigurationFile : ConfigurationFileBase
|
||||
{
|
||||
#region PrivateMemberVariables
|
||||
|
||||
/// <summary>
|
||||
/// Raytheon configuration
|
||||
/// </summary>
|
||||
private readonly IConfigurationManager _configurationManager;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
#region PublicFunctions
|
||||
|
||||
/// <summary>
|
||||
/// The constructor. It will check to make sure the file exists and throw an exception it if does not
|
||||
/// </summary>
|
||||
/// <param name="fileName">The ini file name (path).</param>
|
||||
public XmlConfigurationFile(string fileName)
|
||||
: base(fileName)
|
||||
{
|
||||
if (ConfigurationFileType != ConfigurationFileType.XML)
|
||||
{
|
||||
throw new ArgumentException("Expecting XML file configuration type");
|
||||
}
|
||||
|
||||
_configurationManager = new RaytheonConfigurationManager(_fileInfo.DirectoryName);
|
||||
_configuration = _configurationManager.GetConfiguration(NameWithoutExtension(_fileInfo));
|
||||
}
|
||||
private static string NameWithoutExtension(FileInfo fileInfo)
|
||||
{
|
||||
return fileInfo.Name.Remove(fileInfo.Name.LastIndexOf("."));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads a value from configuration file
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defaultValue"></param>
|
||||
/// <returns></returns>
|
||||
public override T ReadValue<T>(string section, string key, T defaultValue = default)
|
||||
{
|
||||
return _configuration.GetConfigurationValue<T>(section, key, defaultValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads a value from configuration file
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public override string ReadValue(string section, string key)
|
||||
{
|
||||
return _configuration.GetConfigurationValue(section, key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write string value
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="lineToWrite"></param>
|
||||
public override void WriteValue<T>(string section, string key, T lineToWrite)
|
||||
{
|
||||
_configuration.SetConfigurationValue<T>(section, key, lineToWrite);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// reads a list of values from configuration file
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defaultList"></param>
|
||||
/// <returns></returns>
|
||||
public override List<T> ReadList<T>(string section, string key, IList<T> defaultList = null)
|
||||
{
|
||||
return _configuration.GetConfigurationListValue<T>(section, key, defaultList);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// writes a list of values to configuration file
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="listToWrite"></param>
|
||||
public override void WriteList<T>(string section, string key, IList<T> listToWrite)
|
||||
{
|
||||
_configuration.SetConfigurationListValue(section, key, listToWrite);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads all keys from a section of an ini file.
|
||||
/// </summary>
|
||||
/// <param name="section">The section.</param>
|
||||
/// <returns>A list of all keys.</returns>
|
||||
public override List<string> ReadAllKeys(string section)
|
||||
{
|
||||
return ConfigurationHelper.GetAvailableConfigSectionKeys(_fileName, section);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of all of the sections in the ini file.
|
||||
/// </summary>
|
||||
/// <returns>A list of all sections.</returns>
|
||||
public override List<string> ReadAllSections()
|
||||
{
|
||||
return ConfigurationHelper.GetAvailableConfigSections(_fileName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
[DataContract]
|
||||
public class ConfigurationException : Exception
|
||||
{
|
||||
public ConfigurationException()
|
||||
:base()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ConfigurationException(string message)
|
||||
:base(message)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ConfigurationException(string message, Exception innerException)
|
||||
:base(message, innerException)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public ConfigurationException(SerializationInfo info, StreamingContext context)
|
||||
:base(info, context)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// interface for flaging the moment when configurable object is done with configuration
|
||||
/// restored from the previous version of Raytheon.Configuration package
|
||||
/// </summary>
|
||||
public interface IConfigurable
|
||||
{
|
||||
void OnConfigured();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration interface
|
||||
/// restored from the previous version of Raytheon.Configuration package
|
||||
/// </summary>
|
||||
public interface IConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the configuration value.
|
||||
/// </summary>
|
||||
/// <param name="section">The section.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="value">The value.</param>
|
||||
void SetConfigurationValue(string section, string key, string value);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the configuration value.
|
||||
/// </summary>
|
||||
/// <param name="section">The section.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="defaultValue">The default value.</param>
|
||||
/// <returns></returns>
|
||||
string GetConfigurationValue(string section, string key, string defaultValue);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the configuration value.
|
||||
/// </summary>
|
||||
/// <param name="section">The section.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <returns></returns>
|
||||
string GetConfigurationValue(string section, string key);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the XML configuration.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <param name="xml">The XML.</param>
|
||||
void SetXmlConfiguration(string name, string xml);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the XML configuration.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <returns></returns>
|
||||
string GetXmlConfiguration(string name);
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to get the enumerated configuration value.
|
||||
/// If it does not exist or cannot be parsed to a valid value,
|
||||
/// it will create a new section called Valid_{key} and list the valid enumeration values.
|
||||
/// </summary>
|
||||
/// <param name="section">The section.</param>
|
||||
/// <param name="key">The key.</param>
|
||||
/// <param name="defaultValue">The default value.</param>
|
||||
/// <returns></returns>
|
||||
bool TryGetEnumValue<T>(string section, string key, out T value) where T : struct;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// supported file types
|
||||
/// </summary>
|
||||
public enum ConfigurationFileType
|
||||
{
|
||||
INI,
|
||||
XML,
|
||||
TOML,
|
||||
JSON,
|
||||
YAML,
|
||||
OTHER
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// updated version of IConfiguration interface
|
||||
/// allows reading and writing generic types as well as lists
|
||||
/// </summary>
|
||||
public interface IConfigurationFile
|
||||
{
|
||||
/// <summary>
|
||||
/// reads a single generic type value from the file section
|
||||
/// if value or section does not exist, will create one and will add the default value
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defValue"></param>
|
||||
/// <returns></returns>
|
||||
T ReadValue<T>(string section, string key, T defValue = default);
|
||||
|
||||
/// <summary>
|
||||
/// reads a single generic type value from the file section
|
||||
/// if value doesn't exist, throw exception
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
string ReadValue(string section, string key);
|
||||
|
||||
/// <summary>
|
||||
/// reads a list of generic type values from the file section
|
||||
/// if list or section does not exist, will create one and will populate with the default list
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="defList"></param>
|
||||
/// <returns></returns>
|
||||
List<T> ReadList<T>(string section, string key, IList<T> defList = null);
|
||||
|
||||
/// <summary>
|
||||
/// reads all available keys from the given section of configuration file
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <returns></returns>
|
||||
List<string> ReadAllKeys(string section);
|
||||
|
||||
/// <summary>
|
||||
/// reads all available sections from configuration file
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<string> ReadAllSections();
|
||||
|
||||
/// <summary>
|
||||
/// writes a single value of a generic type
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="lineToWrite"></param>
|
||||
void WriteValue<T>(string section, string key, T lineToWrite);
|
||||
|
||||
/// <summary>
|
||||
/// writes a list of generic values
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="listToWrite"></param>
|
||||
void WriteList<T>(string section, string key, IList<T> listToWrite);
|
||||
|
||||
/// <summary>
|
||||
/// checks if the value exists in the given section and given key
|
||||
/// </summary>
|
||||
/// <param name="section"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
bool ValueExists(string section, string key);
|
||||
|
||||
/// <summary>
|
||||
/// configuration file name
|
||||
/// </summary>
|
||||
string FileName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// configuration file type
|
||||
/// </summary>
|
||||
ConfigurationFileType ConfigurationFileType { get; }
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// ******************************************************************************//
|
||||
// RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
|
||||
// PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
|
||||
// AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
|
||||
// UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
|
||||
// RAYTHEON COMPANY''S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
|
||||
// CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
|
||||
// OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
|
||||
// COMPANY.
|
||||
//
|
||||
// THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S. GOVERNMENT
|
||||
//
|
||||
// UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
|
||||
//
|
||||
// WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE
|
||||
// EXPORT OR DISCLOSURE TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED
|
||||
// BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTION
|
||||
// 120-130) OR THE EXPORT ADMINISTRATION REGULATIONS (EAR) (15 C.F.R. SECTION
|
||||
// 730-774). THIS DOCUMENT CANNOT BE EXPORTED (E.G., PROVIDED TO A SUPPLIER
|
||||
// OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S. PERSON, WHEREVER
|
||||
// LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS
|
||||
// BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S. GOVERNMENT
|
||||
// APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL
|
||||
// PENALTIES.
|
||||
//
|
||||
// DOD 5220.22-M, INDUSTRIAL SECURITY MANUAL, CHAPTER 5, SECTION 1 THROUGH 9 :
|
||||
// FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN OR DOD 5200.1-R,
|
||||
// INFORMATION SECURITY PROGRAM, CHAPTER 6. FOR UNCLASSIFIED, LIMITED DOCUMENTS
|
||||
// DESTROY BY ANY METHOD THAT WILL PREVENT DISCLOSURE OF CONTENTS OR
|
||||
// RECONSTRUCTION OF THE DOCUMENT.
|
||||
// ****************************************************************************//
|
||||
|
||||
namespace Raytheon.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration Manager interface
|
||||
/// </summary>
|
||||
public interface IConfigurationManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the configuration by name.
|
||||
/// </summary>
|
||||
/// <param name="configurationName">Name of the configuration.</param>
|
||||
/// <returns></returns>
|
||||
IConfiguration GetConfiguration(string configurationName);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the configuration storage path or the location of the configuration files
|
||||
/// </summary>
|
||||
string ConfigurationStoragePath { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user