/// <summary>
        /// Returns a subordinate <see cref="IConfigurationSource"/> with the specified name.<br/>
        /// Throws <see cref="ConfigurationSourceErrorsException"/> if the source was not found.
        /// </summary>
        /// <param name="sourceName">The name of the source that should be returned.</param>
        /// <returns>The <see cref="IConfigurationSource"/> instance.</returns>
        protected IConfigurationSource GetSubordinateSource(string sourceName)
        {
            SubordinateSource sourceHolder = null;

            if (subordinateSourcesByName.TryGetValue(sourceName, out sourceHolder))
            {
                return(sourceHolder.Source);
            }

            return(CreateSubordinateSource(sourceName, true));
        }
 private void RefreshExistingSectionMappings()
 {
     if (sectionMappings.Count > 0)
     {
         foreach (SectionInSubordinateSource sectionInSubordinateSource in sectionMappings.Values.ToArray())
         {
             SubordinateSource subordinateSource = null;
             if (!subordinateSourcesByName.TryGetValue(sectionInSubordinateSource.SubordinateSourceName, out subordinateSource))
             {
                 sectionMappings.Remove(sectionInSubordinateSource.SectionName);
             }
             else
             {
                 if (subordinateSource.Source != null)
                 {
                     sectionInSubordinateSource.Refresh(subordinateSource.Source);
                 }
             }
         }
     }
 }
        private IConfigurationSource CreateSubordinateSource(string sourceName, bool throwWhenNotFound)
        {
            EnsureInitialized();

            ConfigurationSourceSection configurationSourcesSection = configurationSource.GetSection(ConfigurationSourceSection.SectionName) as ConfigurationSourceSection;

            if (configurationSourcesSection == null)
            {
                return(null);
            }
            else
            {
                var configurationSourceElement = configurationSourcesSection.Sources
                                                 .Where(x => x.Name == sourceName)
                                                 .FirstOrDefault();

                if (configurationSourceElement == null)
                {
                    if (throwWhenNotFound)
                    {
                        string message = string.Format(CultureInfo.CurrentCulture,
                                                       Resources.ExceptionConfigurationSourceNotFound,
                                                       sourceName,
                                                       ConfigurationSourceSection.SectionName);

                        throw new ConfigurationSourceErrorsException(message);
                    }
                    else
                    {
                        return(null);
                    }
                }
                IConfigurationSource source = configurationSourceElement.CreateSource();

                SubordinateSource sourceHolder = new SubordinateSource(this, sourceName, source);
                subordinateSourcesByName[sourceName] = sourceHolder;

                return(source);
            }
        }
        /// <summary>
        /// Adds a subordinate <see cref="IConfigurationSource"/> to the <see cref="ConfigurationSourceHandler"/>.
        /// This <see cref="IConfigurationSource"/> will not be refreshed or disposed.
        /// </summary>
        /// <param name="sourceName">The name under which the <see cref="IConfigurationSource"/> will be added.</param>
        /// <param name="configurationSource">The <see cref="IConfigurationSource"/> that will be added.</param>
        protected void AddCustomSubordinateSource(string sourceName, IConfigurationSource configurationSource)
        {
            SubordinateSource sourceHolder = new SubordinateSource(this, sourceName, configurationSource, true);

            subordinateSourcesByName.Add(sourceName, sourceHolder);
        }
        private IConfigurationSource CreateSubordinateSource(string sourceName, bool throwWhenNotFound)
        {
            EnsureInitialized();

            ConfigurationSourceSection configurationSourcesSection = configurationSource.GetSection(ConfigurationSourceSection.SectionName) as ConfigurationSourceSection;
            if (configurationSourcesSection == null)
            {
                return null;
            }
            else
            {
                var configurationSourceElement = configurationSourcesSection.Sources
                                                    .Where(x => x.Name == sourceName)
                                                    .FirstOrDefault();

                if (configurationSourceElement == null)
                {
                    if (throwWhenNotFound)
                    {
                        string message = string.Format(CultureInfo.CurrentCulture,
                            Resources.ExceptionConfigurationSourceNotFound,
                            sourceName,
                            ConfigurationSourceSection.SectionName);

                        throw new ConfigurationSourceErrorsException(message);
                    }
                    else
                    {
                        return null;
                    }
                }
                IConfigurationSource source = configurationSourceElement.CreateSource();

                SubordinateSource sourceHolder = new SubordinateSource(this, sourceName, source);
                subordinateSourcesByName[sourceName] = sourceHolder;

                return source;

            }
        }
 /// <summary>
 /// Adds a subordinate <see cref="IConfigurationSource"/> to the <see cref="ConfigurationSourceHandler"/>.
 /// This <see cref="IConfigurationSource"/> will not be refreshed or disposed.
 /// </summary>
 /// <param name="sourceName">The name under which the <see cref="IConfigurationSource"/> will be added.</param>
 /// <param name="configurationSource">The <see cref="IConfigurationSource"/> that will be added.</param>
 protected void AddCustomSubordinateSource(string sourceName, IConfigurationSource configurationSource)
 {
     SubordinateSource sourceHolder = new SubordinateSource(this, sourceName, configurationSource, true);
     subordinateSourcesByName.Add(sourceName, sourceHolder);
 }