public OverriddenElementViewModel(ElementLookup lookup, EnvironmentMergeSection environmentSection, ElementViewModel subject) { this.lookup = lookup; this.environmentSection = environmentSection; this.elementReference = new ReferenceContainer(this); this.subject = subject; }
public OverriddenElementViewModel(ElementLookup lookup, EnvironmentMergeSection environmentSection, ElementViewModel subject) { this.lookup = lookup; this.environmentSection = environmentSection; this.elementReference = new ReferenceContainer(this); this.subject = subject; }
public OverriddenElementViewModel(ElementLookup lookup, EnvironmentMergeSection environmentSection, EnvironmentNodeMergeElement mergeElement) { this.lookup = lookup; this.environmentSection = environmentSection; this.mergeElement = mergeElement; this.elementReference = new ReferenceContainer(this); this.elementReference.InitializeReference(mergeElement.ConfigurationNodePath, mergeElement); }
public OverriddenElementViewModel(ElementLookup lookup, EnvironmentMergeSection environmentSection, EnvironmentNodeMergeElement mergeElement) { this.lookup = lookup; this.environmentSection = environmentSection; this.mergeElement = mergeElement; this.elementReference = new ReferenceContainer(this); this.elementReference.InitializeReference(mergeElement.ConfigurationNodePath, mergeElement); }
public override void Save(IServiceProvider serviceProvider) { IErrorLogService errorService = ServiceHelper.GetErrorService(serviceProvider); IEnvironmentMergeService environmentMergeService = serviceProvider.GetService(typeof(IEnvironmentMergeService)) as IEnvironmentMergeService; if (environmentMergeService != null) { if (environmentMergeService.EnvironmentMergeInProgress) { return; } } IConfigurationUIHierarchy hierarchy = ServiceHelper.GetCurrentHierarchy(serviceProvider); Debug.Assert(hierarchy != null); ConfigurationApplicationNode configurationRootNode = hierarchy.FindNodeByType(typeof(ConfigurationApplicationNode)) as ConfigurationApplicationNode; Debug.Assert(configurationRootNode != null); string configurationFileDirectory = Path.GetDirectoryName(configurationRootNode.ConfigurationFile); foreach (EnvironmentNode environmentNode in hierarchy.FindNodesByType(typeof(EnvironmentNode))) { string environmentDeltaFilePath = Path.Combine(configurationFileDirectory, environmentNode.EnvironmentDeltaFile); Dictionary <string, ConfigurationNodeMergeData> mergeDataByPath = environmentNode.EnvironmentMergeData.UnfoldMergeData(hierarchy, false); EnvironmentMergeSection environmentMergeSection = new EnvironmentMergeSection(); environmentMergeSection.EnvironmentName = environmentNode.Name; environmentMergeSection.EnvironmentDeltaFile = environmentNode.EnvironmentConfigurationFile; CopyEnvironmentOverrides(environmentMergeSection, mergeDataByPath, hierarchy); string protectionProvider = GetProtectionProviderName(environmentNode); try { FileConfigurationSource fileConfigurationSource = new FileConfigurationSource(environmentDeltaFilePath, false); if (!string.IsNullOrEmpty(protectionProvider)) { fileConfigurationSource.Save(EnvironmentMergeSection.EnvironmentMergeData, environmentMergeSection, protectionProvider); } else { fileConfigurationSource.Add(EnvironmentMergeSection.EnvironmentMergeData, environmentMergeSection); } } catch (ConfigurationErrorsException configurationErrors) { errorService.LogErrors(configurationErrors); } } }
public override void Save(IServiceProvider serviceProvider) { IErrorLogService errorService = ServiceHelper.GetErrorService(serviceProvider); IEnvironmentMergeService environmentMergeService = serviceProvider.GetService(typeof(IEnvironmentMergeService)) as IEnvironmentMergeService; if (environmentMergeService != null) { if (environmentMergeService.EnvironmentMergeInProgress) return; } IConfigurationUIHierarchy hierarchy = ServiceHelper.GetCurrentHierarchy(serviceProvider); Debug.Assert(hierarchy != null); ConfigurationApplicationNode configurationRootNode = hierarchy.FindNodeByType(typeof(ConfigurationApplicationNode)) as ConfigurationApplicationNode; Debug.Assert(configurationRootNode != null); string configurationFileDirectory = Path.GetDirectoryName(configurationRootNode.ConfigurationFile); foreach (EnvironmentNode environmentNode in hierarchy.FindNodesByType(typeof(EnvironmentNode))) { string environmentDeltaFilePath = Path.Combine(configurationFileDirectory, environmentNode.EnvironmentDeltaFile); Dictionary<string, ConfigurationNodeMergeData> mergeDataByPath = environmentNode.EnvironmentMergeData.UnfoldMergeData(hierarchy, false); EnvironmentMergeSection environmentMergeSection = new EnvironmentMergeSection(); environmentMergeSection.EnvironmentName = environmentNode.Name; environmentMergeSection.EnvironmentDeltaFile = environmentNode.EnvironmentConfigurationFile; CopyEnvironmentOverrides(environmentMergeSection, mergeDataByPath, hierarchy); string protectionProvider = GetProtectionProviderName(environmentNode); try { FileConfigurationSource fileConfigurationSource = new FileConfigurationSource(environmentDeltaFilePath, false); if (!string.IsNullOrEmpty(protectionProvider)) { fileConfigurationSource.Save(EnvironmentMergeSection.EnvironmentMergeData, environmentMergeSection, protectionProvider); } else { fileConfigurationSource.Add(EnvironmentMergeSection.EnvironmentMergeData, environmentMergeSection); } } catch (ConfigurationErrorsException configurationErrors) { errorService.LogErrors(configurationErrors); } } }
/// <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()); }
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); } }
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); }
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 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); } }