public void Initialize(IPfConfiguration configuration) { SystemIndex = configuration.Get <int>("AppWebContext.SystemIndex"); Domain = configuration.Get <string>("AppWebContext.Domain"); EnabledSuperAdmin = configuration.Get <bool>("AppWebContext.EnabledSuperAdmin"); var xmlCommentTool = new XmlCommentTool(Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml")); Comments = xmlCommentTool.GetPropertySummaries(); }
public IActionResult SetApi() { var apiDescGroups = _apiExplorer.ApiDescriptionGroups.Items; var apis = new List <Api>(); var xmlCommentTool = new XmlCommentTool(Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml")); foreach (var group in apiDescGroups) { foreach (var apiDesc in group.Items) { var controllerActionDescriptor = apiDesc.ActionDescriptor as ControllerActionDescriptor; if (controllerActionDescriptor != null) { var controllerName = controllerActionDescriptor.ControllerTypeInfo.FullName; var methodInfoList = controllerActionDescriptor.MethodInfo.ToString().Split(" ").ToList(); methodInfoList[0] = controllerName + "."; var actionName = string.Join(' ', methodInfoList).Replace(" ", string.Empty); var controllerInfo = xmlCommentTool.GetControllerSummary(controllerName)?.Split("-") ?? new string[] { "", "" }; var actionInfo = xmlCommentTool.GetActionSummary(actionName); var api = new Api { Uid = $"{AppWebContext.Instance.SystemIndex}:{actionName.GetHashCode()}", Name = actionInfo, Area = controllerInfo[0], Controller = controllerInfo[controllerInfo.Length - 1], Method = apiDesc.HttpMethod, Url = apiDesc.ActionDescriptor.AttributeRouteInfo.Template }; apis.Add(api); } } } if (apis.Distinct(new ApiComparer()).Count() < apis.Count()) { throw new Exception("有接口的hash值重复"); } _apiService.UpdateApis(apis); return(Created("", new { })); }