コード例 #1
0
        /// <summary>
        /// <para>Load the configured protection mechanism for the section. This is the <see cref="KeyAlgorithmPairStorageProviderData"/> to load the <see cref="KeyAlgorithmPair"/>.</para>
        /// </summary>
        /// <param name="sectionName">
        /// <para>The name of the section to encrypt.</para>
        /// </param>
        /// <param name="context">
        /// <para>A <see cref="ConfigurationContext"/> object.</para>
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="context"/> is a <see langword="null"/> reference (Nothing in Visual Basic).</para>
        /// </exception>
        /// <exception cref="ConfigurationException">
        /// <para>An error occured in configuration.</para>
        /// </exception>
        public void Load(ConfigurationContext context, string sectionName)
        {
            ArgumentValidation.CheckForNullReference(context, "context");
            ArgumentValidation.CheckForNullReference(sectionName, "sectionName");
            ArgumentValidation.CheckForEmptyString(sectionName, "sectionName");

            ConfigurationSettings    settings = context.GetMetaConfiguration();
            ConfigurationSectionData data     = settings.ConfigurationSections[sectionName];

            if (null == data)
            {
                InvalidSectionExceptionBuilder builder = new InvalidSectionExceptionBuilder(sectionName, context.ConfigurationFile);
                throw builder.ThrowException();
            }

            if ((null == settings.KeyAlgorithmPairStorageProviderData) && (data.Encrypt))
            {
                throw new ConfigurationException(SR.ExceptionNoKeyAlgorithmStorageProvider);
            }

            if (data.Encrypt)
            {
                SetDataToBeEncrypted(context);
            }
        }
コード例 #2
0
        /// <summary>
        /// <para>Adds an <see cref="ConfigurationSectionData"/> into the collection.</para>
        /// </summary>
        /// <param name="configurationSection">
        /// <para>The <see cref="ConfigurationSectionData"/> to add. The value can not be a <see langword="null"/> reference (Nothing in Visual Basic).</para>
        /// </param>
        /// <remarks>
        /// <para>If a reference already exists in the collection by <seealso cref="ConfigurationSectionData.Name"/>, it will be replaced with the new reference.</para>
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="configurationSection"/> is a <see langword="null"/> reference (Nothing in Visual Basic).</para>
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// <para><seealso cref="ConfigurationSectionData.Name"/> is a <see langword="null"/> reference (Nothing in Visual Basic).</para>
        /// </exception>
        public void Add(ConfigurationSectionData configurationSection)
        {
            ArgumentValidation.CheckForNullReference(configurationSection, "configurationSection");

            ArgumentValidation.CheckForInvalidNullNameReference(configurationSection.Name, "configuraitonSection");

            BaseAdd(configurationSection.Name, configurationSection);
        }
コード例 #3
0
        /// <summary>
        /// <para>Determines if a section name is valid in the current configuration file.</para>
        /// </summary>
        /// <param name="sectionName">
        /// <para>The name of the section to validate.</para>
        /// </param>
        /// <returns><see langword="true"/> if the section name is valid; otherwise, <see langword="false"/></returns>
        public bool IsValidSection(string sectionName)
        {
            if (this.configurationSettings == null)
            {
                return(false);
            }
            ConfigurationSectionData configurationSection = this.configurationSettings.ConfigurationSections[sectionName];

            return(configurationSection != null);
        }
コード例 #4
0
 /// <summary>
 /// <para>
 /// Write the meta configuration for the configuration manager to the configuration file.
 /// </para>
 /// </summary>
 /// <param name="configurationSectionData">
 /// The meta configuration to write to configuration.
 /// </param>
 /// <exception cref="ConfigurationException">
 /// <para>An error occured while reading the configuration to save the data.</para>
 /// </exception>
 /// <exception cref="InvalidOperationException">
 /// <para>The configuration section already exists.</para>
 /// </exception>
 public void WriteMetaConfig(ConfigurationSectionData configurationSectionData)
 {
     configurationSettings.ConfigurationSections.Add(configurationSectionData);
     if (UserAcceptsMetaConfigurationChange(configurationSettings) == true)
     {
         SaveMetaConfigurationChanges(configurationSettings);
     }
     else
     {
         configurationSettings.ConfigurationSections.Remove(configurationSectionData.Name);
     }
 }
