示例#1
0
        /// <summary>
        /// Reads all configuration settings from Windows registry.
        /// </summary>
        /// <returns>Read settings as <see cref="Hashtable"/>.</returns>
        private SettingsCollection LoadSettings()
        {
            SettingsCollection result = new SettingsCollection();

            this.ReadNodeContentRecursive(this.RootConfigNode, ref result);
            return(result);
        }
示例#2
0
        /// <summary>
        /// Override this in child class to implement custom initialization.
        /// </summary>
        /// <param name="configurationSection">The section.</param>
        protected override void MemberwiseInitialize(ConfSection configurationSection)
        {
            sectionName = GetSettingsValue(SectionNameAttributeName);

            if (string.IsNullOrEmpty(this.sectionName))
            {
                throw new InvalidOperationException("Missing parameter \"" + SectionNameAttributeName + "\".");
            }

            var values = ConfigurationManager.GetSection(this.sectionName) as NameValueCollection;

            if (values == null)
            {
                throw new SectionNotFoundException("Section \"" + this.sectionName + "\" is not found.");
            }

            SettingsCollection v = new SettingsCollection();

            foreach (string key in values.AllKeys)
            {
                v.Add(key, values.Get(key));
            }

            Values = v;
        }
示例#3
0
 /// <summary>
 /// Reads the content of the node.
 /// </summary>
 /// <param name="hiveKey">The hive key.</param>
 /// <param name="collection">The collection.</param>
 private static void ReadNodeContent(RegistryKey hiveKey, ref SettingsCollection collection)
 {
     foreach (string key in hiveKey.GetValueNames())
     {
         string value = Convert.ToString(hiveKey.GetValue(key), CultureInfo.InvariantCulture);
         collection.Add(key, value);
     }
 }
示例#4
0
        /// <summary>
        /// Reads the node content recursive.
        /// </summary>
        /// <param name="hiveKey">The hive key.</param>
        /// <param name="collection">The collection.</param>
        private void ReadNodeContentRecursive(RegistryKey hiveKey, ref SettingsCollection collection)
        {
            ReadNodeContent(hiveKey, ref collection);

            string[] hives = hiveKey.GetSubKeyNames();
            foreach (string hive in hives)
            {
                this.ReadNodeContentRecursive(hiveKey.OpenSubKey(hive), ref collection);
            }
        }
示例#5
0
        /// <summary>
        /// Make call to a webservice to get all configuration settings.
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <returns>Get settings collection <see cref="SettingsCollection"/>.</returns>
        private static SettingsCollection GetSettings(Provider provider)
        {
            var settingsData = provider.GetSettings();

            // Convert to SettingsCollection
            var collection = new SettingsCollection();

            foreach (var setting in settingsData)
            {
                collection.Add(setting.Key, setting.Value);
            }

            return(collection);
        }
示例#6
0
文件: Settings.cs 项目: wolsk1/ratio
        /// <summary>
        /// Reload all providers with data from data sources and rebuild configurations list
        /// </summary>
        public static void Reload()
        {
            if (providers == null)
            {
                throw new InvalidOperationException("Providers collection is null.");
            }

            lock (syncRoot)
            {
                settings = new SettingsCollection();
                foreach (ISettingsProvider provider in providers)
                {
                    provider.Reload();
                    CopyProviderData(provider);
                }
            }
        }
示例#7
0
文件: Settings.cs 项目: wolsk1/ratio
        /// <summary>
        /// Re-read all configuration values from providers.
        /// </summary>
        public static void Refresh()
        {
            if (providers == null)
            {
                throw new InvalidOperationException("Providers collection is null.");
            }

            // If there are no any providers than clean up settings
            lock (syncRoot)
            {
                settings = new SettingsCollection();
                foreach (ISettingsProvider provider in providers)
                {
                    CopyProviderData(provider);
                }
            }
        }
示例#8
0
        public SettingsCollection ReadSettings(XmlNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            SettingsCollection settings = new SettingsCollection();
            XmlNodeList        keys     = node.ChildNodes;

            foreach (XmlNode key in keys)
            {
                if (key.NodeType != XmlNodeType.Comment)
                {
                    settings.Add(key.Attributes.GetNamedItem("key").InnerText,
                                 key.Attributes.GetNamedItem("value").InnerText);
                }
            }

            return(settings);
        }
示例#9
0
文件: Settings.cs 项目: wolsk1/ratio
        /// <summary>
        /// Tests the instance.
        /// </summary>
        private static void TestInstance()
        {
            if (settings == null)
            {
                lock (syncRoot)
                {
                    settings  = new SettingsCollection();
                    providers = new Collection <ISettingsProvider>();

                    try
                    {
                        GetProviders();
                    }
                    catch (ConfigurationErrorsException)
                    {
                        /*
                         * if during executing there will be no configuration context
                         * empty settings provider will be created to provider and empty settings store there will be no keys
                         */
                    }
                }
            }
        }
 /// <summary>
 /// Initializes the specified section.
 /// </summary>
 /// <param name="configurationSection">The section.</param>
 public void Initialize(ConfSection configurationSection)
 {
     this.values = new SettingsCollection();
 }
 /// <summary>
 /// Reload provider data
 /// </summary>
 public void Reload()
 {
     this.values = null;
 }