Example #1
0
        /// <summary>
        /// 保存时 对当前配置项进行赋值
        /// </summary>
        /// <param name="item">当前配置项</param>
        /// <param name="ListOptions">配置项值</param>
        public void SetValue(ConfigOption item, List <Options> ListOptions)
        {
            //调用保存后处理事件
            item.AfterSave(ListOptions);

            var     desc   = ConfigDescriptionCache.GetTypeDiscription(item.GetType());
            Options option = null;

            foreach (PropertyInfo prop in desc.StaticPropertyInfo)
            {
                option = ListOptions.First(e => e.Key.Equals(prop.Name, StringComparison.OrdinalIgnoreCase));
                if (option == null)
                {
                    //不存在该配置项,则清空当前值
                    prop.SetValue(null, Convert.ChangeType(null, prop.PropertyType), null);
                }
                else
                {
                    prop.SetValue(null, Convert.ChangeType(option.Value, prop.PropertyType), null);
                }
            }
        }
Example #2
0
        /// <summary>
        /// 初始化系统参数配置信息
        /// </summary>
        public void Init()
        {
            //所有选项值
            List <Options> listOption = ConfigService.GetAllOptions();

            ConfigDescription desc = null;

            //代码现有配置项
            foreach (ConfigOption item in AllConfig)
            {
                //反射读取配置项ConfigTypeAttribute  ConfigAttribute 信息
                desc = ConfigDescriptionCache.GetTypeDiscription(item.GetType());

                //设置当前配置项的GroupType
                desc.GroupTypePropertyInfo.SetValue(item, Convert.ChangeType(desc.Group, desc.GroupTypePropertyInfo.PropertyType), null);

                //每项值信息
                List <Options>  itemOptions = listOption.Where(e => e.OptionType.Equals(desc.Group, StringComparison.OrdinalIgnoreCase)).ToList();
                Options         op          = null;
                ConfigAttribute ca          = null;
                foreach (PropertyInfo prop in desc.StaticPropertyInfo)
                {
                    op = itemOptions.FirstOrDefault(e1 => e1.Key.Equals(prop.Name, StringComparison.OrdinalIgnoreCase));
                    ca = desc.MemberDict[prop.Name];
                    if (op == null)
                    {
                        //设置默认值
                        prop.SetValue(null, Convert.ChangeType(ca.DefaultValue, prop.PropertyType), null);
                    }
                    else
                    {
                        prop.SetValue(null, Convert.ChangeType(op.Value, prop.PropertyType), null);
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// 获取所有配置信息
        /// </summary>
        /// <returns>所有配置信息</returns>
        public List <OptionViewModel> GetAllOption(string GroupType = "")
        {
            //所有选项值
            List <Options> listOption = ConfigService.GetAllOptions(GroupType);
            //所有分组
            List <OptionGroup>         listOptionGroup = new List <OptionGroup>();
            IEnumerable <ConfigOption> listConfigs     = AllConfig;

            if (!string.IsNullOrEmpty(GroupType))
            {
                listConfigs = AllConfig.Where(e => e.GroupType.Equals(GroupType, StringComparison.OrdinalIgnoreCase));
            }

            ConfigDescription desc = null;

            //分组信息
            OptionGroup     optionGroup = null;
            Options         op          = null;
            ConfigAttribute ca          = null;

            List <OptionViewModel> result = new List <OptionViewModel>();
            OptionViewModel        itemOptionViewModel = null;

            //代码现有配置项
            foreach (ConfigOption item in listConfigs)
            {
                //反射读取配置项ConfigTypeAttribute  ConfigAttribute 信息
                desc = ConfigDescriptionCache.GetTypeDiscription(item.GetType());

                itemOptionViewModel = new OptionViewModel();

                optionGroup = new OptionGroup {
                    GroupType = desc.Group, GroupName = desc.GroupCn, ImmediateUpdate = desc.ImmediateUpdate, CustomPage = desc.CustomPage
                };
                listOptionGroup.Add(optionGroup);

                itemOptionViewModel.Group       = optionGroup;
                itemOptionViewModel.ListOptions = new List <Options>();

                //每项值信息
                List <Options> itemOptions = listOption.Where(e => e.OptionType.Equals(desc.Group, StringComparison.OrdinalIgnoreCase)).ToList();

                foreach (PropertyInfo prop in desc.StaticPropertyInfo)
                {
                    op = itemOptions.FirstOrDefault(e1 => e1.Key.Equals(prop.Name, StringComparison.OrdinalIgnoreCase));
                    ca = desc.MemberDict[prop.Name];

                    if (op == null)
                    {
                        op = new Options {
                            OptionType = desc.Group, OptionName = ca.Name, Key = prop.Name, Value = Convert.ToString(ca.DefaultValue), ValueType = Convert.ToInt32(ca.ValueType).ToString()
                        };
                    }
                    //必填设置
                    op.Required = ca.Required;
                    //校验规则
                    op.ValidateRule = ca.ValidateRule;
                    //悬浮title
                    op.Title = ca.Title;
                    itemOptionViewModel.ListOptions.Add(op);
                }
                result.Add(itemOptionViewModel);
            }
            return(result.OrderBy(e => e.Group.GroupType).ToList());
        }