/// <summary> /// 重写以实现从方法信息中提取模块信息 /// </summary> /// <param name="method">方法信息</param> /// <param name="typeInfo">所在类型模块信息</param> /// <param name="index">序号</param> /// <returns>提取到的模块信息</returns> protected override ModuleInfo GetModule(MethodInfo method, ModuleInfo typeInfo, int index) { ModuleInfoAttribute infoAttr = method.GetAttribute <ModuleInfoAttribute>(); ModuleInfo info = new ModuleInfo() { Name = infoAttr.Name ?? method.GetDescription() ?? method.Name, Code = infoAttr.Code ?? method.Name, Order = infoAttr.Order > 0 ? infoAttr.Order : index + 1 }; string controller = method.DeclaringType?.Name.Replace("Controller", ""); info.Position = $"{typeInfo.Position}.{controller}"; //依赖的功能 string area = method.DeclaringType.GetAttribute <AreaAttribute>(true)?.RouteValue; List <IFunction> dependOnFunctions = new List <IFunction>() { FunctionHandler.GetFunction(area, controller, method.Name) }; DependOnFunctionAttribute[] dependOnAttrs = method.GetAttributes <DependOnFunctionAttribute>(); foreach (DependOnFunctionAttribute dependOnAttr in dependOnAttrs) { string darea = dependOnAttr.Area == null ? area : dependOnAttr.Area == string.Empty ? null : dependOnAttr.Area; string dcontroller = dependOnAttr.Controller ?? controller; IFunction function = FunctionHandler.GetFunction(darea, dcontroller, dependOnAttr.Action); if (function == null) { throw new OsharpException($"功能“{area}/{controller}/{method.Name}”的依赖功能“{darea}/{dcontroller}/{dependOnAttr.Action}”无法找到"); } dependOnFunctions.Add(function); } info.DependOnFunctions = dependOnFunctions.ToArray(); return(info); }
private string getModuleTypesJSON() { SortedDictionary <string, ArrayList> grups = new SortedDictionary <string, ArrayList>(); foreach (Type type in Provider.GetModuleTypes()) { ModuleInfoAttribute mInfo = (ModuleInfoAttribute)CMSUtility.GetAttribute(type, typeof(ModuleInfoAttribute)); string grup = Provider.GetResource(mInfo.Grup); if (!mInfo.Visible) { continue; //*** } if (!grups.ContainsKey(grup)) { grups.Add(grup, new ArrayList()); } grups[grup].Add("{name:'" + Provider.GetResource(type.Name) + "',id:'" + type.Name + "'}"); } ArrayList res = new ArrayList(); foreach (string grup in grups.Keys) { //grups[grup].Sort(); res.Add("{grup:'" + grup + "', items:[" + String.Join(",", (string[])grups[grup].ToArray(typeof(string))) + "]}"); } return("[" + String.Join(",", (string[])res.ToArray(typeof(string))) + "]"); }
/// <summary> /// 重写以实现从类型中提取模块信息 /// </summary> /// <param name="type">类型信息</param> /// <param name="existPaths">已存在的路径集合</param> /// <returns>提取到的模块信息</returns> protected override ModuleInfo[] GetModules(Type type, string[] existPaths) { ModuleInfoAttribute infoAttr = type.GetAttribute <ModuleInfoAttribute>(); if (infoAttr == null) { return(new ModuleInfo[0]); } ModuleInfo info = new ModuleInfo() { Name = infoAttr.Name ?? GetName(type), Code = infoAttr.Code ?? type.Name.Replace("Controller", ""), Order = infoAttr.Order, Position = GetPosition(type, infoAttr.Position), PositionName = infoAttr.PositionName }; List <ModuleInfo> infos = new List <ModuleInfo>() { info }; //获取中间分类模块 if (infoAttr.Position != null) { info = new ModuleInfo() { Name = infoAttr.PositionName ?? infoAttr.Position, Code = infoAttr.Position, Position = GetPosition(type, null) }; if (!existPaths.Contains($"{info.Position}.{info.Code}")) { infos.Insert(0, info); } } //获取区域模块 string area = type.GetAttribute <AreaAttribute>()?.RouteValue ?? "Site"; string name = area == "Site" ? "站点" : area == "Admin" ? "管理" : null; info = new ModuleInfo() { Name = name ?? area, Code = area, Position = "Root", PositionName = area == "Site" ? "站点" : area == "Admin" ? "管理" : null }; if (!existPaths.Contains($"{info.Position}.{info.Code}")) { infos.Insert(0, info); } return(infos.ToArray()); }
/// <summary> /// 重写以实现从类型中提取模块信息 /// </summary> /// <param name="type">类型信息</param> /// <returns>提取到的模块信息</returns> protected override ModuleInfo GetModule(Type type) { ModuleInfoAttribute infoAttr = type.GetAttribute <ModuleInfoAttribute>(); ModuleInfo info = new ModuleInfo() { Name = infoAttr.Name ?? GetName(type), Code = infoAttr.Code ?? type.Name.Replace("Controller", ""), Order = infoAttr.Order, Position = GetPosition(type, infoAttr.Position) }; return(info); }
/// <summary> /// Constructor /// </summary> /// <param name="m">Module</param> public ModuleHeader(Type type) { Type = type; IModule.GetNames(type, out _ModulePath, out _Name, out _FullPath); ModuleInfoAttribute at = Type.GetCustomAttribute <ModuleInfoAttribute>(); if (at != null) { Description = at.Description; Author = at.Author; DisclosureDate = at.DisclosureDate; if (string.IsNullOrEmpty(Author)) { Author = GetAuthorFromLibrary(Type); } } }
public void cmdInfo(string args) { if (!CheckModule(false, EModuleType.None)) { return; } args = args.Trim().ToLowerInvariant(); Module curM = _Current.ModuleType == EModuleType.Module ? (Module)_Current : null; CommandTable tb = new CommandTable(); tb.AddRow(Lang.Get("Path"), _Current.ModulePath, "")[0].ForeColor = ConsoleColor.DarkGray; tb.AddRow(Lang.Get("Name"), _Current.Name, "")[0].ForeColor = ConsoleColor.DarkGray; tb.AddRow("", "", ""); ModuleInfoAttribute mInfo = _Current == null ? null : _Current.GetType().GetCustomAttribute <ModuleInfoAttribute>(); if (mInfo != null && !string.IsNullOrEmpty(mInfo.Author)) { CommandTableRow row = tb.AddRow(1, Lang.Get("Author"), mInfo.Author, ""); row[0].ForeColor = ConsoleColor.DarkGray; row[1].Align = CommandTableCol.EAlign.None; row[2].Align = CommandTableCol.EAlign.None; } if (curM != null) { if (curM.DisclosureDate != DateTime.MinValue) { tb.AddRow(Lang.Get("DisclosureDate"), curM.DisclosureDate.ToString(), "")[0].ForeColor = ConsoleColor.DarkGray; } if (curM.References != null && curM.References.Length > 0) { tb.AddRow("", "", ""); StringBuilder sb = new StringBuilder(); foreach (Reference r in curM.References) { if (r == null) { continue; } sb.AppendLine(r.Type.ToString() + " - " + r.Value); } foreach (CommandTableRow row in tb.AddSplitRow(1, Lang.Get("References"), sb.ToString(), "")) { row[0].ForeColor = ConsoleColor.DarkGray; row[1].Align = CommandTableCol.EAlign.None; row[2].Align = CommandTableCol.EAlign.None; } } } if (mInfo != null && !string.IsNullOrEmpty(mInfo.Description)) { foreach (CommandTableRow row in tb.AddSplitRow(1, Lang.Get("Description"), mInfo.Description, "")) { row[0].ForeColor = ConsoleColor.DarkGray; row[1].Align = CommandTableCol.EAlign.None; row[2].Align = CommandTableCol.EAlign.None; } } tb.OutputColored(_IO); }
/// <summary> /// 重写以实现从类型中提取模块信息 /// </summary> /// <param name="type">类型信息</param> /// <param name="existPaths">已存在的路径集合</param> /// <returns>提取到的模块信息</returns> protected override ModuleInfo[] GetModules(Type type, string[] existPaths) { ModuleInfoAttribute infoAttr = type.GetAttribute <ModuleInfoAttribute>(); if (infoAttr == null) { return(new ModuleInfo[0]); } ModuleInfo info = new ModuleInfo() { Name = infoAttr.Name ?? GetName(type), Code = infoAttr.Code ?? type.Name.Replace("Controller", ""), Order = infoAttr.Order, Position = GetPosition(type, infoAttr.Position), PositionName = infoAttr.PositionName }; List <ModuleInfo> infos = new List <ModuleInfo>() { info }; //获取中间分类模块 if (infoAttr.Position != null) { info = new ModuleInfo() { Name = infoAttr.PositionName ?? infoAttr.Position, Code = infoAttr.Position, Position = GetPosition(type, null) }; if (!existPaths.Contains($"{info.Position}.{info.Code}")) { infos.Insert(0, info); } } //获取区域模块 string area, name; AreaInfoAttribute areaInfo = type.GetAttribute <AreaInfoAttribute>(); if (areaInfo != null) { area = areaInfo.RouteValue; name = areaInfo.Display ?? area; } else { AreaAttribute areaAttr = type.GetAttribute <AreaAttribute>(); area = areaAttr?.RouteValue ?? "Site"; DisplayNameAttribute display = type.GetAttribute <DisplayNameAttribute>(); name = display?.DisplayName ?? area; } info = new ModuleInfo() { Name = name, Code = area, Position = "Root", PositionName = name }; if (!existPaths.Contains($"{info.Position}.{info.Code}")) { infos.Insert(0, info); } return(infos.ToArray()); }