/// <summary>
        /// Removes a <see cref="ConfigurationSection"/> from the configuration source location specified by
        /// <paramref name="removeParameter"/> and saves the configuration source.
        /// </summary>
        /// <param name="removeParameter">The <see cref="IConfigurationParameter"/> that represents the location where
        /// to save the updated configuration. Must be an instance of <see cref="FileConfigurationParameter"/>.</param>
        /// <param name="sectionName">The name of the section to remove.</param>
        public void Remove(IConfigurationParameter removeParameter, string sectionName)
        {
            FileConfigurationParameter parameter = removeParameter as FileConfigurationParameter;

            if (null == parameter)
            {
                throw new ArgumentException(string.Format(Resources.Culture, Resources.ExceptionUnexpectedType, typeof(FileConfigurationParameter).Name), "saveParameter");
            }

            Remove(parameter.FileName, sectionName);
        }
Пример #2
0
        /// <summary>
        /// TODO: add comment
        /// </summary>
        /// <param name="saveParameter"></param>
        /// <param name="sectionName"></param>
        /// <param name="configurationSection"></param>
        /// <param name="protectionProviderName"></param>
        public void Add(IConfigurationParameter saveParameter, string sectionName, ConfigurationSection configurationSection, string protectionProviderName)
        {
            FileConfigurationParameter parameter = saveParameter as FileConfigurationParameter;

            if (null == parameter)
            {
                throw new ArgumentException(string.Format(Resources.Culture, Resources.ExceptionUnexpectedType, typeof(FileConfigurationParameter).Name), "saveParameter");
            }

            Save(parameter.FileName, sectionName, configurationSection, protectionProviderName);
        }
		public void RemovingAndAddingSection()
		{
			SystemConfigurationSource.ResetImplementation(true);
			SystemConfigurationSource sysSource = new SystemConfigurationSource();

			DummySection dummySection = sysSource.GetSection(localSection) as DummySection;
			Assert.IsTrue(dummySection != null);

			System.Threading.Thread.Sleep(300);

			System.Configuration.Configuration rwConfiguration =
				ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
			string fileName = rwConfiguration.FilePath;
			int numSections = rwConfiguration.Sections.Count;
			FileConfigurationParameter parameter = new FileConfigurationParameter(fileName);
			sysSource.Remove(parameter, localSection);

			System.Threading.Thread.Sleep(300);

			rwConfiguration =
				ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
			Assert.AreEqual(rwConfiguration.Sections.Count, numSections - 1);
			sysSource.Add(parameter, localSection, new DummySection());	// can't be the same instance

			System.Threading.Thread.Sleep(300);
			rwConfiguration =
				ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
			Assert.AreEqual(rwConfiguration.Sections.Count, numSections);
		}
Пример #4
0
        /// <exclude />
        public static void SaveConfigurationSection(string sectionName, ConfigurationSection configurationSection)
        {
            using (GlobalInitializerFacade.CoreLockScope)
            {
                lock (_lock)
                {
                    string tempFilePath = ConfigurationServices.TempRandomConfigFilePath;
                    C1File.Copy(FileConfigurationSourcePath, tempFilePath);
                    FileConfigurationParameter configurationParameter = new FileConfigurationParameter(tempFilePath);
                    ConfigurationServices.ConfigurationSource.Add(configurationParameter, sectionName, configurationSection);
                    // Kill monitoring of file changes:
                    //                    FileConfigurationSource.ResetImplementation(ConfigurationServices.FileConfigurationSourcePath, false);
                    C1File.Copy(tempFilePath, ConfigurationServices.FileConfigurationSourcePath, true);
                    DeleteTempConfigurationFile(tempFilePath);

                    _configurationSource = new FileConfigurationSource(ConfigurationServices.FileConfigurationSourcePath);
                    // Kill monitoring of file changes:
                    //                    FileConfigurationSource.ResetImplementation(ConfigurationServices.FileConfigurationSourcePath, false);
                }
            }
        }