protected override void Arrange() { base.Arrange(); var resources = new ResourceHelper <ConfigFileLocator>(); resources.DumpResourceFileToDisk("empty.config"); var applicationViewModel = Container.Resolve <ApplicationViewModel>(); ConfigurationSourceModel sourceModel = applicationViewModel.CurrentConfigurationSource; applicationViewModel.NewEnvironment(); EhabModel = sourceModel.AddSection(ExceptionHandlingSettings.SectionName, Section); EnvironmentViewModel = applicationViewModel.Environments.First(); EnvironmentSection = (EnvironmentalOverridesSection)EnvironmentViewModel.ConfigurationElement; ((EnvironmentSourceViewModel)EnvironmentViewModel).EnvironmentConfigurationFile = "empty.config"; ((EnvironmentSourceViewModel)EnvironmentViewModel).EnvironmentDeltaFile = "empty.config"; WrapHandler = EhabModel.DescendentElements().Where(x => x.ConfigurationType == typeof(WrapHandlerData)).First(); MainExceptionMessage = WrapHandler.Property("ExceptionMessage"); MainExceptionMessage.Value = "Main Value"; OverridesProperty = WrapHandler.Properties.Where(x => x.PropertyName.StartsWith("Overrides")).First(); OverriddenExceptionMessage = OverridesProperty.ChildProperties.Where(x => x.PropertyName == "ExceptionMessage").First(); }
protected override void InnerExecute(object parameter) { OpenFileDialog openEnvironmentConfigurationDeltaDialog = new OpenFileDialog { Filter = DesignResources.DeltaDialogFilter, Title = DesignResources.OpenDeltaDialogTitle }; var openFileResult = UIService.ShowFileDialog(openEnvironmentConfigurationDeltaDialog); if (openFileResult.DialogResult != true) { return; } try { var configuration = ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = openFileResult.FileName }, ConfigurationUserLevel.None); EnvironmentalOverridesSection mergeSection = (EnvironmentalOverridesSection)configuration.GetSection(EnvironmentalOverridesSection.EnvironmentallyOverriddenProperties); sourceModel.LoadEnvironment(mergeSection, openFileResult.FileName); } catch (Exception ex) { ConfigurationLogWriter.LogException(ex); UIService.ShowMessageWpf(string.Format(CultureInfo.CurrentCulture, Resources.ErrorLoadingDeltaFile, ex.Message), Resources.ErrorTitle, MessageBoxButton.OK); } }
public EnvironmentOverriddenElementPayload(EnvironmentalOverridesSection environmentSection, string elementPath) { Guard.ArgumentNotNull(environmentSection, "environmentSection"); this.environmentSection = environmentSection; this.elementPath = elementPath; }
/// <summary> /// Initializes a new instance of <see cref="ConfigurationMerger"/>. /// </summary> /// <param name="mainConfigurationFile">The path to the main configuration file, which should be used to create the environment specific configuration file.</param> /// <param name="deltaConfigurationFile">The path to the delta configuration file (*.dconfig) that contains the environment specific configuration.</param> public ConfigurationMerger(string mainConfigurationFile, string deltaConfigurationFile) { this.mainConfigurationFile = mainConfigurationFile; using (var configurationSource = new FileConfigurationSource(deltaConfigurationFile)) { mergeSection = (EnvironmentalOverridesSection)configurationSource.GetSection(EnvironmentalOverridesSection.EnvironmentallyOverriddenProperties); } }
protected override void Arrange() { TargetFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("{0}.config", Guid.NewGuid())); Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration( new ExeConfigurationFileMap { ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "merge_environment.dconfig") }, ConfigurationUserLevel.None); MergeSection = (EnvironmentalOverridesSection)configuration.GetSection(EnvironmentalOverridesSection.EnvironmentallyOverriddenProperties); }
public void LoadEnvironment(EnvironmentalOverridesSection environment, string environmentDeltaFile) { var environmentSection = (EnvironmentSourceViewModel) SectionViewModel.CreateSection(builder, EnvironmentalOverridesSection.EnvironmentallyOverriddenProperties, environment); environmentSection.EnvironmentDeltaFile = environmentDeltaFile; environmentSection.LastEnvironmentDeltaSavedFilePath = environmentDeltaFile; environments.Add(environmentSection); SectionInitializer.InitializeSection(environmentSection, new InitializeContext(null)); lookup.AddSection(environmentSection); environmentSection.Select(); }
public void then_stored_value_is_lower_case() { Property requirePermissionProperty = LoggingSectionViewModel.Properties.Where(x => x.PropertyName == "Require Permission").Single(); overridesProperty.Value = true; var overriddenRequirePermissions = overridesProperty.ChildProperties.First(x => x.PropertyName == "Require Permission"); overriddenRequirePermissions.Value = true; EnvironmentalOverridesSection overridesSection = (EnvironmentalOverridesSection)overridesProperty.Environment.ConfigurationElement; var allProperties = overridesSection.MergeElements.OfType <EnvironmentalOverridesElement>().SelectMany(x => x.OverriddenProperties.OfType <EnvironmentOverriddenPropertyElement>()); var propertyForRequirePermissions = allProperties.Where(x => x.ContainingElementXPath == ((IEnvironmentalOverridesProperty)requirePermissionProperty).ContainingElementXPath).Single(); Assert.AreEqual("true", propertyForRequirePermissions.OverriddenValue); }
protected override void Act() { var mergeSection = new EnvironmentalOverridesSection { EnvironmentName = "TestEnvironment", MergeElements = { new EnvironmentalOverridesElement { LogicalParentElementPath = base.settings.Path } } }; var appModel = base.Container.Resolve <ApplicationViewModel>(); appModel.LoadEnvironment(mergeSection, string.Empty); }
public EnvironmentSourceViewModel(IUnityContainer builder, IUIServiceWpf uiService, ApplicationViewModel sourceModel, ConfigurationSection section) : base(builder, EnvironmentalOverridesSection.EnvironmentallyOverriddenProperties, section, new Attribute[] { new EnvironmentalOverridesAttribute(false) }) { this.uiService = uiService; this.environmentSection = (EnvironmentalOverridesSection)section; this.elementLookup = builder.Resolve <ElementLookup>(); this.applicationModel = sourceModel; foreach (EnvironmentalOverridesElement mergeElement in environmentSection.MergeElements) { var payload = new EnvironmentOverriddenElementPayload(environmentSection, mergeElement.LogicalParentElementPath); var reference = new EnvironmentOverriddenElementReference(elementLookup, environmentSection); reference.InitializeWithConfigurationElementPayload(payload); overriddenElements.Add(reference); } saveMergedConfigurationCommand = CreateCommand <SaveMergedEnvironmentConfigurationCommand>(this); saveEnvironmentDeltaCommand = CreateCommand <SaveEnvironmentConfigurationDeltaCommand>(this); }
public EnvironmentOverriddenElementReference(ElementLookup lookup, EnvironmentalOverridesSection environmentSourceModel) { this.lookup = lookup; this.environmentSourceModel = environmentSourceModel; }
/// <summary> /// Initializes a new instance of <see cref="ConfigurationMerger"/>. /// </summary> /// <param name="mainConfigurationFile">The path to the main configuration file, which should be used to create the environment specific configuration file.</param> /// <param name="mergeSection">The <see cref="EnvironmentalOverridesSection"/> instance that contains the environment specific configuration.</param> public ConfigurationMerger(string mainConfigurationFile, EnvironmentalOverridesSection mergeSection) { this.mainConfigurationFile = mainConfigurationFile; this.mergeSection = mergeSection; }