コード例 #1
0
        /// <summary>
        /// 拦截
        /// </summary>
        /// <param name="basicReturn">基本返回</param>
        /// <param name="invocation">拦截参数</param>
        /// <param name="attr">特性</param>
        /// <param name="isExecProceeded">是否已执行</param>
        protected override void Intercept(BasicReturnInfo basicReturn, IInvocation invocation, ValiAttribute attr, out bool isExecProceeded)
        {
            isExecProceeded = false;
            if (attr.Handlers.IsNullOrLength0())
            {
                return;
            }

            for (int i = 0; i < attr.Handlers.Length; i++)
            {
                Type         type = attr.Handlers[i];
                IValiHandler vali = type.CreateInstance <IValiHandler>() as IValiHandler;
                if (vali == null)
                {
                    basicReturn.SetFailureMsg($"{type.FullName}未实现IValiable接口");
                    return;
                }

                BasicReturnInfo reInfo = vali.Exec(invocation.Arguments, attr.Indexs[i]);
                if (basicReturn.Failure())
                {
                    basicReturn.FromBasic(reInfo);
                    return;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 拦截
        /// </summary>
        /// <param name="basicReturn">基本返回</param>
        /// <param name="invocation">拦截参数</param>
        /// <param name="attr">特性</param>
        /// <param name="isExecProceeded">是否已执行</param>
        protected override void Intercept(BasicReturnInfo basicReturn, IInvocation invocation, FunctionAttribute attr, out bool isExecProceeded)
        {
            isExecProceeded = false;
            var ignorePerAttr = invocation.Method.GetAttribute <IgnorePermissionAttribute>();

            if (ignorePerAttr != null)
            {
                return;
            }
            if (attr.Codes.IsNullOrCount0())
            {
                basicReturn.SetFailureMsg("功能编码不能为空");
                return;
            }
            MenuAttribute menuAttr = invocation.TargetType.GetAttribute <MenuAttribute>();

            if (menuAttr == null)
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(menuAttr.Code))
            {
                basicReturn.SetFailureMsg("菜单编码不能为空");
                return;
            }

            // 这里执行权限验证
            IUserService userService = AutofacTool.Resolve <IUserService>();

            if (userService == null)
            {
                basicReturn.SetFailureMsg("找不到用户服务");
                return;
            }
            ReturnInfo <bool> perReInfo = userService.IsCurrUserPermission(menuAttr.Code, attr.Codes);

            if (perReInfo.Failure())
            {
                basicReturn.FromBasic(perReInfo);
                return;
            }
            if (perReInfo.Data)
            {
                return;
            }
            else
            {
                basicReturn.SetCodeMsg(ErrCodeDefine.NOT_PERMISSION, "Sorry,您没有访问此功能权限");
            }
        }
コード例 #3
0
        /// <summary>
        /// 判断是否拥有权限
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="controller">控制器信息</param>
        /// <param name="action">动作信息</param>
        /// <param name="basicReturn">基本返回</param>
        /// <returns>获取是否拥有权限</returns>
        protected override bool IsHavePermission(HttpContext context, RoutePermissionInfo controller, ActionInfo action, BasicReturnInfo basicReturn)
        {
            if (string.IsNullOrWhiteSpace(controller.Code) || action.Codes.IsNullOrLength0())
            {
                return(true);
            }
            ReturnInfo <bool> perReInfo = userService.IsCurrUserPermission(controller.Code, action.Codes, comData: context.CreateCommonUseData(comDataFactory, key: action.ResourceKey, menuCode: controller.Code, functionCodes: action.Codes));

            if (perReInfo.Failure())
            {
                basicReturn.FromBasic(perReInfo);
                return(false);
            }

            return(perReInfo.Data);
        }
コード例 #4
0
        /// <summary>
        /// 设置错误消息
        /// </summary>
        /// <param name="invocation">拦截参数</param>
        /// <param name="returnInfo">返回信息</param>
        private void SetErrMsg(IInvocation invocation, BasicReturnInfo returnInfo)
        {
            if (invocation.Method.ReturnType.IsReturnType())
            {
                BasicReturnInfo basicReturn = invocation.Method.ReturnType.CreateInstance <BasicReturnInfo>();
                basicReturn.FromBasic(returnInfo);

                invocation.ReturnValue = basicReturn;

                return;
            }
            else
            {
                throw new Exception(returnInfo.Msg);
            }
        }
コード例 #5
0
        /// <summary>
        /// 读取其他配置
        /// </summary>
        /// <param name="workflowDefine">工作流定义</param>
        /// <param name="connectionId">连接ID</param>
        /// <param name="comData">通用数据</param>
        private BasicReturnInfo ReaderOtherConfig(WorkflowDefineInfo workflowDefine, string connectionId, CommonUseData comData = null)
        {
            BasicReturnInfo basicReturn = new BasicReturnInfo();

            if (workflowDefine == null)
            {
                basicReturn.SetFailureMsg("找不到工作流定义信息");
                return(basicReturn);
            }

            #region 查找流程/表单/流程关卡

            ReturnInfo <FlowInfo> reFlow = FlowService.Find(workflowDefine.FlowId, connectionId: connectionId, comData: comData);
            if (reFlow.Failure())
            {
                basicReturn.FromBasic(reFlow);
                return(basicReturn);
            }
            if (reFlow.Data == null)
            {
                basicReturn.SetFailureMsg("找不到工作流的流程信息");
                return(basicReturn);
            }

            ReturnInfo <FormInfo> reForm = FormService.Find(workflowDefine.FormId, connectionId: connectionId, comData: comData);

            workflowDefine.Flow = reFlow.Data;

            if (reForm.Failure())
            {
                basicReturn.FromBasic(reForm);
                return(basicReturn);
            }
            if (reForm.Data == null)
            {
                basicReturn.SetFailureMsg("找不到工作流的表单信息");
                return(basicReturn);
            }
            workflowDefine.Form = reForm.Data;

            ReturnInfo <IList <FlowCensorshipInfo> > reFlowCensorships = FlowCensorshipService.QueryByFlowId(workflowDefine.FlowId, connectionId: connectionId, comData: comData);
            if (reFlowCensorships.Failure())
            {
                basicReturn.FromBasic(reFlowCensorships);
                return(basicReturn);
            }
            if (reFlowCensorships.Data.IsNullOrCount0())
            {
                basicReturn.SetFailureMsg("找不到工作流的流程关卡信息");
                return(basicReturn);
            }
            workflowDefine.Flow.FlowCensorships = reFlowCensorships.Data.ToArray();

            // 构造流程关卡ID数组
            int[]       flowCensorshipIds   = new int[workflowDefine.Flow.FlowCensorships.Length];
            IList <int> stFlowCensorshipIds = new List <int>();
            for (var i = 0; i < flowCensorshipIds.Length; i++)
            {
                var f = workflowDefine.Flow.FlowCensorships[i];
                flowCensorshipIds[i] = f.Id;

                if (f.OwnerCensorshipType == CensorshipTypeEnum.STANDARD)
                {
                    stFlowCensorshipIds.Add(f.OwnerCensorshipId);
                }
            }
            #endregion

            #region 查找送件/退件路线/标准关卡

            IList <StandardCensorshipInfo> standardCensorships = null;
            // 标准关卡
            if (!stFlowCensorshipIds.IsNullOrCount0())
            {
                ReturnInfo <IList <StandardCensorshipInfo> > reStand = StandardCensorshipService.Find(stFlowCensorshipIds.ToArray(), connectionId: connectionId, comData: comData);
                if (reStand.Failure())
                {
                    basicReturn.FromBasic(reStand);
                    return(basicReturn);
                }
                if (reStand.Data.IsNullOrCount0())
                {
                    basicReturn.SetFailureMsg("找不到标准关卡信息");
                    return(basicReturn);
                }

                standardCensorships = reStand.Data;
            }

            ReturnInfo <IList <SendFlowRouteInfo> > reSend = SendFlowRouteService.QueryByFlowCensorshipIds(flowCensorshipIds, connectionId: connectionId, comData: comData);
            if (reSend.Failure())
            {
                basicReturn.FromBasic(reSend);
                return(basicReturn);
            }
            if (reSend.Data.IsNullOrCount0())
            {
                basicReturn.SetFailureMsg("找不到工作流的送件路线信息");
            }

            ReturnInfo <IList <ReturnFlowRouteInfo> > reReturn = ReturnFlowRouteService.QueryByFlowCensorshipIds(flowCensorshipIds, connectionId: connectionId, comData: comData);
            if (reReturn.Failure())
            {
                basicReturn.FromBasic(reReturn);
                return(basicReturn);
            }

            foreach (var f in workflowDefine.Flow.FlowCensorships)
            {
                switch (f.OwnerCensorshipType)
                {
                case CensorshipTypeEnum.STANDARD:
                    IList <StandardCensorshipInfo> stdList = new List <StandardCensorshipInfo>();
                    foreach (var s in standardCensorships)
                    {
                        if (f.OwnerCensorshipId == s.Id)
                        {
                            stdList.Add(s);
                        }
                    }

                    if (stdList.Count == 0)
                    {
                        basicReturn.SetFailureMsg($"找不到归属ID为{f.OwnerCensorshipId}的标准关卡信息");
                        return(basicReturn);
                    }

                    f.StandardCensorships = stdList.ToArray();

                    break;
                }

                IList <SendFlowRouteInfo> sendRotes = new List <SendFlowRouteInfo>();
                foreach (var send in reSend.Data)
                {
                    if (f.Id == send.FlowCensorshipId)
                    {
                        sendRotes.Add(send);
                    }
                }

                if (!sendRotes.IsNullOrCount0())
                {
                    f.SendFlowRoutes = sendRotes.ToArray();
                }

                if (!reReturn.Data.IsNullOrCount0())
                {
                    IList <ReturnFlowRouteInfo> returnRotes = new List <ReturnFlowRouteInfo>();
                    foreach (var re in reReturn.Data)
                    {
                        if (f.Id == re.FlowCensorshipId)
                        {
                            returnRotes.Add(re);
                        }
                    }

                    if (!returnRotes.IsNullOrCount0())
                    {
                        f.ReturnFlowRoutes = returnRotes.ToArray();
                    }
                }
            }

            #endregion

            return(basicReturn);
        }