Exemple #1
0
        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.ResetImplementation(environmentDeltaFilePath, false);
                    FileConfigurationSource fileConfigurationSource = new FileConfigurationSource(environmentDeltaFilePath);
                    if (!string.IsNullOrEmpty(protectionProvider))
                    {
                        fileConfigurationSource.Save(environmentDeltaFilePath, EnvironmentMergeSection.EnvironmentMergeData, environmentMergeSection, protectionProvider);
                    }
                    else
                    {
                        fileConfigurationSource.Save(environmentDeltaFilePath, EnvironmentMergeSection.EnvironmentMergeData, environmentMergeSection);
                    }
                }
                catch (ConfigurationErrorsException configurationErrors)
                {
                    errorService.LogErrors(configurationErrors);
                }
            }
        }
        protected override void Arrange()
        {
            waitForChangedEvents = new CountdownEvent(2);
            ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(1000);

            originalConfigurationFileContents = File.ReadAllText(@"ExternalFileSource.config");

            using (var externalConfigurationFileSource = new FileConfigurationSource(@"ExternalFileSource.config", false))
            {
                externalConfigurationFileSource.Save(FileSourceDummySectionName, new DummySection {
                });
            }

            base.Arrange();

            this.CompositeSource.SourceChanged +=
                (sender, e) =>
            {
                sourceChangedEvents++;
                waitForChangedEvents.Signal();
            };
            this.CompositeSource.AddSectionChangeHandler(
                FileSourceDummySectionName,
                (sender, e) =>
            {
                sectionChangedEvents++;
                waitForChangedEvents.Signal();
            });
        }
        public void CanSaveConfigurationSectionToFile()
        {
            FileConfigurationSource source = new FileConfigurationSource(file, false);

            source.Save(TestConfigurationSection.SectionName, CreateTestSection());

            ValidateConfiguration(file);
        }
Exemple #4
0
        protected override void Arrange()
        {
            originalConfigurationFileContents = File.ReadAllText(@"ExternalFileSource.config");

            FileConfigurationSource externalConfigurationFileSource = new FileConfigurationSource(@"ExternalFileSource.config");

            externalConfigurationFileSource.Save(FileSourceDummySectionName, new DummySection {
            });

            base.Arrange();
        }
        public void Save()
        {
            UserSettings data = this.UserSettings.Clone();

            if (this.Source is FileConfigurationSource)
            {
                FileConfigurationSource fs = this.Source as FileConfigurationSource;
                fs.Save(UserSettings.SectionName, data);
            }

            if (this.Source is SystemConfigurationSource)
            {
                SystemConfigurationSource fs = this.Source as SystemConfigurationSource;
                fs.Save(UserSettings.SectionName, data);
            }
        }
        private void UpdateLoggingTemplate()
        {
            var originalSettings = LoggingSettings.GetLoggingSettings(secondSource);

            var newSettings = new LoggingSettings(originalSettings.Name, originalSettings.TracingEnabled,
                                                  originalSettings.DefaultCategory)
            {
                SpecialTraceSources             = originalSettings.SpecialTraceSources,
                LogWarningWhenNoCategoriesMatch = originalSettings.LogWarningWhenNoCategoriesMatch,
                RevertImpersonation             = originalSettings.RevertImpersonation
            };

            CopyData(originalSettings.TraceListeners, tl => newSettings.TraceListeners.Add(tl));
            CopyData(originalSettings.Formatters, f => newSettings.Formatters.Add(f));
            CopyData(originalSettings.LogFilters, lf => newSettings.LogFilters.Add(lf));
            CopyData(originalSettings.TraceSources, ts => newSettings.TraceSources.Add(ts));

            var formatter = (TextFormatterData)newSettings.Formatters.Get("Text Formatter");

            formatter.Template = "*** " + formatter.Template;

            secondSource.Save(LoggingSettings.SectionName, newSettings);
        }
        public void TryToSaveWithNullSectionThrows()
        {
            FileConfigurationSource source = new FileConfigurationSource(file, false);

            source.Save(TestConfigurationSection.SectionName, null);
        }
        public void TryToSaveWithNullOrEmptySectionNameThrows()
        {
            FileConfigurationSource source = new FileConfigurationSource(file, false);

            source.Save(null, CreateTestSection());
        }