예제 #1
0
        private void CopyEnvironmentOverrides(EnvironmentMergeSection environmentMergeSection, Dictionary <string, ConfigurationNodeMergeData> mergeDataByPath, IConfigurationUIHierarchy configurationHierarchy)
        {
            foreach (string path in mergeDataByPath.Keys)
            {
                ConfigurationNodeMergeData mergeData = mergeDataByPath[path];

                EnvironmentNodeMergeElement mergeElement = new EnvironmentNodeMergeElement();
                mergeElement.ConfigurationNodePath = path;
                mergeElement.OverrideProperties    = mergeData.OverrideProperties;

                foreach (string propertyName in mergeData.AllPropertyNames)
                {
                    object propertyValue            = mergeData.GetPropertyValue(propertyName, typeof(string), null, configurationHierarchy);
                    string serializedRepresentation = SerializationUtility.SerializeToString(propertyValue, configurationHierarchy);

                    NameValueConfigurationElement keyValue = new NameValueConfigurationElement(propertyName, serializedRepresentation);
                    mergeElement.OverriddenProperties.Add(keyValue);
                }

                environmentMergeSection.MergeElements.Add(mergeElement);
            }
        }
예제 #2
0
        /// <summary>
        /// Returns all the instances of <see cref="ConfigurationNodeMergeData"/> contained in this environment, indexed by the path of the configuration they apply to.
        /// <seealso cref="ConfigurationNodeMergeData"/>
        /// </summary>
        /// <param name="hierarchy"></param>
        /// <param name="useFullPathNames"></param>
        /// <returns></returns>
        public Dictionary <string, ConfigurationNodeMergeData> UnfoldMergeData(IConfigurationUIHierarchy hierarchy, bool useFullPathNames)
        {
            Dictionary <string, ConfigurationNodeMergeData> result = new Dictionary <string, ConfigurationNodeMergeData>();

            foreach (Guid configurationNodeId in mergeDataDictionary.Keys)
            {
                ConfigurationNode configurationNode = hierarchy.FindNodeById(configurationNodeId);
                string            rootNodePath      = hierarchy.RootNode.Path;

                if (configurationNode != null)
                {
                    string configurationNodePath = configurationNode.Path;
                    if (!useFullPathNames)
                    {
                        configurationNodePath = SerializationUtility.CreatePathRelativeToRootNode(configurationNodePath, hierarchy);
                    }

                    result.Add(configurationNodePath, mergeDataDictionary[configurationNodeId]);
                }
            }

            return(result);
        }
예제 #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);
            }
        }
예제 #4
0
 /// <summary>
 /// Deseralize the property values.
 /// </summary>
 /// <param name="type">The type for the property.</param>
 /// <param name="hierarchy">An <see cref="IConfigurationUIHierarchy"/> object.</param>
 /// <returns>The deserialzied value.</returns>
 public object DeserializePropertyValue(Type type,
                                        IConfigurationUIHierarchy hierarchy)
 {
     return(SerializationUtility.DeserializeFromString(serializedContents, type, hierarchy));
 }