public async Task <ProcessInstance[]> StartAsync(string bpmnFile, string[] users, IDictionary <string, object> variables = null, string bpmnName = null)
        {
            IProcessInstanceController client = CreateWorkflowHttpProxy().GetProcessInstanceClient();

            Deployment dep = await DeployAsync(bpmnFile, bpmnName).ConfigureAwait(false);

            StartProcessInstanceCmd[] cmds = new StartProcessInstanceCmd[users.Length];
            for (int idx = 0; idx < users.Length; idx++)
            {
                var user = users[idx];

                var vars = new Dictionary <string, object>(variables ?? new Dictionary <string, object>())
                {
                    { "name", new string[] { user } }
                };
                StartProcessInstanceCmd cmd = new StartProcessInstanceCmd()
                {
                    ProcessName = dep.Name,
                    Variables   = vars,
                    TenantId    = TenantId
                };

                cmds[idx] = cmd;
            }

            ProcessInstance[] instances = await client.Start(cmds).ConfigureAwait(false);

            return(instances);
        }
        public Task <ProcessInstance[]> StartUseFile(string bpmnFile, string[] users, IDictionary <string, object> variables = null, string businessKey = null)
        {
            IProcessInstanceController client = CreateWorkflowHttpProxy().GetProcessInstanceClient();

            string processDefinitionId = GetOrAddProcessDefinition(bpmnFile).Id;

            var vars = new Dictionary <string, object>(variables ?? new Dictionary <string, object>());

            if (users is object)
            {
                vars.TryAdd("name", users);
            }

            StartProcessInstanceCmd cmd = new StartProcessInstanceCmd()
            {
                ProcessDefinitionId = processDefinitionId,
                Variables           = vars,
                BusinessKey         = businessKey,
                TenantId            = TenantId
            };

            StartProcessInstanceCmd[] cmds = new StartProcessInstanceCmd[] { cmd };

            return(client.Start(cmds));
        }
        public ProcessInstance[] Start(string bpmnFile, string[] users, IDictionary <string, object> variables = null)
        {
            IProcessInstanceController client = CreateWorkflowHttpProxy().GetProcessInstanceClient();

            string     bpmnName = string.Join("", Guid2IntString(Guid.NewGuid()));
            Deployment dep      = Deploy(bpmnFile, bpmnName);

            StartProcessInstanceCmd[] cmds = new StartProcessInstanceCmd[users.Length];
            for (int idx = 0; idx < users.Length; idx++)
            {
                var user = users[idx];

                var vars = new Dictionary <string, object>(variables ?? new Dictionary <string, object>());
                vars.Add("name", new string[] { user });
                StartProcessInstanceCmd cmd = new StartProcessInstanceCmd()
                {
                    ProcessName = bpmnName,
                    Variables   = vars,
                    TenantId    = TenantId
                };

                cmds[idx] = cmd;
            }

            ProcessInstance[] instances = client.Start(cmds).GetAwaiter().GetResult();

            return(instances);
        }
