public SConfigManager(string configuration)
{
this._configXml = configuration;
XmlDocument configXml = null;
// Initializing XmlDocument
try
{
configXml = new XmlDocument();
configXml.LoadXml(configuration);
}
catch (Exception e)
{
Exception exception = new Exception("Cannot parse XML file", e);
throw exception;
}
// Read Name of the configuration section
try
{
Name = configXml.DocumentElement.Attributes["name"].Value;
if (Name == "")
{
throw new Exception();
}
}
catch (Exception)
{
ArgumentException exception = new ArgumentException("Argument cannot null nor empty", "name");
throw exception;
}
try
{
// parse settings
Settings = new Dictionary<string, string>();
XmlNodeList xnList = configXml.SelectNodes("/configuration/settings//setting");
foreach (XmlNode xn in xnList)
{
string key = xn.Attributes["key"].Value;
string value = xn.Attributes["value"].Value;
Settings.Add(key, value);
}
// get custom xml
xnList = configXml.SelectNodes("/configuration/custom");
if (xnList.Count > 0)
{
CustomXml = xnList[0].InnerXml.ToString();
}
// get children
Children = new Dictionary<string, SConfigManager>();
xnList = configXml.SelectNodes("/configuration/children/configuration");
if (xnList.Count > 0)
{
foreach (XmlNode xmlNode in xnList)
{
SConfigManager childConfig = new SConfigManager(xmlNode.OuterXml.ToString());
Children.Add(childConfig.Name, childConfig);
}
}
}
catch (Exception ex)
{
Exception exception = new Exception("Error while processing XML", ex);
throw exception;
}
}