Example #1
0
        public bool ContainsSetting(string groupName, string entityName)
        {
            #region Contracts

            if (string.IsNullOrEmpty(groupName) == true)
            {
                throw new ArgumentNullException();
            }
            if (string.IsNullOrEmpty(entityName) == true)
            {
                throw new ArgumentNullException();
            }

            #endregion

            // Section
            ReflectConfigurationSection section = _configuration.GetSection(groupName) as ReflectConfigurationSection;
            if (section == null)
            {
                throw new InvalidOperationException(string.Format("Fail to Get ReflectConfigurationSection:{0}", groupName));
            }

            // Element
            ReflectConfigurationElement element = section.ElementCollection.GetByName(entityName);
            if (element == null)
            {
                return(false);
            }

            // Return
            return(true);
        }
Example #2
0
        public void AddSetting(string groupName, string entityName, ReflectSetting setting)
        {
            #region Contracts

            if (string.IsNullOrEmpty(groupName) == true)
            {
                throw new ArgumentNullException();
            }
            if (string.IsNullOrEmpty(entityName) == true)
            {
                throw new ArgumentNullException();
            }
            if (setting == null)
            {
                throw new ArgumentNullException();
            }

            #endregion

            // Section
            ReflectConfigurationSection section = _configuration.GetSection(groupName) as ReflectConfigurationSection;
            if (section == null)
            {
                throw new InvalidOperationException(string.Format("Fail to Get ReflectConfigurationSection:{0}", groupName));
            }

            // Element
            ReflectConfigurationElement element = new ReflectConfigurationElement();
            element.EntityName  = entityName;
            element.BuilderType = setting.BuilderType;
            foreach (string parameterKey in setting.Parameters.Keys)
            {
                element.FreeAttributes.Add(parameterKey, setting.Parameters[parameterKey]);
            }

            // Add
            section.ElementCollection.Add(element);

            // Save
            section.CurrentConfiguration.Save();
        }
Example #3
0
        public ReflectSetting GetSetting(string groupName, string entityName)
        {
            #region Contracts

            if (string.IsNullOrEmpty(groupName) == true)
            {
                throw new ArgumentNullException();
            }
            if (string.IsNullOrEmpty(entityName) == true)
            {
                throw new ArgumentNullException();
            }

            #endregion

            // Section
            ReflectConfigurationSection section = _configuration.GetSection(groupName) as ReflectConfigurationSection;
            if (section == null)
            {
                throw new InvalidOperationException(string.Format("Fail to Get ReflectConfigurationSection:{0}", groupName));
            }

            // Element
            ReflectConfigurationElement element = section.ElementCollection.GetByName(entityName);
            if (element == null)
            {
                return(null);
            }

            // Setting
            ReflectSetting setting = new ReflectSetting(element.BuilderType);
            foreach (string parameterKey in element.FreeAttributes.Keys)
            {
                setting.Parameters.Add(parameterKey, element.FreeAttributes[parameterKey]);
            }

            // Return
            return(setting);
        }
Example #4
0
        public void AddSetting(string groupName, string entityName, ReflectSetting setting)
        {
            #region Contracts

            if (string.IsNullOrEmpty(groupName) == true) throw new ArgumentNullException();
            if (string.IsNullOrEmpty(entityName) == true) throw new ArgumentNullException();
            if (setting == null) throw new ArgumentNullException();

            #endregion

            // Section
            ReflectConfigurationSection section = _configuration.GetSection(groupName) as ReflectConfigurationSection;
            if (section == null) throw new InvalidOperationException(string.Format("Fail to Get ReflectConfigurationSection:{0}", groupName));

            // Element
            ReflectConfigurationElement element = new ReflectConfigurationElement();
            element.EntityName = entityName;
            element.BuilderType = setting.BuilderType;
            foreach (string parameterKey in setting.Parameters.Keys)
            {
                element.FreeAttributes.Add(parameterKey, setting.Parameters[parameterKey]);
            }

            // Add
            section.ElementCollection.Add(element);

            // Save
            section.CurrentConfiguration.Save();
        }