public ConfigDescriptionCache(ConfigDescriptionCache prev, Type type) { this.prev = prev; // Suche alle Actions actions = ( from mi in type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod) let attr = mi.GetCustomAttribute <DEConfigHttpActionAttribute>() let attrDesc = mi.GetCustomAttribute <DescriptionAttribute>() where attr != null && mi.DeclaringType == type select new ConfigAction { Description = attrDesc == null ? String.Empty : attrDesc.Description, Attribute = attr, Method = mi } ).ToArray(); // Suche alle Eigenschaften properties = ( from pi in TypeDescriptor.GetProperties(type).Cast <PropertyDescriptor>() let name = (PropertyNameAttribute)pi.Attributes[typeof(PropertyNameAttribute)] where name != null select pi ).ToArray(); } // ctor
} // func InvokeAction private DEConfigAction CompileTypeAction(string actionName) { var cac = ConfigDescriptionCache.Get(GetType()); if (cac == null) { return(DEConfigAction.Empty); } return(cac.GetConfigAction(actionName, out var ca) ? CompileTypeAction(ref ca) : DEConfigAction.Empty); } // func CompileTypeAction
/// <summary>Initialisiert die Eigenschaften, an einem Knoten.</summary> private void InitTypeProperties() { valueChangedHandler = ValueChangedHandler; var cdc = ConfigDescriptionCache.Get(GetType()); if (cdc != null) { foreach (var pi in cdc.Properties) { RegisterProperty(new ConfigItemProperty(this, pi)); } } } // proc InitTypeProperties
/// <summary> /// 保存时 对当前配置项进行赋值 /// </summary> /// <param name="item">当前配置项</param> /// <param name="ListOptions">配置项值</param> public void SetValue(ConfigOption item, List <Options> 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); } } }
} // proc AttachedScriptCompiled /// <summary>Sammelt alle für diesen Knoten vorhande Aktionen.</summary> protected virtual void CollectActions() { // Suche alle Type Actions CompileTypeActions(ConfigDescriptionCache.Get(GetType())); // Suche alle Lua Actions var table = GetActionTable(); if (table != null) { foreach (var c in table) { if (c.Key is string actionId && !actions.Contains(actionId)) { actions[actionId] = CompileLuaAction(actionId, c.Value as LuaTable); } } } } // proc CollectActions
} // func InvokeAction private DEConfigAction CompileTypeAction(string sAction) { ConfigDescriptionCache cac = ConfigDescriptionCache.Get(GetType()); if (cac == null) { return(DEConfigAction.Empty); } ConfigAction ca; if (cac.GetConfigAction(sAction, out ca)) { return(CompileTypeAction(ref ca)); } else { return(DEConfigAction.Empty); } } // func CompileTypeAction
public static ConfigDescriptionCache Get(Type type) { if (!typeof(DEConfigItem).IsAssignableFrom(type)) { return(null); } lock (configDescriptors) { ConfigDescriptionCache ret; if (configDescriptors.TryGetValue(type, out ret)) { return(ret); } else { return(configDescriptors[type] = new ConfigDescriptionCache(Get(type.BaseType), type)); } } } // func Get
} // func CompileTypeAction private void CompileTypeActions(ConfigDescriptionCache cac) { if (cac == null) { return; } // Vorgänger bearbeiten CompileTypeActions(cac.Previous); if (cac.Actions != null) { for (int i = 0; i < cac.Actions.Length; i++) { if (!actions.Contains(cac.Actions[i].Attribute.ActionName)) { actions[cac.Actions[i].Attribute.ActionName] = CompileTypeAction(ref cac.Actions[i]); } } } } // proc CompileTypeActions
} // proc AttachedScriptCompiled /// <summary>Sammelt alle für diesen Knoten vorhande Aktionen.</summary> protected virtual void CollectActions() { // Suche alle Type Actions CompileTypeActions(ConfigDescriptionCache.Get(GetType())); // Suche alle Lua Actions var table = GetActionTable(); if (table != null) { foreach (var c in table) { string sAction = c.Key as string; if (sAction == null || actions.Contains(sAction)) { continue; } actions[sAction] = CompileLuaAction(sAction, c.Value as LuaTable); } } } // proc CollectActions
/// <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); } } } }
/// <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 }; 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());; }