/// <summary> /// Reads the specified XML element (a 'Configuration' element) and updates the corresponding items in the specified /// configuration. /// </summary> /// <param name="configuration">Configuration to update.</param> /// <param name="parent">Parent element in the XML tree.</param> private void LoadInternal(CascadedConfiguration configuration, XmlElement parent) { // read 'Configuration' element XmlElement configurationElement = parent.SelectSingleNode(string.Format("Configuration[@name='{0}']", configuration.Name)) as XmlElement; if (configurationElement != null) { foreach (ICascadedConfigurationItem item in configuration.Items) { XmlElement itemElement = configurationElement.SelectSingleNode(string.Format("Item[@name='{0}']", item.Name)) as XmlElement; if (itemElement != null) { object value = GetValueFromXmlElement(itemElement, item.Name, item.Type); item.Value = value; } else { item.ResetValue(); } } // load child configurations foreach (CascadedConfiguration child in configuration.Children) { LoadInternal(child, configurationElement); } // add configurations that do not exist, yet // (items are not mapped, since items are typed and the file does not contain any type information) foreach (XmlElement element in configurationElement.SelectNodes("Configuration[@name]")) { string name = element.Attributes["name"].Value; CascadedConfiguration child = configuration.Children.Where(x => x.Name == name).FirstOrDefault(); if (child == null) { child = configuration.GetChildConfiguration(CascadedConfigurationPathHelper.EscapeName(name), true); LoadInternal(child, configurationElement); } } } else { configuration.ResetItems(true); } }
/// <summary> /// Recursion helper for the <see cref="LoadItem(ICascadedConfigurationItem)"/> method. /// </summary> /// <param name="item">Item to load.</param> /// <param name="remainingPath">Remaining path to the requested item.</param> /// <param name="parent">XML node of the parent configuration.</param> private void LoadItemInternal(ICascadedConfigurationItem item, string remainingPath, XmlElement parent) { string[] pathTokens = CascadedConfigurationPathHelper.SplitPath(this, remainingPath, true, true); if (pathTokens.Length > 1) { string itemName = CascadedConfigurationPathHelper.UnescapeName(pathTokens[0]); XmlElement configurationElement = parent.SelectSingleNode(string.Format("Configuration[@name='{0}']", itemName)) as XmlElement; if (configurationElement != null) { LoadItemInternal(item, string.Join("/", pathTokens, 1, pathTokens.Length - 1), configurationElement); } } else { XmlElement itemElement = parent.SelectSingleNode(string.Format("Item[@name='{0}']", item.Name)) as XmlElement; if (itemElement != null) { object value = GetValueFromXmlElement(itemElement, item.Name, item.Type); item.Value = value; } } }