コード例 #1
0
 private void GenerateGetNavigationAction(int permissionid, Dictionary <string, int> permissionNavis)
 {
     foreach (var item in Entity.NavigationPropertys.Values)
     {
         ControllerMethodMetadata method;
         var controller = Entity.Definition.Controller;
         if (item.PropertyType.IsCollection)
         {
             method = new ControllerMethodMetadata(EControllerMethodType.GetNavigateQueryable).PermissionAction(permissionid);
             if (controller.DisablePage)
             {
                 method.Write("System.Web.OData.EnableQuery");
             }
             else
             {
                 method.Write("System.Web.OData.EnableQuery", $"PageSize={controller.PageSize}");
             }
         }
         else
         {
             method = new ControllerMethodMetadata(EControllerMethodType.GetNavigateSingleResult).PermissionAction(permissionid);
             method.Write("System.Web.OData.EnableQuery");
         }
         method.Navigation = item;
         if (permissionNavis.ContainsKey(item.Name))
         {
             method.PermissionAction(permissionNavis[item.Name]);
         }
         Methods.Add(method);
     }
 }
コード例 #2
0
        private void GeneratePutAction(ControllerConfigure controller)
        {
            int permissionid = PermissionAction("UPDATE", "修改权限", "修改数据[" + Entity.ProjectItem.Title + "]的权限");

            var put = new ControllerMethodMetadata(EControllerMethodType.Put);

            if (controller.AuthPut)
            {
                put.PermissionAction(permissionid);
            }
            Methods.Add(put);

            var patch = new ControllerMethodMetadata(EControllerMethodType.Patch);

            if (controller.AuthPut)
            {
                patch.PermissionAction(permissionid);
            }
            Methods.Add(patch);


            var update = new ControllerMethodMetadata(EControllerMethodType.OnUpdateEntity);
            int count  = InheritEntitys.SelectMany(a => a.Definition.Members).OfType <ColumnMember>().Where(a => a.GenerateMode == EColumnGenerateMode.CodeCreate).Count();

            count += InheritEntitys.SelectMany(a => a.Definition.Members).OfType <ColumnMember>().Where(a => a.GenerateMode == EColumnGenerateMode.CodeUpdate || a.GenerateMode == EColumnGenerateMode.CodeCreateUpdate).Count();

            if (InheritEntitys.Select(a => a.Definition.Controller).Where(a => !string.IsNullOrEmpty(a.PutInterceptor)).Count() > 0 || count > 0)
            {
                Methods.Add(update);
            }

            if (Permission != null && controller.AuthPut)
            {
                foreach (var a in Entity.ColumnPropertys.Values.Where(a => a.Member.EnableAuth && a.Member.GenerateMode == EColumnGenerateMode.None))
                {
                    UpdateEntityCommonPropertyPerssions.Add(Permission.Write(Entity.ProjectItem.Id, ServiceCompile.PermissionModify, a.Name, a.Member.Title + "修改", $"修改属性[{Entity.ProjectItem.Title}]的权限"), a.Name);
                }
                foreach (var a in Entity.NavigationPropertys.Values.Where(a => a.Member.EnableAuth))
                {
                    UpdateEntityNavigatePropertyPermissions.Add(a.Name, Permission.Write(Entity.ProjectItem.Id, ServiceCompile.PermissionModify, a.Name, a.Member.Title + "修改", $"修改属性[{Entity.ProjectItem.Title}]的权限"));
                }
            }

            if (InheritEntitys.SelectMany(a => a.NavigationPropertys).Count() > 0)
            {
                Methods.Add(new ControllerMethodMetadata(EControllerMethodType.CreateRef));
                Methods.Add(new ControllerMethodMetadata(EControllerMethodType.CreateRefOverride));
                Methods.Add(new ControllerMethodMetadata(EControllerMethodType.DeleteRef1));
                Methods.Add(new ControllerMethodMetadata(EControllerMethodType.DeleteRef2));
                Methods.Add(new ControllerMethodMetadata(EControllerMethodType.DeleteRefOverride));
            }
        }