コード例 #5
0
        /// <summary>
        /// <para>Retrieves the <see cref="TransformerData"/> for the section.</para>
        /// </summary>
        /// <param name="sectionName">
        /// <para>The name of the section to get the <see cref="TransformerData"/></para>
        /// </param>
        /// <returns>
        /// <para>The <see cref="TransformerData"/> for the section.</para>
        /// </returns>
        public virtual TransformerData GetTransformerProviderData(string sectionName)
        {
            ConfigurationSettings settings = GetConfigurationSettings();

            ConfigurationSectionData configurationSectionData = settings.ConfigurationSections[sectionName];

            if (configurationSectionData == null)
            {
                InvalidSectionExceptionBuilder builder = new InvalidSectionExceptionBuilder(sectionName, ConfigurationContext.ConfigurationFile);
                throw builder.ThrowException();
            }

            return(configurationSectionData.Transformer);
        }
コード例 #6
0
 private void CloneConfigurationSettingsFromContextDictionary(ConfigurationDictionary dictionary)
 {
     // we need to make sure to check if the meta config is in the dictionary and clone it
     // so we get our own copy of the data
     if (dictionary.Contains(ConfigurationSettings.SectionName))
     {
         ConfigurationSettings settings = dictionary[ConfigurationSettings.SectionName] as ConfigurationSettings;
         configurationSettings.KeyAlgorithmPairStorageProviderData = (KeyAlgorithmPairStorageProviderData)((null != settings.KeyAlgorithmPairStorageProviderData) ? settings.KeyAlgorithmPairStorageProviderData.Clone() : null);
         foreach (ConfigurationSectionData data in settings.ConfigurationSections)
         {
             ConfigurationSectionData cloneData = new ConfigurationSectionData(data.Name, data.Encrypt,
                                                                               (null != data.StorageProvider) ? (StorageProviderData)data.StorageProvider.Clone() : null,
                                                                               (null != data.Transformer) ? (TransformerData)data.Transformer.Clone() : null);
             configurationSettings.ConfigurationSections.Add(cloneData);
         }
         sections.Remove(ConfigurationSettings.SectionName);
     }
 }
コード例 #7
0
 /// <summary>
 /// <para>
 /// Write the meta configuration for the configuration manager to the configuration file.
 /// </para>
 /// </summary>
 /// <param name="configurationSectionData">
 /// The meta configuration to write to configuration.
 /// </param>
 /// <exception cref="ConfigurationException">
 /// <para>An error occured while reading the configuration to save the data.</para>
 /// </exception>
 /// <exception cref="InvalidOperationException">
 /// <para>The configuration section already exists.</para>
 /// </exception>
 public void WriteMetaConfiguration(ConfigurationSectionData configurationSectionData)
 {
     disposableWrapper.ConfigurationBuilder.WriteMetaConfig(configurationSectionData);
 }
コード例 #8
0
        /// <summary>
        /// <para>Adds an <see cref="ConfigurationSectionData"/> into the collection.</para>
        /// </summary>
        /// <param name="configurationSection">
        /// <para>The <see cref="ConfigurationSectionData"/> to add. The value can not be a <see langword="null"/> reference (Nothing in Visual Basic).</para>
        /// </param>
        /// <remarks>
        /// <para>If a reference already exists in the collection by <seealso cref="ConfigurationSectionData.Name"/>, it will be replaced with the new reference.</para>
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="configurationSection"/> is a <see langword="null"/> reference (Nothing in Visual Basic).</para>
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// <para><seealso cref="ConfigurationSectionData.Name"/> is a <see langword="null"/> reference (Nothing in Visual Basic).</para>
        /// </exception>
        public void Add(ConfigurationSectionData configurationSection)
        {
            ArgumentValidation.CheckForNullReference(configurationSection, "configurationSection");

            ArgumentValidation.CheckForInvalidNullNameReference(configurationSection.Name, "configuraitonSection");

            BaseAdd(configurationSection.Name, configurationSection);
        }
