Example #1
0
        private void MergeHierarchy(IConfigurationUIHierarchy configurationHierarhcy, Dictionary <string, ConfigurationNodeMergeData> mergeDataByPath)
        {
            string rootNodeName = configurationHierarhcy.RootNode.Name;

            foreach (String configurationNodePath in mergeDataByPath.Keys)
            {
                ConfigurationNodeMergeData mergeData = mergeDataByPath[configurationNodePath];
                if (mergeData.OverrideProperties)
                {
                    ConfigurationNode node = configurationHierarhcy.FindNodeByPath(rootNodeName + configurationNodePath);
                    if (node != null)
                    {
                        PropertyDescriptorCollection propertiesOnNode = TypeDescriptor.GetProperties(node);
                        foreach (PropertyDescriptor property in propertiesOnNode)
                        {
                            object propertyValue = mergeData.GetPropertyValue(property.Name, property.PropertyType, property.GetValue(node), configurationHierarhcy);
                            property.SetValue(node, propertyValue);
                        }
                    }
                }
            }
        }
Example #2
0
        EnvironmentMergeData ReadEnvironmentMergeData(EnvironmentMergeSection environmentSection, IConfigurationUIHierarchy configurationHierarchy)
        {
            EnvironmentMergeData mergeData = new EnvironmentMergeData();

            foreach (EnvironmentNodeMergeElement mergeElement in environmentSection.MergeElements)
            {
                ConfigurationNodeMergeData propertyDictionaty = new ConfigurationNodeMergeData();
                foreach (string key in mergeElement.OverriddenProperties.AllKeys)
                {
                    string overriddenValue = mergeElement.OverriddenProperties[key].Value;
                    propertyDictionaty.SetPropertyValue(key, new UnserializedPropertyValue(overriddenValue));
                }
                ConfigurationNodeMergeData configurationNodeMergeData = new ConfigurationNodeMergeData(mergeElement.OverrideProperties, propertyDictionaty);
                string            fullNodePath = configurationHierarchy.RootNode.Path + mergeElement.ConfigurationNodePath;
                ConfigurationNode node         = configurationHierarchy.FindNodeByPath(fullNodePath);
                if (node != null)
                {
                    mergeData.UpdateMergeData(node, configurationNodeMergeData);
                }
            }

            return(mergeData);
        }
Example #3
0
        /// <summary>
        /// Deserialize content from a string.
        /// </summary>
        /// <param name="serializedContents">The serialized content.</param>
        /// <param name="targetType">The target type.</param>
        /// <param name="hierarchy">An <see cref="IConfigurationUIHierarchy"/> object.</param>
        /// <returns>The deserialized content.</returns>
        public static object DeserializeFromString(string serializedContents, Type targetType, IConfigurationUIHierarchy hierarchy)
        {
            if (serializedContents == null)
            {
                return(null);
            }
            else if (typeof(IEnvironmentalOverridesSerializable).IsAssignableFrom(targetType))
            {
                IEnvironmentalOverridesSerializable instance = (IEnvironmentalOverridesSerializable)Activator.CreateInstance(targetType);
                instance.DesializeFromString(serializedContents);

                return(instance);
            }
            else if (typeof(ConfigurationNode).IsAssignableFrom(targetType))
            {
                string            fullNodePath = SerializationUtility.CreateAbsolutePath(serializedContents, hierarchy);
                ConfigurationNode foundNode    = hierarchy.FindNodeByPath(fullNodePath);
                if (foundNode != null)
                {
                    if (targetType.IsAssignableFrom(foundNode.GetType()))
                    {
                        return(foundNode);
                    }
                }
                return(null);
            }
            else
            {
                TypeConverter converter = TypeDescriptor.GetConverter(targetType);
                if (converter != null)
                {
                    return(converter.ConvertFromInvariantString(serializedContents));
                }
                return(null);
            }
        }
        EnvironmentMergeData ReadEnvironmentMergeData(EnvironmentMergeSection environmentSection, IConfigurationUIHierarchy configurationHierarchy)
        {
            EnvironmentMergeData mergeData = new EnvironmentMergeData();

            foreach (EnvironmentNodeMergeElement mergeElement in environmentSection.MergeElements)
            {
                ConfigurationNodeMergeData propertyDictionaty = new ConfigurationNodeMergeData();
                foreach (string key in mergeElement.OverriddenProperties.AllKeys)
                {
                    string overriddenValue = mergeElement.OverriddenProperties[key].Value;
                    propertyDictionaty.SetPropertyValue(key, new UnserializedPropertyValue(overriddenValue));
                }
                ConfigurationNodeMergeData configurationNodeMergeData = new ConfigurationNodeMergeData(mergeElement.OverrideProperties, propertyDictionaty);
                string fullNodePath = configurationHierarchy.RootNode.Path + mergeElement.ConfigurationNodePath;
                ConfigurationNode node = configurationHierarchy.FindNodeByPath(fullNodePath);
                if (node != null)
                {
                    mergeData.UpdateMergeData(node, configurationNodeMergeData);
                }
            }

            return mergeData;
        }
 private void MergeHierarchy(IConfigurationUIHierarchy configurationHierarhcy, Dictionary<string, ConfigurationNodeMergeData> mergeDataByPath)
 {
     string rootNodeName = configurationHierarhcy.RootNode.Name;
     foreach (String configurationNodePath in mergeDataByPath.Keys)
     {
         ConfigurationNodeMergeData mergeData = mergeDataByPath[configurationNodePath];
         if (mergeData.OverrideProperties)
         {
             ConfigurationNode node = configurationHierarhcy.FindNodeByPath(rootNodeName + configurationNodePath);
             if (node != null)
             {
                 PropertyDescriptorCollection propertiesOnNode = TypeDescriptor.GetProperties(node);
                 foreach (PropertyDescriptor property in propertiesOnNode)
                 {
                     object propertyValue
                         = mergeData.GetPropertyValue(property.Name, property.PropertyType, property.GetValue(node), configurationHierarhcy);
                     property.SetValue(node, propertyValue);
                 }
             }
         }
     }
 }