Beispiel #4
0
        public void Remove_删除部署的流程_如果当前流程已存在实例则抛出异常_否则删除(string bpmnFile)
        {
            var ex = Record.Exception(() =>
            {
                string bpmnName       = string.Join("", ctx.Guid2IntString(Guid.NewGuid()));
                Deployment deployment = ctx.DeployAsync(bpmnFile, bpmnName).GetAwaiter().GetResult();

                IProcessInstanceController instanceController = ctx.CreateWorkflowHttpProxy().GetProcessInstanceClient();

                StartProcessInstanceCmd cmd = new StartProcessInstanceCmd
                {
                    ProcessName = bpmnName,
                    TenantId    = ctx.TenantId,
                    Variables   = new Dictionary <string, object>
                    {
                        { "name", new string[] { "用户1" } }
                    },
                };
                ProcessInstance[] instances = instanceController.Start(new StartProcessInstanceCmd[] { cmd }).GetAwaiter().GetResult();

                Assert.True(instances.Length > 0);

                IProcessDefinitionDeployerController deployerController = ctx.CreateWorkflowHttpProxy().GetDefinitionDeployerClient();

                deployerController.Remove(deployment.Id).GetAwaiter().GetResult();
            });

            Assert.NotNull(ex);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public async Task Start_完成用户注册路径_男(string bpmnFile)
        {
            var ex = await Record.ExceptionAsync(async() =>
            {
                IProcessDefinitionDeployerController pdc = ctx.CreateWorkflowHttpProxy().GetDefinitionDeployerClient();

                string formKey = Guid.NewGuid().ToString();

                string xml    = IntegrationTestContext.ReadBpmn(bpmnFile);
                XDocument doc = XDocument.Load(new MemoryStream(Encoding.UTF8.GetBytes(xml)), LoadOptions.PreserveWhitespace);
                var elem      = doc.Descendants(XName.Get("startEvent", BpmnXMLConstants.BPMN2_NAMESPACE)).First();
                elem.Attribute(XName.Get("formKey", BpmnXMLConstants.ACTIVITI_EXTENSIONS_NAMESPACE)).Value = formKey;

                Deployment deployment = await pdc.Deploy(new ProcessDefinitionDeployer
                {
                    BpmnXML  = doc.ToString(),
                    Name     = Path.GetFileNameWithoutExtension(bpmnFile),
                    TenantId = ctx.TenantId
                }).ConfigureAwait(false);

                string uid = Guid.NewGuid().ToString();
                StartProcessInstanceCmd cmd = new StartProcessInstanceCmd()
                {
                    StartForm = formKey,
                    Variables = new Dictionary <string, object>
                    {
                        { "User", new string[] { uid } }
                    },
                    TenantId = ctx.TenantId
                };

                ProcessInstance[] instances = AsyncHelper.RunSync <ProcessInstance[]>(() => client.Start(new StartProcessInstanceCmd[] { cmd }));

                Assert.NotNull(instances);
                Assert.True(instances.Count() > 0);

                ITaskController tc = ctx.CreateWorkflowHttpProxy().GetTaskClient();

                Resources <TaskModel> myTasks = null;

                while (true)
                {
                    myTasks = await Complete(tc, uid, new Dictionary <string, object>
                    {
                        { "gender", 1 }
                    }).ConfigureAwait(false);

                    if (myTasks == null || myTasks.TotalCount <= 0)
                    {
                        break;
                    }
                }
            }).ConfigureAwait(false);

            Assert.Null(ex);
        }
        public Task <ProcessInstance[]> StartUseFile(ProcessDefinition process, IDictionary <string, object> variables = null)
        {
            IProcessInstanceController client = CreateWorkflowHttpProxy().GetProcessInstanceClient();

            var vars = new Dictionary <string, object>(variables ?? new Dictionary <string, object>());

            StartProcessInstanceCmd cmd = new StartProcessInstanceCmd()
            {
                ProcessDefinitionId = process.Id,
                Variables           = vars,
                TenantId            = TenantId
            };

            StartProcessInstanceCmd[] cmds = new StartProcessInstanceCmd[] { cmd };

            return(client.Start(cmds));
        }
Beispiel #8
0
        public Task <ProcessInstance[]> Start(IProcessInstanceController client, string bpmnFile, string[] users)
        {
            string bpmnName = string.Join("", ctx.Guid2IntString(Guid.NewGuid()));

            ctx.Deploy(bpmnFile, bpmnName);

            var vars = new Dictionary <string, object>
            {
                { "name", users }
            };
            StartProcessInstanceCmd cmd = new StartProcessInstanceCmd()
            {
                ProcessName = bpmnName,
                Variables   = vars,
                TenantId    = ctx.TenantId
            };

            StartProcessInstanceCmd[] cmds = new StartProcessInstanceCmd[] { cmd };

            return(client.Start(cmds));
        }