public async Task 变量抛异常(string bpmnFile) { var ex = await Record.ExceptionAsync(async() => { string uid = Guid.NewGuid().ToString(); ProcessInstance[] instances = AsyncHelper.RunSync(() => ctx.StartUseFile(bpmnFile, new string[0], new Dictionary <string, object> { { "starter", new string[] { uid } } })); ITaskController tc = ctx.CreateWorkflowHttpProxy().GetTaskClient(); Resources <TaskModel> tasks = await tc.MyTasks(uid).ConfigureAwait(false); TaskModel task = tasks.List.FirstOrDefault(x => x.Status == "ASSIGNED"); await tc.CompleteTask(new CompleteTaskCmd { TaskId = task.Id }).ConfigureAwait(false); Assert.NotNull(instances); Assert.True(instances.Count() > 0); }).ConfigureAwait(false); Assert.NotNull(ex); }
public async Task 任务转审单人(string bpmnFile) { var ex = await Record.ExceptionAsync(async() => { string sid = Guid.NewGuid().ToString(); ProcessInstance[] instances = AsyncHelper.RunSync(() => ctx.StartUseFile(bpmnFile, new string[] { sid })); Assert.NotNull(instances); Assert.True(instances.Count() > 0); ITaskController tc = ctx.CreateWorkflowHttpProxy().GetTaskClient(); var tasks = await tc.MyTasks(sid).ConfigureAwait(false); var uid = Guid.NewGuid().ToString(); TaskModel[] model = await tc.TransferTask(new TransferTaskCmd { TaskId = tasks.List.FirstOrDefault().Id, Assignees = new string[] { uid }, Description = "转审测试" }).ConfigureAwait(false); tasks = await tc.MyTasks(uid).ConfigureAwait(false); await tc.CompleteTask(new CompleteTaskCmd { TaskId = tasks.List.First().Id }).ConfigureAwait(false); tasks = await tc.MyTasks(uid).ConfigureAwait(false); }); Assert.Null(ex); }
public async Task <bool> Passed(string id) { //处理业务部分内容 IUserInfo user = await accessToken.FromRequestHeaderAsync(httpContext); WorkflowVariable workflowVariable = new WorkflowVariable(); workflowVariable.Approvaled = true; //提交流程 await taskClient.CompleteTask(new CompleteTaskCmd { BusinessKey = id, Assignee = user.Id, OutputVariables = workflowVariable }); return(true); }
public void 主活动终止事件同时终止子活动(string bpmnFile, string subBpmnFile) { var ex = Record.Exception(() => { string 主任务 = Guid.NewGuid().ToString(); string 一任务 = Guid.NewGuid().ToString(); string[] subUsers = new string[] { Guid.NewGuid().ToString() }; string[] subUsers1 = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; var bizIds = new string[] { Guid.NewGuid().ToString() }; ctx.Deploy(bpmnFile); ctx.Deploy(subBpmnFile); WorkflowVariable vars = new WorkflowVariable(); vars.AddAssignee(nameof(主任务), 主任务) .AddAssignee(nameof(一任务), 一任务) .AddAssignee(nameof(subUsers), subUsers) .AddAssignee(nameof(subUsers1), subUsers1); vars.Add("ids", bizIds); string bizId = Guid.NewGuid().ToString(); ProcessInstance[] instances = ctx.StartUseFile(bpmnFile, null, vars, businessKey: bizId).GetAwaiter().GetResult(); ITaskController taskClient = ctx.CreateWorkflowHttpProxy().GetTaskClient(); Assert.NotEmpty(taskClient.MyTasks(主任务).GetAwaiter().GetResult().List); Assert.NotEmpty(taskClient.MyTasks(subUsers[0]).GetAwaiter().GetResult().List); ///完成主任务节点的任务 taskClient.CompleteTask(new CompleteTaskCmd { BusinessKey = bizId, Assignee = 主任务 }).GetAwaiter().GetResult(); Assert.Empty(taskClient.MyTasks(subUsers[0]).GetAwaiter().GetResult().List); Assert.Empty(taskClient.MyTasks(一任务).GetAwaiter().GetResult().List); var pi = ctx.CreateWorkflowHttpProxy().GetProcessInstanceClient().GetProcessInstanceById(instances[0].Id).GetAwaiter().GetResult(); }); Assert.NotNull(ex); }
private async Task <Resources <TaskModel> > Complete(ITaskController tc, string userId, WorkflowVariable vars) { Resources <TaskModel> tasks = await tc.MyTasks(userId).ConfigureAwait(false); TaskModel task = tasks.List.FirstOrDefault(); await tc.CompleteTask(new CompleteTaskCmd { TaskId = task.Id, OutputVariables = vars }).ConfigureAwait(false); tasks = await tc.MyTasks(userId).ConfigureAwait(false); return(tasks); }
public void 部分完成并行子活动(string bpmnFile, string subBpmnFile) { var ex = Record.Exception(() => { string teachers = Guid.NewGuid().ToString(); string students = Guid.NewGuid().ToString(); string[] subUsers = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; string[] subUsers1 = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; var bizIds = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; ctx.Deploy(bpmnFile); ctx.Deploy(subBpmnFile); WorkflowVariable vars = new WorkflowVariable(); vars.AddAssignee(nameof(teachers), teachers) .AddAssignee(nameof(students), students) .AddAssignee(nameof(subUsers), subUsers) .AddAssignee(nameof(subUsers1), subUsers1); vars.Add("ids", bizIds); string bizId = Guid.NewGuid().ToString(); ProcessInstance[] instances = ctx.StartUseFile(bpmnFile, null, vars, businessKey: bizId).GetAwaiter().GetResult(); ITaskController taskClient = ctx.CreateWorkflowHttpProxy().GetTaskClient(); ///完成子任务节点1的任务 foreach (var uid in subUsers) { var myTasks = taskClient.MyTasks(uid).GetAwaiter().GetResult().List.ToList(); myTasks.ForEach(tsk => { taskClient.CompleteTask(new CompleteTaskCmd { TaskId = tsk.Id }).GetAwaiter().GetResult(); }); } { //任务节点1仅完成子用户1的任务,子活动1应该停在任务节点2 var myTask = taskClient.MyTasks(subUsers1[0]).GetAwaiter().GetResult().List.First(); _ = taskClient.CompleteTask(new CompleteTaskCmd { TaskId = myTask.Id }).GetAwaiter().GetResult(); //完成子活动2的所有任务 var myTasks = taskClient.MyTasks(subUsers1[1]).GetAwaiter().GetResult().List.ToList(); myTasks.ForEach(tsk => taskClient.CompleteTask(new CompleteTaskCmd { TaskId = tsk.Id }).GetAwaiter().GetResult()); Assert.NotEmpty(taskClient.MyTasks(subUsers1[0]).GetAwaiter().GetResult().List); } var sTasks = taskClient.MyTasks(students).GetAwaiter().GetResult().List; Assert.Empty(sTasks); }); Assert.Null(ex); }
public void 调用子活动(string bpmnFile, string subBpmnFile) { var ex = Record.Exception(() => { string teachers = Guid.NewGuid().ToString(); string students = Guid.NewGuid().ToString(); string[] subUsers = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; string[] subUsers1 = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; var bizIds = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; ctx.Deploy(bpmnFile); ctx.Deploy(subBpmnFile); WorkflowVariable vars = new WorkflowVariable(); vars.AddAssignee(nameof(teachers), teachers) .AddAssignee(nameof(students), students) .AddAssignee(nameof(subUsers), subUsers) .AddAssignee(nameof(subUsers1), subUsers1); string bizId = Guid.NewGuid().ToString(); ProcessInstance[] instances = ctx.StartUseFile(bpmnFile, null, vars, businessKey: bizId).GetAwaiter().GetResult(); ITaskController taskClient = ctx.CreateWorkflowHttpProxy().GetTaskClient(); TaskModel task = taskClient.MyTasks(teachers).GetAwaiter().GetResult().List.FirstOrDefault(); _ = taskClient.CompleteTask(new CompleteTaskCmd { TaskId = task.Id, OutputVariables = WorkflowVariable.FromObject(new { ids = bizIds, 完成 = true }), NotFoundThrowError = true }).GetAwaiter().GetResult(); Resources <TaskModel> tasks = ctx.CreateWorkflowHttpProxy().GetProcessInstanceTasksClient() .GetTasks(new ProcessInstanceTaskQuery() { IncludeCompleted = false, ProcessInstanceId = instances[0].Id }).GetAwaiter().GetResult(); foreach (var uid in subUsers) { var myTasks = taskClient.MyTasks(uid).GetAwaiter().GetResult().List.ToList(); myTasks.ForEach(tsk => taskClient.CompleteTask(new CompleteTaskCmd { TaskId = tsk.Id }).GetAwaiter().GetResult()); } foreach (var uid in subUsers1) { var myTasks = taskClient.MyTasks(uid).GetAwaiter().GetResult().List.ToList(); myTasks.ForEach(tsk => taskClient.CompleteTask(new CompleteTaskCmd { TaskId = tsk.Id }).GetAwaiter().GetResult()); } var sTasks = taskClient.MyTasks(students).GetAwaiter().GetResult().List.ToList(); sTasks.ForEach(tsk => taskClient.CompleteTask(new CompleteTaskCmd { TaskId = tsk.Id }).GetAwaiter().GetResult()); ctx.CreateWorkflowHttpProxy().GetProcessInstanceClient().GetProcessInstanceById(instances[0].Id).GetAwaiter().GetResult(); }); Assert.NotNull(ex); }
public void 使用子活动BUSINEEKEY完成并行子活动(string bpmnFile, string subBpmnFile) { var ex = Record.Exception(() => { string teachers = Guid.NewGuid().ToString(); string students = Guid.NewGuid().ToString(); string[] subUsers = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; string[] subUsers1 = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; var bizIds = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; ctx.Deploy(bpmnFile); ctx.Deploy(subBpmnFile); WorkflowVariable vars = new WorkflowVariable(); vars.AddAssignee(nameof(teachers), teachers) .AddAssignee(nameof(students), students) .AddAssignee(nameof(subUsers), subUsers) .AddAssignee(nameof(subUsers1), subUsers1); vars.Add("ids", bizIds); string bizId = Guid.NewGuid().ToString(); ProcessInstance[] instances = ctx.StartUseFile(bpmnFile, null, vars, businessKey: bizId).GetAwaiter().GetResult(); ITaskController taskClient = ctx.CreateWorkflowHttpProxy().GetTaskClient(); ///完成子任务节点1的任务 foreach (var uid in subUsers) { foreach (var bid in bizIds) { taskClient.CompleteTask(new CompleteTaskCmd { Assignee = uid, BusinessKey = bid }).GetAwaiter().GetResult(); } } //完成子活动1,2的所有任务 foreach (var uid in subUsers1) { foreach (var bid in bizIds) { taskClient.CompleteTask(new CompleteTaskCmd { Assignee = uid, BusinessKey = bid }).GetAwaiter().GetResult(); } } var sTasks = taskClient.MyTasks(students).GetAwaiter().GetResult().List; Assert.NotEmpty(sTasks); }); Assert.Null(ex); }
public void 完成并行子活动(string bpmnFile, string subBpmnFile) { var ex = Record.Exception(() => { string teachers = Guid.NewGuid().ToString(); string students = Guid.NewGuid().ToString(); string[] subUsers = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; string[] subUsers1 = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; var bizIds = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; ctx.Deploy(bpmnFile); ctx.Deploy(subBpmnFile); WorkflowVariable vars = new WorkflowVariable(); vars.AddAssignee(nameof(teachers), teachers) .AddAssignee(nameof(students), students) .AddAssignee(nameof(subUsers), subUsers) .AddAssignee(nameof(subUsers1), subUsers1); vars.Add("ids", bizIds); string bizId = Guid.NewGuid().ToString(); ProcessInstance[] instances = ctx.StartUseFile(bpmnFile, null, vars, businessKey: bizId).GetAwaiter().GetResult(); ITaskController taskClient = ctx.CreateWorkflowHttpProxy().GetTaskClient(); ///完成子任务节点1的任务 foreach (var uid in subUsers) { var myTasks = taskClient.MyTasks(uid).GetAwaiter().GetResult().List; Task.WhenAll(Enumerable.Select(myTasks, (task) => { return(taskClient.CompleteTask(new CompleteTaskCmd { TaskId = task.Id })); })).GetAwaiter().GetResult(); } { //完成子活动1,2的所有任务 foreach (var uid in subUsers1) { var myTasks = taskClient.MyTasks(uid).GetAwaiter().GetResult().List; taskClient.CompleteTask(myTasks.Select(tsk => new CompleteTaskCmd { TaskId = tsk.Id }).ToArray()).GetAwaiter().GetResult(); } } var sTasks = taskClient.MyTasks(students).GetAwaiter().GetResult().List; Assert.NotEmpty(sTasks); }); Assert.Null(ex); }
public void 部分完成并行子活动(string bpmnFile, string subBpmnFile) { var ex = Record.Exception(() => { string teachers = Guid.NewGuid().ToString(); string students = Guid.NewGuid().ToString(); string[] subUsers = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; string[] subUsers1 = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; var bizIds = new string[] { Guid.NewGuid().ToString(), Guid.NewGuid().ToString() }; ctx.Deploy(bpmnFile); ctx.Deploy(subBpmnFile); WorkflowVariable vars = new WorkflowVariable(); vars.AddAssignee(nameof(teachers), teachers) .AddAssignee(nameof(students), students) .AddAssignee(nameof(subUsers), subUsers) .AddAssignee(nameof(subUsers1), subUsers1); string bizId = Guid.NewGuid().ToString(); ProcessInstance[] instances = AsyncHelper.RunSync(() => ctx.StartUseFile(bpmnFile, null, vars, businessKey: bizId)); ITaskController taskClient = ctx.CreateWorkflowHttpProxy().GetTaskClient(); TaskModel task = AsyncHelper.RunSync(() => taskClient.MyTasks(teachers)).List.FirstOrDefault(); _ = AsyncHelper.RunSync(() => taskClient.CompleteTask(new CompleteTaskCmd { TaskId = task.Id, OutputVariables = WorkflowVariable.FromObject(new { ids = bizIds, 完成 = true }), NotFoundThrowError = true })); ///完成子任务节点1的任务 foreach (var uid in subUsers) { var myTasks = AsyncHelper.RunSync(() => taskClient.MyTasks(uid)).List.ToList(); myTasks.ForEach(tsk => AsyncHelper.RunSync(() => taskClient.CompleteTask(new CompleteTaskCmd { TaskId = tsk.Id }))); } { //任务节点1仅完成子用户1的任务,子活动1应该停在任务节点2 var myTask = AsyncHelper.RunSync(() => taskClient.MyTasks(subUsers1[0])).List.First(); AsyncHelper.RunSync(() => taskClient.CompleteTask(new CompleteTaskCmd { TaskId = myTask.Id })); //完成子活动2的所有任务 var myTasks = AsyncHelper.RunSync(() => taskClient.MyTasks(subUsers1[1])).List.ToList(); myTasks.ForEach(tsk => AsyncHelper.RunSync(() => taskClient.CompleteTask(new CompleteTaskCmd { TaskId = tsk.Id }))); } var sTasks = AsyncHelper.RunSync(() => taskClient.MyTasks(students)).List; Assert.Empty(sTasks); }); Assert.Null(ex); }