/// <summary> /// Initializes a new instance of <see cref="EnvironmentNode"/> given a <see cref="EnvironmentMergeData"/> instance. /// </summary> /// <param name="environmentData">The <see cref="EnvironmentMergeData"/> that contains the information for this environemnt.</param> public EnvironmentNode(EnvironmentMergeData environmentData) : base(environmentData.EnvironmentName) { this.environmentData = environmentData; this.environmentDeltaFile = environmentData.EnvironmentDeltaFile; this.environmentConfigurationFile = environmentData.EnvironmentConfigurationFile; }
/// <summary> /// Builds an <see cref="EnvironmentNode"/> given a Environment Delta file (.dconfig) and a <see cref="ConfigurationUIHierarchy"/>. /// </summary> /// <param name="environmentFileName">The path of the Environment Delta file (.dconfig) that should be used to construct the <see cref="EnvironmentNode"/>.</param> /// <param name="uiHierarchy">The <see cref="IConfigurationUIHierarchy"/> the created <see cref="EnvironmentNode"/> belongs to.</param> /// <returns>An instance of <see cref="EnvironmentNode"/> that represents the Environment Delta file (.dconfig) passed as <paramref name="environmentFileName"/>.</returns> public EnvironmentNode Build(string environmentFileName, IConfigurationUIHierarchy uiHierarchy) { EnvironmentMergeSection mergeSection = GetEnvrinmentMergeSection(environmentFileName); if (mergeSection != null) { EnvironmentMergeData data = ReadEnvironmentMergeData(mergeSection, uiHierarchy); data.EnvironmentName = mergeSection.EnvironmentName; data.EnvironmentDeltaFile = environmentFileName; data.EnvironmentConfigurationFile = mergeSection.EnvironmentDeltaFile; EnvironmentNode environmentNode = new EnvironmentNode(data); if (mergeSection.SectionInformation.IsProtected && mergeSection.SectionInformation.ProtectionProvider != null) { environmentNode.ProtectionProvider = mergeSection.SectionInformation.ProtectionProvider.Name; } return(environmentNode); } return(new EnvironmentNode()); }
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); }