Exemple #1
0
        // Methods
        public void Add(string entityName, ReflectBuilder builder)
        {
            #region Contracts

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

            #endregion

            // Setting
            ReflectSetting setting = builder.ToSetting();
            if (setting == null)
            {
                throw new InvalidOperationException();
            }

            // Repository
            _repository.AddSetting(_groupName, entityName, setting);
        }
Exemple #2
0
        public ReflectBuilder GetValue(string entityName)
        {
            #region Contracts

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

            #endregion

            // Setting
            ReflectSetting setting = _repository.GetSetting(_groupName, entityName);
            if (setting == null)
            {
                return(null);
            }

            // Builder
            ReflectBuilder builder = setting.ToBuilder();
            if (builder == null)
            {
                throw new InvalidOperationException();
            }

            // Return
            return(builder);
        }
Exemple #3
0
        // Convert
        public static ReflectBuilder ToBuilder(this ReflectSetting setting)
        {
            #region Contracts

            if (setting == null)
            {
                throw new ArgumentNullException();
            }

            #endregion

            // Type
            Type type = Type.GetType(setting.BuilderType);
            if (type == null)
            {
                throw new InvalidOperationException(string.Format("Fail to create type:{0}", setting.BuilderType));
            }

            // Builder
            ReflectBuilder builder = Activator.CreateInstance(type) as ReflectBuilder;
            if (type == null)
            {
                throw new InvalidOperationException(string.Format("Fail to create instance:{0}", setting.BuilderType));
            }

            // Parameters
            foreach (string parameterKey in setting.Parameters.Keys)
            {
                builder.Parameters.Add(parameterKey, setting.Parameters[parameterKey]);
            }

            // Return
            return(builder);
        }
        // Convert
        public static ReflectSetting ToSetting(this ReflectBuilder builder)
        {
            #region Contracts

            if (builder == null) throw new ArgumentNullException();

            #endregion

            // Create
            ReflectSetting setting = new ReflectSetting(builder.GetType().AssemblyQualifiedName);

            // Parameters
            foreach (string parameterKey in builder.Parameters.Keys)
            {
                setting.Parameters.Add(parameterKey, builder.Parameters[parameterKey]);
            }

            // Return
            return setting;
        }
Exemple #5
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();
        }
Exemple #6
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);
        }
        // Convert
        public static ReflectSetting ToSetting(this ReflectBuilder builder)
        {
            #region Contracts

            if (builder == null)
            {
                throw new ArgumentNullException();
            }

            #endregion

            // Create
            ReflectSetting setting = new ReflectSetting(builder.GetType().AssemblyQualifiedName);

            // Parameters
            foreach (string parameterKey in builder.Parameters.Keys)
            {
                setting.Parameters.Add(parameterKey, builder.Parameters[parameterKey]);
            }

            // Return
            return(setting);
        }
        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;
        }
        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();
        }