public IEnumerable <MvcControllerInfo> GetControllers() { if (_mvcControllers != null) { return(_mvcControllers); } _mvcControllers = new List <MvcControllerInfo>(); var items = _actionDescriptorCollectionProvider .ActionDescriptors.Items .Where(descriptor => descriptor.GetType() == typeof(ControllerActionDescriptor)) .Select(descriptor => (ControllerActionDescriptor)descriptor) .GroupBy(descriptor => descriptor.ControllerTypeInfo.FullName) .ToList(); foreach (var actionDescriptors in items) { if (!actionDescriptors.Any()) { continue; } var actionDescriptor = actionDescriptors.First(); var controllerTypeInfo = actionDescriptor.ControllerTypeInfo; var currentController = new MvcControllerInfo { AreaName = controllerTypeInfo.GetCustomAttribute <AreaAttribute>()?.RouteValue, DisplayName = controllerTypeInfo.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName, Name = actionDescriptor.ControllerName, }; var actions = new List <MvcActionInfo>(); foreach (var descriptor in actionDescriptors.GroupBy(a => a.ActionName).Select(g => g.First())) { var methodInfo = descriptor.MethodInfo; if (IsProtectedAction(controllerTypeInfo, methodInfo)) { var actionInfo = new MvcActionInfo() { ControllerId = currentController.Id, Name = descriptor.ActionName, DisplayName = methodInfo.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName, ActionHide = methodInfo.GetCustomAttribute <ActionTypeAttribute>()?.ActionHide ?? false, }; if (!actionInfo.ActionHide) { actions.Add(actionInfo); } } } if (actions.Any()) { currentController.Actions = actions; _mvcControllers.Add(currentController); } } return(_mvcControllers); }
/// <summary> /// Builds the action signature /// </summary> /// <param name="action">The action to build the signature for</param> /// <returns>The string signature</returns> private string BuildActionSignature(MvcActionInfo action) { List <string> actionParams = new List <string>(); // Build parameters foreach (MvcActionParameter oneParam in action.Parameters) { string paramText = $"{oneParam.Name}: {oneParam.Type.FormatType(TypeFormatter)}"; actionParams.Add(paramText); } // Add success and fail functions actionParams.Add($"{SuccessFuncName}?: (result: {action.ReturnType.FormatType(TypeFormatter)}) => void"); actionParams.Add($"{FailFuncName}?: (result: any) => void"); return($"{action.Name}({string.Join(", ", actionParams)}): void"); }
public IEnumerable <MvcControllerInfo> GetFunctions() { if (_mvcControllers != null) { return(_mvcControllers); } _mvcControllers = new List <MvcControllerInfo> (); var items = _actionDescriptorCollectionProvider .ActionDescriptors.Items .Where(descriptor => descriptor.GetType() == typeof(ControllerActionDescriptor)) .Select(descriptor => (ControllerActionDescriptor)descriptor) .GroupBy(descriptor => descriptor.ControllerTypeInfo.FullName) .ToList(); foreach (var actionDescriptors in items) { if (!actionDescriptors.Any()) { continue; } var actionDescriptor = actionDescriptors.First(); var controllerTypeInfo = actionDescriptor.ControllerTypeInfo; var currentController = new MvcControllerInfo { areaName = controllerTypeInfo.GetCustomAttribute <AreaAttribute> ()?.RouteValue, displayName = controllerTypeInfo.GetCustomAttribute <DisplayNameAttribute> ()?.DisplayName, name = actionDescriptor.ControllerName, }; var actions = new List <MvcActionInfo> (); foreach (var descriptor in actionDescriptors.GroupBy(a => a.ActionName).Select(g => g.First())) { var methodInfo = descriptor.MethodInfo; // var r = methodInfo.GetCustomAttribute<HttpPostAttribute> (); MvcActionInfo actionInfo = new MvcActionInfo() { controllerId = currentController.id, name = descriptor.ActionName, displayName = methodInfo.GetCustomAttribute <DisplayNameAttribute> ()?.DisplayName, }; /* if (methodInfo.GetCustomAttribute<HttpPostAttribute> () != null) { * actionInfo.type = "Create"; * } else if (methodInfo.GetCustomAttribute<HttpGetAttribute> () != null) { * actionInfo.type = "Read"; * } else if (methodInfo.GetCustomAttribute<HttpPutAttribute> () != null) { * actionInfo.type = "Update"; * } else if (methodInfo.GetCustomAttribute<HttpDeleteAttribute> () != null) { * actionInfo.type = "Delete"; * } */ actions.Add(actionInfo); } currentController.Actions = actions; _mvcControllers.Add(currentController); } return(_mvcControllers); }
public IEnumerable <MvcModuleInfo> GetControllers() { if (_mvcModules != null) { return(_mvcModules); } _mvcControllers = new List <MvcControllerInfo>(); _mvcModules = new List <MvcModuleInfo>(); var features = _dbHelper.GetFeatures(); var items = _actionDescriptorCollectionProvider .ActionDescriptors.Items .Where(descriptor => descriptor.GetType() == typeof(ControllerActionDescriptor)) .Select(descriptor => (ControllerActionDescriptor)descriptor) .GroupBy(descriptor => descriptor.ControllerTypeInfo.FullName) .ToList(); foreach (var actionDescriptors in items) { if (!actionDescriptors.Any()) { continue; } var actionDescriptor = actionDescriptors.First(); var controllerTypeInfo = actionDescriptor.ControllerTypeInfo; var currentModule = new MvcModuleInfo { Name = controllerTypeInfo.GetCustomAttribute <CustomAttribute>()?.ModuleName, DisplayName = controllerTypeInfo.GetCustomAttribute <CustomAttribute>()?.ModuleName, }; var currentController = new MvcControllerInfo { AreaName = controllerTypeInfo.GetCustomAttribute <AreaAttribute>()?.RouteValue, DisplayName = controllerTypeInfo.GetCustomAttribute <CustomAttribute>()?.DisplayName, Name = actionDescriptor.ControllerName, Description = controllerTypeInfo.GetCustomAttribute <CustomAttribute>()?.Description, ModuleName = controllerTypeInfo.GetCustomAttribute <CustomAttribute>()?.ModuleName, }; var actions = new List <MvcActionInfo>(); foreach (var descriptor in actionDescriptors.GroupBy (a => a.ActionName).Select(g => g.First())) { var methodInfo = descriptor.MethodInfo; var action = new MvcActionInfo(); action.ControllerId = currentController.Id; action.Name = descriptor.ActionName; action.DisplayName = methodInfo.GetCustomAttribute <CustomAttribute>()?.DisplayName; action.Description = methodInfo.GetCustomAttribute <CustomAttribute>()?.Description; action.RouteLinkAction = descriptor.AttributeRouteInfo?.Template; actions.Add(action); int _count = 0; if (features.Any()) { foreach (var item in features) { if (item.Name == methodInfo.GetCustomAttribute <CustomAttribute>()?.DisplayName) { _count = 1; } } if (_count != 1) { _dbHelper.CreateFeature(methodInfo.GetCustomAttribute <CustomAttribute>()?.DisplayName, descriptor.AttributeRouteInfo?.Template); } } else { _dbHelper.CreateFeature(methodInfo.GetCustomAttribute <CustomAttribute>()?.DisplayName, descriptor.AttributeRouteInfo?.Template); } } currentController.Actions = actions; _mvcControllers.Add(currentController); var controller = new List <MvcControllerInfo>(); controller.Add(new MvcControllerInfo { AreaName = currentController.AreaName, DisplayName = currentController.DisplayName, Name = currentController.Name, Description = currentController.Description, ModuleName = currentController.ModuleName, Actions = currentController.Actions, }); int count = 0; if (_mvcModules.Count != 0) { foreach (var item in _mvcModules) { if (item.Name == currentModule.Name) { item.Controllers.AddRange(controller); count = 1; } } if (count != 1) { currentModule.Controllers = controller; _mvcModules.Add(currentModule); } } else { currentModule.Controllers = controller; _mvcModules.Add(currentModule); } } return(_mvcModules); }
public MvcActionTester(MvcActionInfo method, TypeFormatter typeFormatter) { _method = method; _typeFormatter = typeFormatter; }
/// <summary> /// Gets the URL for an action /// </summary> /// <param name="action">The action</param> /// <returns>The URL</returns> private string GetUrl(MvcActionInfo action) { return($"{BaseActionUrl}{action.Name}"); }