コード例 #3
0
        private void GenerateGetAction(ControllerConfigure controller)
        {
            int permissionid = PermissionAction("RETRIEVE", "查询权限", "查询数据[" + Entity.ProjectItem.Title + "]的权限");

            var getcol = new ControllerMethodMetadata(EControllerMethodType.GetQueryable);

            if (controller.AuthGet)
            {
                getcol.PermissionAction(permissionid);
            }

            var getobj = new ControllerMethodMetadata(EControllerMethodType.GetSingleResult);

            if (controller.AuthGet)
            {
                getobj.PermissionAction(permissionid);
            }

            string idstr = string.Empty, namestr = string.Empty;
            Dictionary <string, int> permissionNavis = PermissionPropertys(controller, ref idstr, ref namestr);

            if (!string.IsNullOrEmpty(idstr) && controller.AuthGet)
            {
                if (controller.DisablePage)
                {
                    getcol.Write("Wilmar.Service.Common.Attributes.ODataQuery", idstr, namestr, $"MaxNodeCount={int.MaxValue}", "MaxExpansionDepth = 4");
                }
                else
                {
                    getcol.Write("Wilmar.Service.Common.Attributes.ODataQuery", idstr, namestr, $"MaxNodeCount={int.MaxValue}", "MaxExpansionDepth = 4", $"PageSize={controller.PageSize}");
                }
                getobj.Write("Wilmar.Service.Common.Attributes.ODataQuery", idstr, namestr);
            }
            else
            {
                if (controller.DisablePage)
                {
                    getcol.Write("Wilmar.Service.Common.Attributes.CustomEnableQuery", $"MaxNodeCount={int.MaxValue}", "MaxExpansionDepth = 4");
                }
                else
                {
                    getcol.Write("Wilmar.Service.Common.Attributes.CustomEnableQuery", $"MaxNodeCount={int.MaxValue}", "MaxExpansionDepth = 4", $"PageSize={controller.PageSize}");
                }
                getobj.Write("Wilmar.Service.Common.Attributes.CustomEnableQuery");
            }
            Methods.Add(getcol);
            Methods.Add(getobj);

            GenerateGetNavigationAction(permissionid, permissionNavis);
        }
コード例 #4
0
        private void GenerateDeleteAction(ControllerConfigure controller)
        {
            int permissionid = PermissionAction("DELETE", "删除权限", "删除数据[" + Entity.ProjectItem.Title + "]的权限");

            var delete = new ControllerMethodMetadata(EControllerMethodType.Delete);

            if (controller.AuthDelete)
            {
                delete.PermissionAction(permissionid);
            }
            Methods.Add(delete);

            if (InheritEntitys.Select(a => a.Definition.Controller).Where(a => !string.IsNullOrEmpty(a.DeleteInterceptor)).Count() > 0)
            {
                Methods.Add(new ControllerMethodMetadata(EControllerMethodType.OnDeleteEntity));
            }
        }
コード例 #5
0
        private void GenerateCustomAction(ControllerConfigure controller)
        {
            foreach (var action in controller.Actions)
            {
                var actionData = new ControllerMethodMetadata(EControllerMethodType.CustomAction)
                {
                    Action = new ControllerActionMetadata(action, Project, Entity)
                };
                int permissionid = PermissionAction(action.Name, action.Title + "执行", $"调用操作[{Entity.ProjectItem.Title}]->[{action.Title}]的权限");
                if (action.EnableAuth)
                {
                    actionData.PermissionAction(permissionid);
                }
                Methods.Add(actionData);

                Project.Service.Actions.Add(actionData.Action);
            }
        }
コード例 #6
0
        private void GeneratePostAction(ControllerConfigure controller)
        {
            int permissionid = PermissionAction("CREATE", "创建权限", "创建数据[" + Entity.ProjectItem.Title + "]的权限");
            var post         = new ControllerMethodMetadata(EControllerMethodType.Post);

            if (controller.AuthPost)
            {
                post.PermissionAction(permissionid);
            }
            Methods.Add(post);

            var create = new ControllerMethodMetadata(EControllerMethodType.OnCreateEntity);

            int count = InheritEntitys.SelectMany(a => a.Definition.Members).OfType <PrimaryMember>().Where(a => a.GenerateMode == EPrimaryGenerateMode.Code).Count();

            count += InheritEntitys.SelectMany(a => a.Definition.Members).OfType <ColumnMember>().Where(a => a.GenerateMode == EColumnGenerateMode.CodeCreate || a.GenerateMode == EColumnGenerateMode.CodeCreateUpdate).Count();

            if (InheritEntitys.Select(a => a.Definition.Controller).Where(a => !string.IsNullOrEmpty(a.PostInterceptor)).Count() > 0 || count > 0)
            {
                Methods.Add(create);
            }
        }