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); }
public string GetText(MvcControllerInfo controllerInfo, ControllerContext context, Uri outputPath) { _innerTemplate = new MvcMethodTextTemplateBase(); _innerTemplate.Initialize(controllerInfo, context, new TypeScriptTypeFormatter(context.ExtractedTypes)); _innerTemplate.PushIndent("\t"); WebMethodNamespace = context.WebMethodNamespace; return(TransformText()); }
/// <summary> /// Gets the result path for a controller /// </summary> /// <param name="controller">The controller</param> /// <returns>The result path</returns> private string GetControllerResultPath(MvcControllerInfo controller) { FileInfo fileInfo = new FileInfo(controller.FilePath); DirectoryInfo controllerDir = fileInfo.Directory; // Calculate the result string controllerName = controller.Name.Substring(0, controller.Name.Length - "Controller".Length); string resultPath = Path.Combine(controllerDir.FullName, $"..\\Scripts\\{controllerName}", controllerName + "Actions.ts"); return(Path.GetFullPath(resultPath)); }
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; actions.Add(new MvcActionInfo { ControllerId = currentController.Id, Name = descriptor.ActionName, DisplayName = methodInfo.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName, }); } currentController.Actions = actions; if (currentController.Name != "Account" && currentController.Name != "AdminManager") { _mvcControllers.Add(currentController); } } return(_mvcControllers); }
public void Initialize(MvcControllerInfo controllerInfo, ControllerContext context, TypeFormatter formatter) { ControllerInfo = controllerInfo; TypeFormatter = formatter; Context = context; if (context.HasOwnAjaxFunction) { HasOwnAjaxFunction = true; AjaxFunctionName = context.AjaxFunctionName; } else { AjaxFunctionName = "callService"; } ControllerName = ControllerInfo.Name.Substring(0, ControllerInfo.Name.Length - "Controller".Length); FileInfo fileInfo = new FileInfo(ControllerInfo.FilePath); DirectoryInfo controllerDir = fileInfo.Directory; // Check if this controller is in an "Area" bool foundAreas = false; DirectoryInfo dir = controllerDir; DirectoryInfo areaDir = null; // if areas is found, this is the specific area directory (like "Admin", or "Shared", etc) while (dir != null) { if (dir.Name == "Areas") { foundAreas = true; break; } areaDir = dir; dir = dir.Parent; } if (foundAreas) { // Area/ControllerName/Action BaseActionUrl = $"/{areaDir.Name}/{ControllerName}/"; } else { // ControllerName/Action BaseActionUrl = $"/{ControllerName}/"; } }
public MvcActionsDiscoveryService(IActionDescriptorCollectionProvider actionDescriptorCollectionProvider) { MvcActions = 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; actions.Add(new MvcActionInfo { ControllerId = currentController.Id, Name = descriptor.ActionName, DisplayName = methodInfo.GetCustomAttribute <DisplayNameAttribute>()?.DisplayName, }); } currentController.Actions = actions; MvcActions.Add(currentController); } }
public string GetText(MvcControllerInfo controllerInfo, ControllerContext context, Uri outputPath) { _innerTemplate = new MvcMethodTextTemplateBase(); _innerTemplate.Initialize(controllerInfo, context, new PrefixedTypeFormatter(context.ExtractedTypes, s_importName, s_importName)); _context = context; // Get relative import paths Uri serverObjectsRelativePath = outputPath.MakeRelativeUri(context.ServerObjectsResultFilepath); if (context.HasOwnAjaxFunction) { Uri ajaxPath = outputPath.MakeRelativeUri(context.AjaxFunctionModulePath); _ajaxImportPath = ajaxPath.ToString(); _ajaxImportPath = _ajaxImportPath.Substring(0, _ajaxImportPath.Length - 3); } _importPath = serverObjectsRelativePath.ToString(); _importPath = _importPath.Substring(0, _importPath.Length - 3); // remove .ts return(TransformText()); }
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 ControllerTester(MvcControllerInfo controller, TypeFormatter typeFormatter) { _controllerInfo = controller; _typeFormatter = typeFormatter; }