public virtual void Save(IServiceProvider serviceProvider)
        {
            ConfigurationSectionInfo info = null;
            ConfigurationNode        node = ServiceHelper.GetCurrentRootNode(serviceProvider);

            try
            {
                IConfigurationSource    configurationSource = GetConfigurationSource(serviceProvider);
                IConfigurationParameter parameter           = GetConfigurationParameter(serviceProvider);

                info = GetConfigurationSectionInfo(serviceProvider);
                if (null != info && !string.IsNullOrEmpty(info.SectionName))
                {
                    if (null != info.Section)
                    {
                        configurationSource.Add(parameter, info.SectionName, info.Section);
                    }
                    else
                    {
                        configurationSource.Remove(parameter, info.SectionName);
                    }
                }
            }
            catch (Exception e)
            {
                ServiceHelper.LogError(serviceProvider, info != null ? info.Node : node, e);
            }
        }
コード例 #2
0
        public void AddGetAndRemoveASection()
        {
            IConfigurationSource source = ConfigurationSourceFactory.Create("sqlSource");

            Assert.AreEqual(typeof(SqlConfigurationSource), source.GetType());

            DummySection dummySection1 = new DummySection();

            dummySection1.Value = 10;

            source.Add(CreateParameter(), localSection, dummySection1);

            ConfigurationSection newSection = source.GetSection(localSection);

            Assert.AreEqual(typeof(DummySection), newSection.GetType());

            DummySection dummySection2 = newSection as DummySection;

            Assert.AreEqual(dummySection1, dummySection2);

            source.Remove(CreateParameter(), localSection);

            newSection = source.GetSection(localSection);
            Assert.AreEqual(null, newSection);
        }
コード例 #3
0
 /// <summary>
 /// Updates a configuration source replacing any existing sections with those
 /// built up with the builder.
 /// </summary>
 /// <param name="source"></param>
 public void UpdateConfigurationWithReplace(IConfigurationSource source)
 {
     foreach (var section in configurationSource.sections)
     {
         source.Remove(section.Key);
         source.Add(section.Key, section.Value);
     }
 }
        /// <summary>
        /// Checks whether a call to <see cref="IConfigurationSource.Remove(string)"/> should be deferred to a subordinate source.<br/>
        /// If the call should be deferred, removes the section from the appropriate source and returns <see langword="true"/>.<br/>
        /// If the call should not be deferred returns <see langword="true"/>.
        /// </summary>
        /// <param name="sectionName">The name of the section that should be removed from configuration.</param>
        /// <returns><see langword="true"/> if the section was removed from a subordinate source, otherwise <see langword="false"/>.</returns>
        /// <seealso cref="IConfigurationSource.Remove(string)"/>
        protected override bool DoCheckRemoveSection(string sectionName)
        {
            string sourceNameForSection;

            if (sectionRedirectTable.TryGetValue(sectionName, out sourceNameForSection))
            {
                IConfigurationSource subordinateSource = GetSubordinateSource(sourceNameForSection);
                subordinateSource.Remove(sectionName);
                return(true);
            }
            return(false);
        }