public int ClearNonExistRecords()
        {
            int ret = 0;

            List <Controller> controllers = this.AuthService.GetControllers().ToList();

            if (controllers.Count > 0)
            {
                ControllerActionsList reflecteds = AuthorizationValidator.ControllerActionsList;// ControllerActionsList.Create<ReflectController>(AppDomain.CurrentDomain.GetAssemblies());

                foreach (Controller controller in controllers)
                {
                    ControllerActions ca = reflecteds.FirstOrDefault((item) => String.Equals(controller.Name, item.ControllerType.Name.Replace("Controller", "")));
                    if (null != ca)
                    {
                        List <Models.Action> actions = this.AuthService.GetActionsBy(controller.ControllerId).ToList();
                        foreach (Models.Action action in actions)
                        {
                            MethodInfo mi = ca[action.Name];
                            if (null == mi)//Mesela method silindi veya ismi değiştirildi.
                            {
                                ret = this.AuthService.DeleteRecordsByControllerAction(action);
                            }
                        }
                    }
                    else
                    {
                        ret += this.AuthService.DeleteRecordsByController(controller);
                    }
                }
            }

            return(ret);
        }
        private static IEnumerable <TreeNode> GetApiActionsHierarchical_Internal(string role)
        {
            if (String.IsNullOrEmpty(role))
            {
                throw new ArgumentNullException(nameof(role));
            }

            var roleView = SqlRoleStorageProvider.Instance.GetAll();
            var indexed  = IndexedRoles.Create(roleView);

            var                   asms          = AppDomain.CurrentDomain.GetAssemblies();
            List <TreeNode>       ret           = new List <TreeNode>();
            ControllerActionsList reflectedList = ControllerActionsList.Create <ReflectController>(asms);

            foreach (ControllerActions reflectedCA in reflectedList)
            {
                string   controllerName = reflectedCA.ControllerType.Name.Replace("Controller", "");
                TreeNode parent         = new TreeNode();
                parent.data     = reflectedCA.ControllerType.FullName;
                parent.label    = controllerName;
                parent.children = new List <TreeNode>();

                bool hasParentCheck = false;
                foreach (MethodInfo mi in reflectedCA)
                {
                    TreeNode child = new TreeNode()
                    {
                        label = mi.Name
                    };
                    var entity = indexed.Find(role, controllerName, mi.Name);
                    child.@checked = entity != null && entity.Enabled;
                    hasParentCheck = hasParentCheck || child.@checked;

                    parent.children.Add(child);
                }
                parent.@checked = hasParentCheck;
                ret.Add(parent);
            }
            return(ret);
        }
Example #3
0
        public int ClearNonExistRecords()
        {
            int ret = 0;

            using (DbClient client = ionixFactory.CreateDbClient())
            {
                ControllerRepository controllerRepository = new ControllerRepository(client.Cmd);
                List <Controller>    controllers          = controllerRepository.Select().ToList();

                if (controllers.Count > 0)
                {
                    ActionRepository actionRepository = new ActionRepository(client.Cmd);

                    ControllerActionsList reflecteds = AuthorizationValidator.ControllerActionsList;// ControllerActionsList.Create<ReflectController>(AppDomain.CurrentDomain.GetAssemblies());

                    foreach (Controller controller in controllers)
                    {
                        ControllerActions ca = reflecteds.FirstOrDefault((item) => String.Equals(controller.Name, item.ControllerType.Name.Replace("Controller", "")));
                        if (null != ca)
                        {
                            List <Server.Models.Action> actions = actionRepository.SelectByControllerId(controller.Id).ToList();
                            foreach (Server.Models.Action action in actions)
                            {
                                MethodInfo mi = ca[action.Name];
                                if (null == mi)//Mesela method silindi veya ismi değiştirildi.
                                {
                                    ret = DeleteRecordsByControllerAction(action);
                                }
                            }
                        }
                        else
                        {
                            ret += DeleteRecordsByController(controller);
                        }
                    }
                }
            }

            return(ret);
        }