Example #1
0
        public async Task <bool> Submit(LeaveRequest request)
        {
            //处理业务部分内容
            IUserInfo user = await accessToken.FromRequestHeaderAsync(httpContext);

            MockDatas.Requests.Add(request);

            //转换为流程变量,这里只是一个演示,实际仅需要传递流程需要的数据变量就可以了。
            //不需要把整个业务数据都传递给工作流
            Dictionary <string, object> variables = JToken.FromObject(request).ToObject <Dictionary <string, object> >();

            //设置流程管理员用户,变量名对应流程中设置的流程变量名.
            variables.Add("AdminUser", new string[] { MockDatas.AdminUser.Id });
            variables.Add("StartUser", user.Id);

            //这块只是演示,获取节点审批人员方法可以参考activiti,也可以看下Engine\imp\bpmn\rules下的几种角色的获取方法
            variables.Add("上级主管", new string[] { MockDatas.Users.FirstOrDefault(x => x.Duty == "上级主管").Id });
            variables.Add("部门经理", new string[] { MockDatas.Users.FirstOrDefault(x => x.Duty == "部门经理").Id });
            variables.Add("HR", new string[] { MockDatas.Users.FirstOrDefault(x => x.Duty == "HR").Id });

            _ = await processInstanceClient.Start(new StartProcessInstanceCmd[]
            {
                new StartProcessInstanceCmd
                {
                    //使用流程key+tenantid启动一个流程
                    ProcessDefinitionKey = Process_LeaveRequest,
                    TenantId             = MockDatas.TenantId,
                    BusinessKey          = request.Id,
                    Variables            = variables
                }
            });

            return(true);
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task Invoke(HttpContext context)
        {
            //IMvcControllerDiscovery mvcControllerDiscovery = context.RequestServices.GetService<IMvcControllerDiscovery>();

            //var controllers = mvcControllerDiscovery.GetControllers();

#if DEBUG
            if (context.Request.Path.HasValue &&
                new Regex("/swagger/?").IsMatch(context.Request.Path.Value))
            {
                await next(context).ConfigureAwait(false);

                return;
            }
#endif
            IAccessTokenProvider tokenProvider = context.RequestServices.GetRequiredService <IAccessTokenProvider>();

            SecurityPoliciesApplicationService spas = context.RequestServices.GetService <SecurityPoliciesApplicationService>();

            spas.User = await tokenProvider.FromRequestHeaderAsync(context).ConfigureAwait(false);

            Authentication.AuthenticatedUser = spas.User;

            await next(context).ConfigureAwait(false);
        }