Beispiel #1
0
        private void LoadSections()
        {
            SectionList loadedSections = _loader.Load();

            CheckForPresenseOfGlobalSection(loadedSections);
            _sections.AddRange(loadedSections);
        }
Beispiel #2
0
 private static void CheckForPresenseOfGlobalSection(SectionList loadedSections)
 {
     if (loadedSections == null || loadedSections.Count == 0 || !loadedSections [0].IsGlobal)
     {
         throw new ConfigurationException(
                   "The loaded sections should contain at least one section. The first section should be named 'Global'");
     }
 }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the ConfigurationHandler class.
        /// </summary>
        /// <param name="loader"></param>
        public ConfigurationHandler(IConfigurationLoader loader,
                                    SectionList predefinedSections,
                                    List <ISettingParser> settingParsers,
                                    List <ISettingsProcessor> processors)
        {
            _loader = loader;

            _predefinedSections.AddRange(predefinedSections);

            RegisterParsers(settingParsers);
            RegisterProcessors(processors);
            RegisterForLoaderSettingsChanged();
        }
Beispiel #4
0
        //Helper methods
        public static IConfigurationHandler CreateConfig(Dictionary <string, object> settings)
        {
            Section globalSection = new Section("Global");

            foreach (KeyValuePair <string, object> pair in settings)
            {
                globalSection.Add(Setting.CreateProcessedSetting(pair.Key, pair.Value));
            }
            var sections = new SectionList()
            {
                globalSection
            };
            ConfigurationHandler config = new ConfigurationHandler(new SettingsConfigurationLoader(globalSection));

            config.LoadSettings();
            return(config);
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the ConfigurationHandler class.
 /// </summary>
 /// <param name="loader"></param>
 public ConfigurationHandler(IConfigurationLoader loader, SectionList predefinedSections)
     : this(loader, predefinedSections, new List <ISettingParser> (), new List <ISettingsProcessor> ())
 {
 }