Пример #1
0
        public async Task <bool> CheckControllerNameActionNameAsync(string sAreaName, string sControllerName, string sActionName, int iActionId)
        {
            SystemAction entitySystemAction = await _systemActionRepository.SelectAsync(iActionId);

            if (entitySystemAction != null)
            {
                SystemController entitySystemController = await _systemControllerService.SelectAsync(entitySystemAction.IcontrollerId);

                if (entitySystemController != null)
                {
                    if (sAreaName == "Admin" && sControllerName == entitySystemController.ScontrollerName && sActionName == entitySystemAction.SactionName.Replace("Async", string.Empty))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
        //[ValidateAntiForgeryToken]
        public async Task <string> ReflectionController()
        {
            BaseResult baseResult = new BaseResult();

            try
            {
                List <SystemController> lstSystemController = new List <SystemController>();
                List <SystemAction>     lstSystemAction     = new List <SystemAction>();
                Assembly[]        arrAssembly             = AppDomain.CurrentDomain.GetAssemblies();
                List <MethodInfo> lstMethodInfoController = new List <MethodInfo>();
                for (int i = 0; i < arrAssembly.Length; i++)
                {
                    if (arrAssembly[i].GetName().Name.Equals("Microsoft.AspNetCore.Mvc.ViewFeatures"))
                    {
                        foreach (Type item in arrAssembly[i].GetModule("Microsoft.AspNetCore.Mvc.ViewFeatures.dll").GetTypes())
                        {
                            if (item.Name.Equals("Controller"))
                            {
                                lstMethodInfoController.AddRange(item.GetMethods());
                                break;
                            }
                        }
                    }
                }
                for (int i = 0; i < arrAssembly.Length; i++)
                {
                    if (arrAssembly[i].GetName().Name.Equals("Message.UI"))
                    {
                        foreach (Type item in arrAssembly[i].GetModule("Message.UI.dll").GetTypes())
                        {
                            if (!string.IsNullOrWhiteSpace(item.Namespace))
                            {
                                if (item.Namespace.ToString().Equals("Message.UI.Areas.Admin.Controllers") && item.Name.EndsWith("Controller"))
                                {
                                    if (item.Name == "BaseAdminController")
                                    {
                                        continue;
                                    }
                                    SystemController entity = new SystemController()
                                    {
                                        ScontrollerName = item.Name.Replace("Controller", string.Empty)
                                    };
                                    if (entity.ScontrollerName == "System")
                                    {
                                        entity.ScontrollerName += "Controller";
                                    }
                                    lstSystemController.Add(entity);
                                    SystemController entitySystemController = await _SystemControllerService.SelectAsync(new SystemController()
                                    {
                                        ScontrollerName = entity.ScontrollerName
                                    });

                                    if (entitySystemController == null)
                                    {
                                        await _SystemControllerService.AppendAsync(entity, User.Identity.Name);
                                    }
                                    else
                                    {
                                        entity.Id = entitySystemController.Id;
                                    }
                                    foreach (MethodInfo entityMethodInfo in item.GetMethods(BindingFlags.Instance | BindingFlags.Public))
                                    {
                                        if (!lstMethodInfoController.Exists(x => x.Name.Equals(entityMethodInfo.Name)))
                                        {
                                            SystemAction entitySystemAction = new SystemAction()
                                            {
                                                IcontrollerId = entity.Id,
                                                SactionName   = entityMethodInfo.Name,
                                                SresultType   = entityMethodInfo.ReturnType.Name
                                            };
                                            if (_systemActionService.Select(entitySystemAction) == null)
                                            {
                                                await _systemActionService.AppendAsync(entitySystemAction, User.Identity.Name);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                baseResult.Code = 0;
                baseResult.Msg  = "操作成功!";
            }
            catch (Exception ex)
            {
                baseResult.Code = 3;
                baseResult.Msg  = ex.Message;
                throw;
            }
            return(JsonHelper.ObjectToJSON(baseResult));
        }