コード例 #9
0
 /// <summary>
 /// <para>Copies the entire <see cref="ConfigurationSectionDataCollection"/> to a compatible one-dimensional <see cref="ConfigurationSectionData"/> array, starting at the specified index of the target array.</para>
 /// </summary>
 /// <param name="array">
 /// <para>The one-dimensional <see cref="ConfigurationSectionData"/> array that is the destination of the elements copied from <see cref="ConfigurationSectionDataCollection"/>. The <see cref="ConfigurationSectionData"/> array must have zero-based indexing.</para>
 /// </param>
 /// <param name="index">
 /// <para>The zero-based index in array at which copying begins.</para>
 /// </param>
 public void CopyTo(ConfigurationSectionData[] array, int index)
 {
     for (IEnumerator e = this.GetEnumerator(); e.MoveNext(); )
     {
         array.SetValue(e.Current, index++);
     }
 }
コード例 #10
0
 /// <summary>
 /// <para>
 /// Write the meta configuration for the configuration manager to the configuration file.
 /// </para>
 /// </summary>
 /// <param name="configurationSectionData">
 /// The meta configuration to write to configuration.
 /// </param>
 /// <exception cref="ConfigurationException">
 /// <para>An error occured while reading the configuration to save the data.</para>
 /// </exception>
 /// <exception cref="InvalidOperationException">
 /// <para>The configuration section already exists.</para>
 /// </exception>
 public void WriteMetaConfiguration(ConfigurationSectionData configurationSectionData)
 {
     disposableWrapper.ConfigurationBuilder.WriteMetaConfig(configurationSectionData);
 }
コード例 #11
0
 private void CloneConfigurationSettingsFromContextDictionary(ConfigurationDictionary dictionary)
 {
     // we need to make sure to check if the meta config is in the dictionary and clone it
     // so we get our own copy of the data
     if (dictionary.Contains(ConfigurationSettings.SectionName))
     {
         ConfigurationSettings settings = dictionary[ConfigurationSettings.SectionName] as ConfigurationSettings;
         configurationSettings.KeyAlgorithmPairStorageProviderData = (KeyAlgorithmPairStorageProviderData)((null != settings.KeyAlgorithmPairStorageProviderData) ? settings.KeyAlgorithmPairStorageProviderData.Clone() : null);
         foreach (ConfigurationSectionData data in settings.ConfigurationSections)
         {
             ConfigurationSectionData cloneData = new ConfigurationSectionData(data.Name, data.Encrypt,
                 (null != data.StorageProvider) ? (StorageProviderData)data.StorageProvider.Clone() : null,
                 (null != data.Transformer) ? (TransformerData)data.Transformer.Clone() : null);
             configurationSettings.ConfigurationSections.Add(cloneData);
         }
         sections.Remove(ConfigurationSettings.SectionName);
     }
 }
コード例 #12
0
 /// <summary>
 /// <para>
 /// Write the meta configuration for the configuration manager to the configuration file.
 /// </para>
 /// </summary>
 /// <param name="configurationSectionData">
 /// The meta configuration to write to configuration.
 /// </param>
 /// <exception cref="ConfigurationException">
 /// <para>An error occured while reading the configuration to save the data.</para>
 /// </exception>
 /// <exception cref="InvalidOperationException">
 /// <para>The configuration section already exists.</para>
 /// </exception>
 public void WriteMetaConfig(ConfigurationSectionData configurationSectionData)
 {
     configurationSettings.ConfigurationSections.Add(configurationSectionData);
     if (UserAcceptsMetaConfigurationChange(configurationSettings) == true)
     {
         SaveMetaConfigurationChanges(configurationSettings);
     }
     else
     {
         configurationSettings.ConfigurationSections.Remove(configurationSectionData.Name);
     }
 }