private static IWfProcess StartNewProcess(IWfProcessDescriptor processDesp, IWfProcess originalProcess, string newResourceID, IUser processCreator, IOrganization department) { WfProcessStartupParams wp = new WfProcessStartupParams(processDesp); IWfProcess process = WfRuntime.StartWorkflow(typeof(OAWfProcess), wp); process.OwnerDepartment = department; WfTransferParams tParams = new WfTransferParams(wp.Descriptor.InitialActivity); tParams.Operator = DeluxeIdentity.CurrentUser; tParams.Receivers.Add(processCreator); process.MoveTo(tParams); process.Context["ApplicationName"] = originalProcess.Context["ApplicationName"]; process.Context["ProgramName"] = originalProcess.Context["ProgramName"]; ((OAWfProcess)process).ResourceID = newResourceID; process.Context[WfVariableDefine.ProcessDraftDepartmentNameVariableName] = WfVariableDefine.GetProcessDraftDepartmentName(originalProcess); process.Context[WfVariableDefine.ProcessDraftUserIDVariableName] = WfVariableDefine.GetProcessDraftUserID(originalProcess); process.Context[WfVariableDefine.ProcessDraftUserNameVariableName] = WfVariableDefine.GetProcessDraftUserName(originalProcess); return(process); }
public WfTransferParams ClientToServer(WfClientTransferParams client, IWfProcess process, ref WfTransferParams server) { client.NullCheck("client"); if (server == null) server = new WfTransferParams(); server.Context["NextActivityDescriptorKey"] = client.NextActivityDescriptorKey; server.Context["FromTransitionDescriptorKey"] = client.FromTransitionDescriptorKey; if (process != null) { if (client.NextActivityDescriptorKey.IsNotEmpty()) { IWfActivity nextActivity = process.Activities.FindActivityByDescriptorKey(client.NextActivityDescriptorKey); if (nextActivity != null) server.NextActivityDescriptor = nextActivity.Descriptor; } if (client.FromTransitionDescriptorKey.IsNotEmpty()) { IWfTransitionDescriptor fromTransition = process.Descriptor.FindTransitionByKey(client.FromTransitionDescriptorKey); server.FromTransitionDescriptor = fromTransition; } } server.Operator = (IUser)client.Operator.ToOguObject(); WfClientBranchProcessTransferParamsCollectionConverter.Instance.ClientToServer(client.BranchTransferParams, server.BranchTransferParams); WfClientAssigneeCollectionConverter.Instance.ClientToServer(client.Assignees, server.Assignees); return server; }
public void ProcessWithMatrix() { try { var wfDescriptor = WfProcessDescriptorManager.GetDescriptor("workflowmatrixtest"); WfProcessStartupParams startParam = new WfProcessStartupParams(); startParam.ProcessDescriptor = wfDescriptor; var processInstance = WfRuntime.StartWorkflow(startParam); processInstance.ApplicationRuntimeParameters.Add("支付方式", "网银"); processInstance.ApplicationRuntimeParameters.Add("成本中心", "成1"); processInstance.ApplicationRuntimeParameters.Add("费用类型", "差旅费"); processInstance.ApplicationRuntimeParameters.Add("金额", "100"); processInstance.ApplicationRuntimeParameters.Add("部门", "商务部"); WfTransferParams transferParams = new WfTransferParams(processInstance.Descriptor.Activities["N2"]); var currentAct = processInstance.MoveTo(transferParams); currentAct.Candidates.ForEach(p => { Console.WriteLine(p.User.DisplayName); }); } catch { } }
public void MovetoDelegationTest() { WfDelegation delegation = PrepareDelegation(); WfDelegationAdapter.Instance.Update(delegation); //添加委托 try { //创建流程 IWfProcess process = WfProcessTestCommon.StartupProcessWithAssignee(); IWfActivityDescriptor nextActivityDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfTransferParams tp = ProcessTestHelper.GetInstanceOfWfTransferParams(nextActivityDesp, OguObject.approver1); process.MoveTo(tp); //流转 WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); Assert.IsTrue((ProcessTestHelper.GetActivityUserTasks(process.CurrentActivity.ID, TaskStatus.Ban).Count) >= 2, "至少有两个待办事项。或许其它人也会去为当前人指定相应的委托人"); } finally { WfDelegationAdapter.Instance.Delete(delegation); //清理委托 } }
public void ActivityConditionTest() { TestContext.Properties["Amount"] = 2500; //不满足条件 WfRuntime.ProcessContext.EvaluateActivityCondition += new Expression.CalculateUserFunction(ProcessContext_EvaluateTransition); IWfProcess process = WfProcessTestCommon.StartupSimpleProcessDescriptorWithActivityCondition(); Assert.AreEqual(WfActivityStatus.Running, process.InitialActivity.Status); IWfActivityDescriptor nextActivityDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfTransferParams transferParams = ProcessTestHelper.GetInstanceOfWfTransferParams(nextActivityDesp, OguObject.requestor); process.MoveTo(transferParams); Assert.AreEqual(WfActivityStatus.Completed, process.InitialActivity.Status); Assert.AreEqual(WfActivityStatus.Pending, process.CurrentActivity.Status); IWfActivity activity = WfRuntime.ProcessContext.OriginalActivity; WfRuntime.PersistWorkflows(); TestContext.Properties["Amount"] = 7500; WfPendingActivityInfoCollection pendingActivities = WfPendingActivityInfoAdapter.Instance.Load(builder => builder.AppendItem("ACTIVITY_ID", process.CurrentActivity.ID)); pendingActivities.ForEach(pai => WfRuntime.ProcessPendingActivity(pai)); }
public void CancelDelegationTest() { WfDelegation delegation = PrepareDelegation(); WfDelegationAdapter.Instance.Update(delegation); try { IWfProcess process = WfProcessTestCommon.StartupProcessWithAssignee(); IWfActivityDescriptor nextActivityDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfTransferParams tp = ProcessTestHelper.GetInstanceOfWfTransferParams(nextActivityDesp, OguObject.approver1); process.MoveTo(tp); WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); process.CancelProcess(false); //取消 WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); Assert.AreEqual(2, ProcessTestHelper.GetActivityUserTasks(process.CurrentActivity.ID, TaskStatus.Yue).Count, "应该产生两条待阅"); } finally { WfDelegationAdapter.Instance.Delete(delegation); //清理委托 } }
public WfClientProcessInfo MoveTo(string processID, WfClientTransferParams clientTransferParams, WfClientRuntimeContext runtimeContext) { processID.CheckStringIsNullOrEmpty("processID"); clientTransferParams.NullCheck("clientTransferParams"); OperationContext.Current.FillContextToOguServiceContext(); IWfProcess process = GetProcessByProcessID(processID, runtimeContext); MeregeRuntimeContext(process, runtimeContext); WfTransferParams transferParams = null; WfClientTransferParamsConverter.Instance.ClientToServer(clientTransferParams, process, ref transferParams); MergeTransferParams(transferParams, runtimeContext); IWfActivity originalActivity = process.CurrentActivity; ExecuteExecutor(process, runtimeContext, (p) => { WfMoveToExecutor executor = new WfMoveToExecutor(p.CurrentActivity, p.CurrentActivity, transferParams); executor.SaveApplicationData += (dataContext) => SaveOpinion(runtimeContext.Opinion, originalActivity, transferParams); executor.PrepareMoveToTasks += (dataContext, tasks) => tasks.ForEach(task => task.Purpose = p.CurrentActivity.Descriptor.Name); return(executor); }); return(process.ToClientProcessInfo(transferParams.Operator).FillCurrentOpinion(process.CurrentActivity, runtimeContext.Operator)); }
public void ActivityOperatorResourceTest() { IWfProcess process = WfProcessTestCommon.StartupProcessWithAssignee(); IWfActivityDescriptor nextActivityDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfTransferParams tp = ProcessTestHelper.GetInstanceOfWfTransferParams(nextActivityDesp, OguObject.approver1); IUser requestor = (IUser)OguObjectSettings.GetConfig().Objects["requestor"].Object; tp.Operator = requestor; process.MoveTo(tp); WfActivityOperatorResourceDescriptor resource = new WfActivityOperatorResourceDescriptor(); resource.ActivityKey = process.InitialActivity.Descriptor.Key; process.CurrentActivity.Descriptor.Resources.Add(resource); OguDataCollection <IUser> users = process.CurrentActivity.Descriptor.Resources.ToUsers(); Assert.IsTrue(users.Count > 0); Assert.AreEqual(requestor.ID, users[0].ID, "验证资源中的人员是否是之前活动的操作人"); WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); users = process.CurrentActivity.Descriptor.Resources.ToUsers(); Assert.IsTrue(users.Count > 0, "重新加载后资源中应该有人"); Assert.AreEqual(requestor.ID, users[0].ID, "重新加载后验证资源中的人员是否是之前活动的操作人"); }
public void NoticeOfLeaveActivity() { IWfProcess process = WfProcessTestCommon.StartupProcessWithAssignee(); IWfActivityDescriptor nextActivityDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfUserResourceDescriptor userResDesp = GetUserResDespInstance(); nextActivityDesp.LeaveEventReceivers.Add(userResDesp); WfTransferParams tp = ProcessTestHelper.GetInstanceOfWfTransferParams(nextActivityDesp, OguObject.approver2); process.MoveTo(tp); WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); process.MoveTo(new WfTransferParams(process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity)); WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); string actKey = process.CurrentActivity.Descriptor.FromTransitions[0].FromActivity.Key; Assert.IsTrue(ProcessTestHelper.ExistsActivityUserTasks(userResDesp.User.ID, process.Activities[1].ID, TaskStatus.Yue)); }
protected void descriptorEditor_SaveButtonClicked(object sender, EventArgs e) { IWfTransitionDescriptor transition = GetNextMoveToTransition(this.operationEditor.CurrentProcess); (transition != null).FalseThrow("不能找到下一步能够流转的连线"); //如果下一步不允许为人员为空,则校验。 if (transition.ToActivity.Properties.GetValue("AllowEmptyCandidates", true) == false) { (this.userSelector.SelectedOuUserData.Count > 0).FalseThrow("必须指定下一步的流转人员"); } WfTransferParams transferParams = new WfTransferParams(transition.ToActivity); transferParams.FromTransitionDescriptor = transition; transferParams.Operator = DeluxeIdentity.CurrentUser; foreach (IUser candidate in this.userSelector.SelectedOuUserData) { transferParams.Assignees.Add(candidate); } WfMoveToExecutor executor = new WfMoveToExecutor( this.operationEditor.CurrentProcess.CurrentActivity, this.operationEditor.CurrentProcess.CurrentActivity, transferParams); executor.Execute(); }
private static IWfProcess GetProcessInstanceWithAssigneesResource() { IWfProcess process = WfProcessTestCommon.StartupProcessWithAssignee(); IWfActivityDescriptor nextActivityDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfTransferParams tp = ProcessTestHelper.GetInstanceOfWfTransferParams(nextActivityDesp, OguObject.approver2); process.MoveTo(tp); WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); IWfActivityDescriptor actDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfActivityAssigneesResourceDescriptor actAssResDesp = new WfActivityAssigneesResourceDescriptor(); actAssResDesp.ActivityKey = actDesp.Key; actDesp.Resources.Add(actAssResDesp); nextActivityDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfTransferParams tpa = ProcessTestHelper.GetInstanceOfWfTransferParams(nextActivityDesp, OguObject.approver1); process.MoveTo(tpa); WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); return(process); }
public void CancelProcessInOtherActivityTest() { IWfProcess process = WfProcessTestCommon.StartupProcessWithAssignee(); WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); IWfActivityDescriptor nextActivityDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfTransferParams tp = ProcessTestHelper.GetInstanceOfWfTransferParams(nextActivityDesp, OguObject.requestor); process.MoveTo(tp); WfRuntime.PersistWorkflows(); UserTaskCollection tasks = UserTaskAdapter.Instance.LoadUserTasks(b => b.AppendItem("ACTIVITY_ID", process.CurrentActivity.ID)); Console.WriteLine("Current Activity ID: {0}", process.CurrentActivity.ID); Console.WriteLine("User Task Count: {0}", tasks.Count); process = CancelProcess(process, false); UserTaskCollection userAccomlishedTasks = UserTaskAdapter.Instance.GetUserAccomplishedTasks(UserTaskIDType.ActivityID, UserTaskFieldDefine.All, false, process.CurrentActivity.ID); Console.WriteLine("User Accomplished Task Count: {0}", userAccomlishedTasks.Count); Assert.AreEqual(tasks.Count, userAccomlishedTasks.Count); }
protected void descriptorEditor_SaveButtonClicked(object sender, EventArgs e) { IWfTransitionDescriptor transition = GetNextMoveToTransition(this.operationEditor.CurrentProcess); (transition != null).FalseThrow("不能找到下一步能够流转的连线"); //如果下一步不允许为人员为空,则校验。 if (transition.ToActivity.Properties.GetValue("AllowEmptyCandidates", true) == false) { (this.userSelector.SelectedOuUserData.Count > 0).FalseThrow("必须指定下一步的流转人员"); } WfTransferParams transferParams = new WfTransferParams(transition.ToActivity); transferParams.FromTransitionDescriptor = transition; transferParams.Operator = DeluxeIdentity.CurrentUser; foreach (IUser candidate in this.userSelector.SelectedOuUserData) transferParams.Assignees.Add(candidate); WfMoveToExecutor executor = new WfMoveToExecutor( this.operationEditor.CurrentProcess.CurrentActivity, this.operationEditor.CurrentProcess.CurrentActivity, transferParams); executor.Execute(); }
public void SimpleProcessPersistTest() { IWfProcess process = WfProcessTestCommon.StartupSimpleProcessWithAssignee(); //process.DefaultTaskTitle = "测试保存的流程"; ProcessTestHelper.OutputExecutionTime(() => WfRuntime.PersistWorkflows(), "保存简单流程"); try { IWfProcess loadedProcess = WfRuntime.GetProcessByProcessID(process.ID); Assert.AreEqual(process.ID, loadedProcess.ID); Assert.AreEqual(process.Status, loadedProcess.Status); Assert.AreEqual(DataLoadingType.External, loadedProcess.LoadingType); WfTransferParams transferParams = new WfTransferParams(process.Descriptor.CompletedActivity); transferParams.Assignees.Add(new WfAssignee((IUser)OguObjectSettings.GetConfig().Objects["approver1"].Object)); transferParams.Assignees.Add(new WfAssignee((IUser)OguObjectSettings.GetConfig().Objects["approver2"].Object)); loadedProcess.MoveTo(transferParams); WfRuntime.PersistWorkflows(); Assert.AreEqual(process.ID, loadedProcess.ID); Assert.AreEqual(WfProcessStatus.Completed, loadedProcess.Status); Assert.AreEqual(DataLoadingType.External, loadedProcess.LoadingType); } finally { //WfRuntime.DeleteProcessByProcessID(process.ID); } }
public void SimpleProcessPersistRepeatTest() { IWfProcess process = WfProcessTestCommon.StartupSimpleProcessWithAssignee(); //process.DefaultTaskTitle = "测试保存的流程"; WfRuntime.PersistWorkflows(); IWfProcess loadedProcess = WfRuntime.GetProcessByProcessID(process.ID); IWfProcess loadedProcess2 = WfRuntime.GetProcessByActivityID(process.Activities[0].ID); Assert.AreEqual(loadedProcess, loadedProcess2); int n = loadedProcess.Activities.Count; for (int i = 0; i < n; i++) { if (loadedProcess.Activities[i].Descriptor != loadedProcess.Descriptor.InitialActivity) { WfTransferParams transferPara = new WfTransferParams(loadedProcess.Activities[i].Descriptor); loadedProcess.MoveTo(transferPara); WfRuntime.PersistWorkflows(); } loadedProcess = WfRuntime.GetProcessByActivityID(loadedProcess.Activities[i].ID); } IWfProcess OnceAgainloadedProcess = WfRuntime.GetProcessByProcessID(process.ID); Assert.AreEqual(OnceAgainloadedProcess.ID, process.ID); }
public void BranchProcessPersistTest() { IWfProcess process = WfProcessTestCommon.StartupSimpleProcessWithAssignee(); WfTransferParams tp = ProcessTestHelper.GetInstanceOfWfTransferParams(process, WfBranchProcessExecuteSequence.Parallel, WfBranchProcessBlockingType.WaitAllBranchProcessesComplete); process.MoveTo(tp); Assert.AreEqual(1, process.CurrentActivity.BranchProcessGroups.Count); IWfBranchProcessGroup group = process.CurrentActivity.BranchProcessGroups[0]; AssertBranchProcessesInfo(group, tp.BranchTransferParams[0].Template.BranchProcessKey); WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); group = process.CurrentActivity.BranchProcessGroups[0]; AssertBranchProcessesInfo(group, tp.BranchTransferParams[0].Template.BranchProcessKey); string subProcessID = process.CurrentActivity.BranchProcessGroups[0].Branches[0].ID; WfRuntime.ClearCache(); //构造子流程,反向查找主流程信息 IWfProcess subProcess = WfRuntime.GetProcessByProcessID(subProcessID); AssertBranchProcessesInfo(subProcess.EntryInfo.OwnerActivity.BranchProcessGroups[0], tp.BranchTransferParams[0].Template.BranchProcessKey); }
public void SimpleProcessPersistTest() { IWfProcess process = WfProcessTestCommon.StartupSimpleProcessWithAssignee(); //process.DefaultTaskTitle = "测试保存的流程"; ProcessTestHelper.OutputExecutionTime(() => WfRuntime.PersistWorkflows(), "保存简单流程"); try { IWfProcess loadedProcess = WfRuntime.GetProcessByProcessID(process.ID); Assert.AreEqual(process.ID, loadedProcess.ID); Assert.AreEqual(process.Status, loadedProcess.Status); Assert.AreEqual(DataLoadingType.External, loadedProcess.LoadingType); WfTransferParams transferParams = new WfTransferParams(process.Descriptor.CompletedActivity); transferParams.Assignees.Add(new WfAssignee((IUser)OguObjectSettings.GetConfig().Objects["approver1"].Object)); transferParams.Assignees.Add(new WfAssignee((IUser)OguObjectSettings.GetConfig().Objects["approver2"].Object)); loadedProcess.MoveTo(transferParams); WfRuntime.PersistWorkflows(); Assert.AreEqual(process.ID, loadedProcess.ID); Assert.AreEqual(WfProcessStatus.Completed, loadedProcess.Status); Assert.AreEqual(DataLoadingType.External, loadedProcess.LoadingType); } finally { //WfRuntime.DeleteProcessByProcessID(process.ID); } }
public static void MoveToAndSaveNextActivityWithDefSelectTranstion(OguObject oguObject, IWfProcess process) { IWfActivityDescriptor nextActivityDesp = process.CurrentActivity.Descriptor.ToTransitions.FindDefaultSelectTransition().ToActivity; WfTransferParams transferParams = ProcessTestHelper.GetInstanceOfWfTransferParams(nextActivityDesp, oguObject); process.MoveTo(transferParams); WfRuntime.PersistWorkflows(); }
/// <summary> /// /// </summary> /// <param name="process"></param> /// <param name="transParams"></param> /// <returns></returns> public IWfActivity CreateActivity(IWfProcess process, WfTransferParams transParams) { WfActivity activity = new WfActivity(transParams.NextActivityDescriptor); activity.Operator = transParams.Operator; activity.Process = process; return activity; }
/// <summary> /// 获取下一节点的参数实例 /// </summary> /// <param name="nextActivityDesp">下一个节点的流程描述</param> /// <param name="oguObject">传入人员的名称</param> /// <returns></returns> public static WfTransferParams GetInstanceOfWfTransferParams(IWfActivityDescriptor nextActivityDesp, OguObject oguObject) { WfTransferParams tp = new WfTransferParams(nextActivityDesp); IUser user = (IUser)OguObjectSettings.GetConfig().Objects[oguObject.ToString()].Object; tp.Assignees.Add(user); return(tp); }
private static void MoveToExecutor(IWfProcess process) { IWfActivityDescriptor nextActivityDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfTransferParams pa = ProcessTestHelper.GetInstanceOfWfTransferParams(nextActivityDesp, OguObject.approver1); WfMoveToExecutor moveExec = new WfMoveToExecutor(process.CurrentActivity, process.CurrentActivity, pa); moveExec.Execute(); }
public void StandardClientTransferParamsToServer() { WfClientTransferParams client = PrepareClientTransferParams(); WfTransferParams server = null; WfClientTransferParamsConverter.Instance.ClientToServer(client, null, ref server); client.AreSame(server); }
private static IWfProcess GetProcessInstanceWithBranchProcessRunning(WfBranchProcessExecuteSequence sequence, WfBranchProcessBlockingType blockingType) { IWfProcess process = WfProcessTestCommon.StartupProcessWithAssignee(); WfTransferParams tp = ProcessTestHelper.GetInstanceOfWfTransferParams(process, sequence, blockingType); process.MoveTo(tp); WfRuntime.PersistWorkflows(); return(WfRuntime.GetProcessByProcessID(process.ID)); }
public void SimpleProcessMoveTest() { IWfProcess process = WfProcessTestCommon.StartupSimpleProcess(); WfTransferParams transferParams = new WfTransferParams(process.Descriptor.CompletedActivity); process.MoveTo(transferParams); Assert.IsTrue(process.InitialActivity.Status == WfActivityStatus.Completed); Assert.IsTrue(process.Status == WfProcessStatus.Completed); Assert.IsTrue(process.CompletedActivity.Status == WfActivityStatus.Completed); }
private void MoveToOneBranchProcessFirstActivity(WfBranchProcessInfo processInfo) { WfTransferParams initialTransferParams = new WfTransferParams(processInfo.ProcessDescriptor.InitialActivity); ((WfActivityDescriptor)processInfo.ProcessDescriptor.InitialActivity).LevelName = processInfo.OwnerOperation.AnchorActivity.Descriptor.LevelName; initialTransferParams.Receivers.CopyFrom(processInfo.BranchProcessReceiver); WfProcess process = ((WfProcess)processInfo.Process); process.MoveTo(initialTransferParams); }
public void SimpleProcessMoveTest() { IWfProcess process = WfProcessTestCommon.StartupSimpleProcess(); WfTransferParams transferParams = new WfTransferParams(process.Descriptor.CompletedActivity); process.MoveTo(transferParams); Assert.IsTrue(process.InitialActivity.Status == WfActivityStatus.Completed); Assert.IsTrue(process.Status == WfProcessStatus.Completed); Assert.IsTrue(process.CompletedActivity.Status == WfActivityStatus.Completed); }
/// <summary> /// 流转到默认的下一个活动 /// </summary> /// <param name="process"></param> /// <returns></returns> public static IWfActivity MoveToNextDefaultActivity(IWfProcess process) { IWfTransitionDescriptor transition = process.CurrentActivity.Descriptor.ToTransitions.GetAllCanTransitTransitions(true).FirstOrDefault(); Assert.IsNotNull(transition, string.Format("活动{0}没有能够使用的出线", process.CurrentActivity.Descriptor.Key)); WfTransferParams transferParams = new WfTransferParams(transition.ToActivity); process.MoveTo(transferParams); return(process.CurrentActivity); }
/// <summary> /// 获取参数实例,即设置即将流转的节点为带分支流程 /// </summary> /// <param name="process"></param> /// <param name="sequence"></param> /// <param name="blockingType"></param> /// <returns></returns> public static WfTransferParams GetInstanceOfWfTransferParams(IWfProcess process, WfBranchProcessExecuteSequence sequence, WfBranchProcessBlockingType blockingType) { WfTransferParams tp = new WfTransferParams(process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity); tp.Assignees.Add((IUser)OguObjectSettings.GetConfig().Objects["requestor"].Object); tp.BranchTransferParams.Add(new WfBranchProcessTransferParams( CreateConsignTemplate(sequence, blockingType), new IUser[] { (IUser)OguObjectSettings.GetConfig().Objects["approver1"].Object, (IUser)OguObjectSettings.GetConfig().Objects["approver2"].Object })); return(tp); }
public void SimpleProcessRuntimeSerializeTest() { IWfProcess process = WfProcessTestCommon.StartupSimpleProcess(); if (process.Activities != null) { foreach (var activity in process.Activities) { if (activity.Descriptor != process.Descriptor.InitialActivity) { Assert.IsTrue(activity.Status == WfActivityStatus.NotRunning); WfTransferParams transferPara = new WfTransferParams(activity.Descriptor); process.MoveTo(transferPara); } } } XElementFormatter formatter = new XElementFormatter(); XElement root = formatter.Serialize(process); Console.WriteLine(root.ToString()); IWfProcess clonedProcess = (IWfProcess)formatter.Deserialize(root); Assert.IsTrue(clonedProcess.Status == WfProcessStatus.Completed); for (int i = 0; i < clonedProcess.Activities.Count; i++) { Assert.IsTrue(clonedProcess.Activities[i].Status == WfActivityStatus.Completed); if (i < clonedProcess.Activities.Count - 1) { Assert.AreEqual(clonedProcess.Activities[i].Descriptor.ToTransitions[0], clonedProcess.Activities[i + 1].Descriptor.FromTransitions[0]); } } Assert.IsNotNull(clonedProcess.Descriptor.Activities[process.Descriptor.InitialActivity.Key], "验证反序列化后集合字典的完整性"); XElement reRoot = formatter.Serialize(clonedProcess); //31000是否允许被撤回默认值不同true false Assert.AreEqual(root.ToString(), reRoot.ToString()); IWfProcess reClonedProcess = (IWfProcess)formatter.Deserialize(reRoot); Assert.AreEqual(clonedProcess.ToString(), reClonedProcess.ToString()); }
public static void AreSame(this WfClientTransferParams expected, WfTransferParams actual) { if (expected != null && actual != null) { expected.Operator.AreSame(actual.Operator); expected.Assignees.AreSame(actual.Assignees); expected.BranchTransferParams.AreSame(actual.BranchTransferParams); } else { Assert.AreEqual(expected, actual); } }
public void MoveToWithBranchProcessesExecutorTest() { IWfProcessDescriptor processDesp = WfProcessTestCommon.CreateSimpleProcessDescriptorWithBranchTemplate(); IWfProcess process = WfProcessTestCommon.StartupProcess(processDesp); IWfActivityDescriptor normalActivity = processDesp.InitialActivity.ToTransitions[0].ToActivity; WfTransferParams transferParams0 = new WfTransferParams(normalActivity); //初始化后,流转到有分支流程的活动 process.MoveTo(transferParams0); Assert.AreEqual(normalActivity.BranchProcessTemplates.Count, process.CurrentActivity.BranchProcessGroups.Count); }
public void AllApprovalProcessScheduleRootTest() { IWfProcessDescriptor processDesp = WfProcessTestCommon.CreateSimpleProcessDescriptorWithBranchTemplate(); IWfProcess process = WfProcessTestCommon.StartupProcess(processDesp); IWfActivityDescriptor normalActivity = processDesp.InitialActivity.ToTransitions[0].ToActivity; WfTransferParams transferParams0 = new WfTransferParams(normalActivity); //初始化后,流转到有分支流程的活动 process.MoveTo(transferParams0); Assert.AreEqual(process.ID, normalActivity.Instance.BranchProcessGroups[0].Branches[0].ScheduleRootProcess.ID); Assert.AreEqual(normalActivity.Instance.ID, normalActivity.Instance.BranchProcessGroups[0].Branches[0].InitialActivity.ScheduleRootActivity.ID); }
public void AllApprovalProcessScheduleRootTest() { IWfProcessDescriptor processDesp = WfProcessTestCommon.CreateSimpleProcessDescriptorWithBranchTemplate(); IWfProcess process = WfProcessTestCommon.StartupProcess(processDesp); IWfActivityDescriptor normalActivity = processDesp.InitialActivity.ToTransitions[0].ToActivity; WfTransferParams transferParams0 = new WfTransferParams(normalActivity); //初始化后,流转到有分支流程的活动 process.MoveTo(transferParams0); Assert.AreEqual(process.ID, normalActivity.Instance.BranchProcessGroups[0].Branches[0].ScheduleRootProcess.ID); Assert.AreEqual(normalActivity.Instance.ID, normalActivity.Instance.BranchProcessGroups[0].Branches[0].InitialActivity.ScheduleRootActivity.ID); }
public void WfActivityAssigneesResourceTest() { IWfProcess process = GetProcessInstanceWithAssigneesResource(); Assert.AreEqual(process.CurrentActivity.Assignees[0].User.ID, process.CurrentActivity.Descriptor.Resources.ToUsers()[0].ID); IWfActivityDescriptor actDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfTransferParams par = new WfTransferParams(actDesp); par.Assignees.Add(actDesp.FromTransitions[0].FromActivity.Resources.ToUsers()[0]); process.MoveTo(par); WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); Assert.IsTrue(ProcessTestHelper.ExistsActivityUserTasks(process.CurrentActivity.ID, TaskStatus.Ban)); }
/// <summary> /// 通过Executor流转到默认的下一个活动,但是不保存 /// </summary> /// <param name="process"></param> /// <returns></returns> public static IWfActivity MoveToNextDefaultActivityWithNoPersistExecutor(IWfProcess process) { IWfTransitionDescriptor transition = process.CurrentActivity.Descriptor.ToTransitions.GetAllCanTransitTransitions(true).FirstOrDefault(); Assert.IsNotNull(transition, string.Format("活动{0}没有能够使用的出线", process.CurrentActivity.Descriptor.Key)); WfTransferParams transferParams = new WfTransferParams(transition.ToActivity); transferParams.FromTransitionDescriptor = transition; WfMoveToExecutor executor = new WfMoveToExecutor(process.CurrentActivity, process.CurrentActivity, transferParams); executor.ExecuteNotPersist(); return(process.CurrentActivity); }
public static WfClientProcess Moveto(WfClientMovetoParameters parameters) { IWfProcess process = WfRuntime.GetProcessByProcessID(parameters.ProcessID); IWfActivity activity = process.CurrentActivity; if (activity == null || activity.Assignees == null)// || !activity.Assignees.Contains(UserHelper.UserId)) { return(null); } WfTransferParams transferParams = WfTransferParams.FromNextDefaultActivity(process); UserTaskCollection userTask = new UserTaskCollection(); WfMoveToExecutor executor = new WfMoveToExecutor(activity, activity, transferParams); //调整待办的url和标题 executor.PrepareMoveToTasks += (dataContext, tasks) => { PrepareUserTasks(tasks, null, null, transferParams.NextActivityDescriptor.Name); }; GenericOpinion serverOpinion = PrepareOpinion(process.CurrentActivity, parameters.CurrentOpinion, DeluxeIdentity.CurrentUser); if (activity.Descriptor.ActivityType == WfActivityType.InitialActivity) { serverOpinion.OpinionType = "提交"; } else if (activity.Descriptor.ActivityType == WfActivityType.CompletedActivity) { serverOpinion.OpinionType = string.Empty; } else if (activity.Descriptor.ActivityType == WfActivityType.NormalActivity) { serverOpinion.OpinionType = "同意"; if (serverOpinion.Content.IsNullOrEmpty()) { serverOpinion.Content = "同意"; } } executor.PrepareApplicationData += dataContext => GenericOpinionAdapter.Instance.Update(serverOpinion); return(GetClientProcess(executor.Execute())); }
public void WithdrawAndReplayRunProcessActivityWithBranchProcess() { IWfProcess process = GetProcessInstance(false); string fromActivityId = process.CurrentActivity.ID; process.Withdraw(process.Activities[0], true); //撤回 WfRuntime.PersistWorkflows(); CheckOperationAndStatusAfterWithdrawProcess(process.ID, fromActivityId, process.Activities[0].ID); process = WfRuntime.GetProcessByProcessID(process.ID); WfTransferParams pa = ProcessTestHelper.GetInstanceOfWfTransferParams(process, WfBranchProcessExecuteSequence.Parallel, WfBranchProcessBlockingType.WaitAllBranchProcessesComplete); process.MoveTo(pa); Assert.AreEqual(4, process.CurrentActivity.BranchProcessGroups[0].Branches.Count, "当前节点的分支流程应为撤回前与当前的,即4"); }
protected void Page_Load(object sender, EventArgs e) { Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); var desc = LoadProcessDescriptor("cb80a469-82bd-8061-42ce-681f775570ef"); AddNodeToDescription(desc, 3); var node3Desc = desc.Activities[3].Descriptor; WfTransferParams param = new WfTransferParams(node3Desc); desc.MoveTo(param); var info = WorkflowInfo.ProcessAdapter(desc); this.viewer1.InitializeValue = info; desc = LoadProcessDescriptor("cb80a469-82bd-8061-42ce-681f775570ef"); AddNodeToDescription(desc, 5); node3Desc = desc.Activities[3].Descriptor; param = new WfTransferParams(node3Desc); desc.MoveTo(param); info = WorkflowInfo.ProcessAdapter(desc); viewer2.InitializeValue = info; //this.viewer1.BranchProcessListUrl = "./ModalDialog/WfBranchProcessList.aspx"; }
protected override void OnModifyWorkflow(WfExecutorDataContext dataContext) { this.TargetActivity.Process.Committed = true; IWfProcess process = this.TargetActivity.Process; IWfActivity activity = process.ElapsedActivities.FindActivityByDescriptorKey(TargetActivity.Descriptor.Key); activity.NullCheck("targetActivity"); WfRuntime.ProcessContext.BeginChangeActivityChangingContext(); try { WfRuntime.ProcessContext.ActivityChangingContext.CreatorInstanceID = process.CurrentActivity.ID; process.CurrentActivity.CopyMainStreamActivities(process.CurrentActivity, TargetActivity, process.CurrentActivity.Descriptor.GetAssociatedActivity().Instance, null, WfControlOperationType.Return); if (process.CurrentActivity.Descriptor.ToTransitions.Count == 0) throw new ApplicationException(string.Format("退回时,不能找到当前活动({0})的出线", process.CurrentActivity.Descriptor.Key)); IWfActivityDescriptor nextActivityDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfTransferParams tp = new WfTransferParams(nextActivityDesp); IWfActivity act = process.Activities.FindActivityByDescriptorKey(nextActivityDesp.Key); if (act.Assignees.Count > 0) tp.Assignees.CopyFrom(act.Assignees); else tp.Assignees.CopyFrom(activity.Assignees); process.MoveTo(tp); } finally { WfRuntime.ProcessContext.RestoreChangeActivityChangingContext(); } }
public void TwoScheduleProcessRootTest() { IWfProcessDescriptor processDesp = WfProcessTestCommon.CreateSimpleProcessDescriptorWithBranchTemplate(); ((WfProcessDescriptor)processDesp).ProcessType = WfProcessType.Schedule; IWfProcess process = WfProcessTestCommon.StartupProcess(processDesp); IWfActivityDescriptor normalActivity = processDesp.InitialActivity.ToTransitions[0].ToActivity; WfTransferParams transferParams0 = new WfTransferParams(normalActivity); //初始化后,流转到有分支流程的活动 process.MoveTo(transferParams0); normalActivity.Instance.BranchProcessGroups.ForEach(g => g.Branches.ForEach(p => ((WfProcessDescriptor)p.Descriptor).ProcessType = WfProcessType.Schedule)); Assert.AreEqual(normalActivity.Instance.BranchProcessGroups[0].Branches[0].ID, normalActivity.Instance.BranchProcessGroups[0].Branches[0].ScheduleRootProcess.ID); Assert.AreEqual(normalActivity.Instance.BranchProcessGroups[0].Branches[0].InitialActivity.ID, normalActivity.Instance.BranchProcessGroups[0].Branches[0].InitialActivity.ScheduleRootActivity.ID); }
public void ProcessTaskAccomplishedOfResourceTest() { IUser user = (IUser)OguObjectSettings.GetConfig().Objects["approver1"].Object; IWfProcess process = WfProcessTestCommon.StartupProcessWithAssignee(); ((WfProcess)process).ResourceID = UuidHelper.NewUuidString(); IWfActivityDescriptor actDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfTransferParams tp = new WfTransferParams(actDesp); tp.Assignees.Add(user); process.MoveTo(tp); //设置 同一人 WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); actDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; tp = ProcessTestHelper.GetInstanceOfWfTransferParams(actDesp, OguObject.approver2); process.MoveTo(tp); WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); actDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; tp = new WfTransferParams(actDesp); tp.Assignees.Add(user); //设置 同一人 WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); actDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; tp = ProcessTestHelper.GetInstanceOfWfTransferParams(actDesp, OguObject.approver2); process.MoveTo(tp); WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); Assert.AreEqual(1, ProcessTestHelper.GetResourceUserTasksAccomplished(process.ResourceID, user.ID), "如果ResourceID相同,且流转过同一个人两次,他只会剩下一个已办"); }
public void RepeatNoticeOfDelegation() { //sourceUser: "******"; destinationUser:"******" WfDelegation delegation = WfDelegationTest.PrepareDelegation(); WfDelegationAdapter.Instance.Update(delegation); try { IWfProcess process = WfProcessTestCommon.StartupProcessWithAssignee(); IWfActivityDescriptor actDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfTransferParams tp = new WfTransferParams(actDesp); IUser user1 = (IUser)OguObjectSettings.GetConfig().Objects["approver1"].Object; IUser user2 = (IUser)OguObjectSettings.GetConfig().Objects["requestor"].Object; tp.Assignees.Add(user1); tp.Assignees.Add(user2); process.MoveTo(tp); WfRuntime.PersistWorkflows(); Assert.AreEqual(3, process.CurrentActivity.Assignees.Count); int count = Find(process.CurrentActivity.Assignees, user2.ID); Assert.AreEqual(2, count); //存在相同的人员,只是Assignees类型不同(委派与非委派) process = WfRuntime.GetProcessByProcessID(process.ID); Assert.IsTrue(ProcessTestHelper.ExistsActivityUserTasks(process.CurrentActivity.ID, TaskStatus.Ban)); Assert.AreEqual(2, ProcessTestHelper.GetActivityUserTasks(process.CurrentActivity.ID, TaskStatus.Ban).Count);//两个人2条待办。如果委托后有重复没排除,会是3条 } finally { WfDelegationAdapter.Instance.Delete(delegation); //清理委托 } }
protected override void OnModifyWorkflow(WfExecutorDataContext dataContext) { this.TargetActivity.Process.Committed = true; IWfProcess process = TargetActivity.Process; WfRuntime.ProcessContext.BeginChangeActivityChangingContext(); try { WfRuntime.ProcessContext.ActivityChangingContext.CreatorInstanceID = TargetActivity.ID; WfRuntime.ProcessContext.ActivityChangingContext.AssociatedActivityKey = TargetActivity.Descriptor.AssociatedActivityKey.IsNotEmpty() ? TargetActivity.Descriptor.AssociatedActivityKey : TargetActivity.Descriptor.Key; //string activityKey = process.Descriptor.FindNotUsedActivityKey(); //WfActivityDescriptor actDesp = new WfActivityDescriptor(activityKey); //actDesp.Name = "会签"; var toReturnTrans = process.CurrentActivity.Descriptor.ToTransitions.FindAll(t => t.IsBackward == true); WfActivityDescriptor actDesp = process.CurrentActivity.Descriptor.Clone() as WfActivityDescriptor; actDesp.ActivityType = WfActivityType.NormalActivity; actDesp.Properties.SetValue("AutoMoveAfterPending", false); actDesp.ClonedKey = process.CurrentActivity.Descriptor.Key; actDesp.BranchProcessTemplates.Clear(); process.CurrentActivity.Append(actDesp); foreach (WfTransitionDescriptor t in toReturnTrans) { WfTransitionDescriptor trans = t.Clone() as WfTransitionDescriptor; if (t.FromActivityKey == t.ToActivityKey) trans.JoinActivity(actDesp, actDesp); else trans.JoinActivity(actDesp, t.ToActivity); actDesp.ToTransitions.Add(trans); } //添加子流程 WfTransferParams tp = new WfTransferParams(actDesp); tp.Assignees.CopyFrom(Assignees); tp.BranchTransferParams.Add(new WfBranchProcessTransferParams( WfTemplateBuilder.CreateDefaultConsignTemplate( "WfConsignProcessTemplateDescriptorKey", this.Sequence, this.BlockingType, this.ConsignUsers))); if (this.CirculateUsers.Count<IUser>() > 0) { tp.BranchTransferParams.Add(new WfBranchProcessTransferParams( WfTemplateBuilder.CreateDefaultCirculationTemplate( "WfCirculationProcessTemplateDescriptorKey", this.CirculateUsers))); } WfRuntime.ProcessContext.AfterStartupBranchProcess += new WfAfterStartupBranchProcessHandler(WfActivityRelativeExecutorBase.AfterStartupBranchProcess); process.MoveTo(tp); } finally { WfRuntime.ProcessContext.RestoreChangeActivityChangingContext(); } }
public void ActivitiesTrackTest() { IWfProcess process = WfProcessTestCommon.StartupSimpleProcess(); for (int i = 0; i < process.Activities.Count; i++) { if (process.Activities[i].Descriptor != process.Descriptor.InitialActivity) { WfTransferParams transferPara = new WfTransferParams(process.Activities[i].Descriptor); process.MoveTo(transferPara); } } int k = process.ElapsedActivities.Count; string[] keys = new string[] { "Initial", "NormalActivity", "Completed" }; for (int j = 0; j < process.ElapsedActivities.Count; j++) { Assert.AreEqual(process.ElapsedActivities[j].Descriptor.Key, process.ElapsedActivities[j].Descriptor.Key, keys[j]); } }
/// <summary> /// 流转到默认的下一个活动 /// </summary> /// <param name="process"></param> /// <returns></returns> public static IWfActivity MoveToNextDefaultActivity(IWfProcess process) { IWfTransitionDescriptor transition = process.CurrentActivity.Descriptor.ToTransitions.GetAllCanTransitTransitions(true).FirstOrDefault(); Assert.IsNotNull(transition, string.Format("活动{0}没有能够使用的出线", process.CurrentActivity.Descriptor.Key)); WfTransferParams transferParams = new WfTransferParams(transition.ToActivity); process.MoveTo(transferParams); return process.CurrentActivity; }
/// <summary> /// 流转时,设置目标节点的状态,包括启动分支流程等操作。 /// </summary> /// <param name="nextActivity"></param> /// <param name="transferParams"></param> private void ExecuteNextActivityActionsAndSetStatus(WfActivityBase nextActivity, WfTransferParams transferParams) { PrepareActivityAssigneesFromTransferParams(nextActivity, transferParams); CalculateActivityCompleteTime(nextActivity.Descriptor); FillAclInContext(this.SearchID, nextActivity); //启动分支流程 transferParams.BranchTransferParams.ForEach(b => nextActivity.StartupBranchProcesses(b)); if (transferParams.BranchTransferParams.Count == 0 && WfRuntime.ProcessContext.TargetActivityCanMoveTo && nextActivity.Descriptor.IsConditionActivity == false) { nextActivity.Status = WfActivityStatus.Running; } else { nextActivity.Status = WfActivityStatus.Pending; } WfRuntime.ProcessContext.ResetContextByProcess(this); RegisterAndPrepareActions(nextActivity.EnterActions); if (nextActivity.Descriptor.ActivityType == WfActivityType.CompletedActivity) { nextActivity.Status = WfActivityStatus.Completed; this.Status = WfProcessStatus.Completed; this.EndTime = DateTime.Now; WfRuntime.ProcessContext.ResetContextByProcess(this); this._ElapsedActivities.Add(nextActivity); RegisterAndPrepareActions(nextActivity.LeaveActions); RegisterAndPrepareActions(this.CompleteProcessActions); ExecuteNextSerialProcess(this.EntryInfo); } SyncUrlsInAssigneesFromTasks(nextActivity, WfRuntime.ProcessContext.MoveToUserTasks); this.ProcessPendingActivity(); }
/// <summary> /// 执行group中下一个需要顺序执行的流程 /// </summary> /// <param name="group"></param> private static void ExecuteNextSerialProcess(IWfBranchProcessGroup group) { if (group != null && group.ProcessTemplate.ExecuteSequence == WfBranchProcessExecuteSequence.Serial) { IWfProcess process = group.Branches.Find(p => p.Status == WfProcessStatus.NotRunning); if (process != null && process.BranchStartupParams != null) { WfTransferParams transferParams = new WfTransferParams(process.Descriptor.InitialActivity); transferParams.Assignees.CopyFrom(process.BranchStartupParams.Assignees); process.MoveTo(transferParams); } } }
protected override void OnModifyWorkflow(WfExecutorDataContext dataContext) { (this.Assignees.Count > 0).FalseThrow<WfRuntimeException>("加签的用户数必须大于零"); IWfProcess process = this.TargetActivity.Process; WfRuntime.ProcessContext.BeginChangeActivityChangingContext(); try { WfRuntime.ProcessContext.ActivityChangingContext.CreatorInstanceID = OperatorActivity.ID; string clonedKey = TargetActivity.Descriptor.AssociatedActivityKey.IsNotEmpty() ? TargetActivity.Descriptor.AssociatedActivityKey : TargetActivity.Descriptor.Key; IWfActivity templateAct = process.Activities.FindActivityByDescriptorKey(clonedKey); //不是仅添加审批人时 if ((this.AddApproverMode & WfAddApproverMode.AreAssociatedActivities) != WfAddApproverMode.OnlyAddApprover) WfRuntime.ProcessContext.ActivityChangingContext.AssociatedActivityKey = clonedKey; //生成加签的点 WfActivityDescriptor addActDesp = CreateAddApproverActivityDescriptor(templateAct.Descriptor); IWfActivity addedActivity = this.TargetActivity.Append(addActDesp); //当仅添加审批人时 if ((this.AddApproverMode & WfAddApproverMode.AreAssociatedActivities) == WfAddApproverMode.OnlyAddApprover) { //将指派人直接赋值给办理人 addedActivity.Candidates.CopyFrom(this.Assignees); IWfActivityDescriptor mainStreamActDesp = templateAct.GetMainStreamActivityDescriptor(); if (mainStreamActDesp != null) { WfActivityDescriptor newMSActDesp = CreateAddApproverActivityDescriptor(mainStreamActDesp); newMSActDesp.Resources.Clear(); foreach (IUser user in this.Assignees.ToUsers()) newMSActDesp.Resources.Add(new WfUserResourceDescriptor(user)); mainStreamActDesp.Append(newMSActDesp); } } //不是仅添加审批人时 if ((this.AddApproverMode & WfAddApproverMode.AppendCurrentActivity) != WfAddApproverMode.OnlyAddApprover) { //Clone当前的点,在加签点后生成再添加当前活动 IWfActivity foundActivity = process.Activities.FindActivityByDescriptorKey(clonedKey); WfActivityDescriptor clonedCurrentActDesp = ((WfActivityDescriptor)foundActivity.Descriptor).Clone() as WfActivityDescriptor; //加签按照加签活动模板进行属性设置 WfActivityBase.ResetPropertiesByDefinedName(addActDesp, "DefaultAddApproverActivityTemplate"); //if (foundActivity.Descriptor.ActivityType == WfActivityType.InitialActivity) // WfActivityBase.ResetPropertiesByDefinedName(clonedCurrentActDesp, "DefaultAddApproverActivityTemplate"); clonedCurrentActDesp.AssociatedActivityKey = WfRuntime.ProcessContext.ActivityChangingContext.AssociatedActivityKey; clonedCurrentActDesp.ClonedKey = this.TargetActivity.Descriptor.Key; clonedCurrentActDesp.IsReturnSkipped = true; IWfActivity clonedActivity = addActDesp.Instance.Append(clonedCurrentActDesp); clonedActivity.Candidates.CopyFrom(foundActivity.Candidates); } WfTransferParams tp = new WfTransferParams(addActDesp); tp.Assignees.CopyFrom(this.Assignees); process.MoveTo(tp); } finally { WfRuntime.ProcessContext.RestoreChangeActivityChangingContext(); } }
public void MainStreamActivitiesWithConsignActivity() { IWfProcess process = WfProcessTestCommon.StartupProcessWithAssignee(); //会签 string currentActivityID = process.CurrentActivity.ID; WfActivityDescriptor actDesp = AddActivity(process); WfTransferParams tp = new WfTransferParams(actDesp); IUser user = (IUser)OguObjectSettings.GetConfig().Objects[OguObject.requestor.ToString()].Object; tp.Assignees.Add(user); tp.BranchTransferParams.Add(new WfBranchProcessTransferParams( ProcessTestHelper.CreateConsignTemplate(WfBranchProcessExecuteSequence.Parallel, WfBranchProcessBlockingType.WaitAllBranchProcessesComplete), new IUser[] {(IUser)OguObjectSettings.GetConfig().Objects["approver1"].Object, (IUser)OguObjectSettings.GetConfig().Objects["approver2"].Object})); process.MoveTo(tp); WfMainStreamActivityDescriptorCollection coll = process.Descriptor.GetMainStreamActivities(); Assert.AreEqual(process.Activities.Count - 1, coll.Count); }
public void MoveToWithBranchProcessesExecutorTest() { IWfProcessDescriptor processDesp = WfProcessTestCommon.CreateSimpleProcessDescriptorWithBranchTemplate(); IWfProcess process = WfProcessTestCommon.StartupProcess(processDesp); IWfActivityDescriptor normalActivity = processDesp.InitialActivity.ToTransitions[0].ToActivity; WfTransferParams transferParams0 = new WfTransferParams(normalActivity); //初始化后,流转到有分支流程的活动 process.MoveTo(transferParams0); Assert.AreEqual(normalActivity.BranchProcessTemplates.Count, process.CurrentActivity.BranchProcessGroups.Count); }
public void WfActivityAssigneesResourceTest() { IWfProcess process = GetProcessInstanceWithAssigneesResource(); Assert.AreEqual(process.CurrentActivity.Assignees[0].User.ID, process.CurrentActivity.Descriptor.Resources.ToUsers()[0].ID); IWfActivityDescriptor actDesp = process.CurrentActivity.Descriptor.ToTransitions[0].ToActivity; WfTransferParams par = new WfTransferParams(actDesp); par.Assignees.Add(actDesp.FromTransitions[0].FromActivity.Resources.ToUsers()[0]); process.MoveTo(par); WfRuntime.PersistWorkflows(); process = WfRuntime.GetProcessByProcessID(process.ID); Assert.IsTrue(ProcessTestHelper.ExistsActivityUserTasks(process.CurrentActivity.ID, TaskStatus.Ban)); }
public void ProcessWithMatrix() { try { var wfDescriptor = WfProcessDescriptorManager.GetDescriptor("workflowmatrixtest"); WfProcessStartupParams startParam = new WfProcessStartupParams(); startParam.ProcessDescriptor = wfDescriptor; var processInstance = WfRuntime.StartWorkflow(startParam); processInstance.ApplicationRuntimeParameters.Add("支付方式", "网银"); processInstance.ApplicationRuntimeParameters.Add("成本中心", "成1"); processInstance.ApplicationRuntimeParameters.Add("费用类型", "差旅费"); processInstance.ApplicationRuntimeParameters.Add("金额", "100"); processInstance.ApplicationRuntimeParameters.Add("部门", "商务部"); WfTransferParams transferParams = new WfTransferParams(processInstance.Descriptor.Activities["N2"]); var currentAct = processInstance.MoveTo(transferParams); currentAct.Candidates.ForEach(p => { Console.WriteLine(p.User.DisplayName); }); } catch { } }
public void SimpleProcessPersistRepeatTest() { IWfProcess process = WfProcessTestCommon.StartupSimpleProcessWithAssignee(); //process.DefaultTaskTitle = "测试保存的流程"; WfRuntime.PersistWorkflows(); IWfProcess loadedProcess = WfRuntime.GetProcessByProcessID(process.ID); IWfProcess loadedProcess2 = WfRuntime.GetProcessByActivityID(process.Activities[0].ID); Assert.AreEqual(loadedProcess, loadedProcess2); int n = loadedProcess.Activities.Count; for (int i = 0; i < n; i++) { if (loadedProcess.Activities[i].Descriptor != loadedProcess.Descriptor.InitialActivity) { WfTransferParams transferPara = new WfTransferParams(loadedProcess.Activities[i].Descriptor); loadedProcess.MoveTo(transferPara); WfRuntime.PersistWorkflows(); } loadedProcess = WfRuntime.GetProcessByActivityID(loadedProcess.Activities[i].ID); } IWfProcess OnceAgainloadedProcess = WfRuntime.GetProcessByProcessID(process.ID); Assert.AreEqual(OnceAgainloadedProcess.ID, process.ID); }
public void TransitionConditionTest() { TestContext.Properties["Amount"] = 7500; WfRuntime.ProcessContext.EvaluateTransitionCondition += new Expression.CalculateUserFunction(ProcessContext_EvaluateTransition); IWfProcess process = WfProcessTestCommon.StartupSimpleProcessDescriptorWithTransitionCondition(); WfTransferParams transferParams = new WfTransferParams(process.Descriptor.InitialActivity.ToTransitions[0].ToActivity); process.MoveTo(transferParams); WfTransitionDescriptorCollection transitions = process.CurrentActivity.Descriptor.ToTransitions.GetAllCanTransitTransitions(); Assert.AreEqual(1, transitions.Count); Console.WriteLine(((IWfForwardTransitionDescriptor)transitions[0]).Condition.Expression); Assert.AreEqual("Amount >= 5000", ((IWfForwardTransitionDescriptor)transitions[0]).Condition.Expression); }
/// <summary> /// 结束流程 /// </summary> /// <param name="completeAllBranchProcesses">是否结束分支流程</param> public void CompleteProcess(bool completeAllBranchProcesses) { (this.Status == WfProcessStatus.Running).FalseThrow<WfRuntimeException>("流程{0}不在运行状态,只有正在运行的流程才能直接结束。"); if (completeAllBranchProcesses) this.Activities.ForEach(act => act.CompleteBranchProcesses(completeAllBranchProcesses)); WfTransferParams transferParams = new WfTransferParams(this.CompletedActivity.Descriptor); MoveTo(transferParams); }
public void WithdrawAndReplayRunProcessActivity() { IWfProcess process = GetProcessInstance(false); string fromActivityId = process.CurrentActivity.ID; string branchProcessID1 = process.CurrentActivity.BranchProcessGroups[0].Branches[0].ID; string branchProcessID2 = process.CurrentActivity.BranchProcessGroups[0].Branches[1].ID; process.Withdraw(process.Activities[0], true); WfRuntime.PersistWorkflows(); CheckOperationAndStatusAfterWithdrawProcess(process.ID, fromActivityId, process.Activities[0].ID); IWfProcess proc = WfRuntime.GetProcessByProcessID(process.ID); WfTransferParams pa = new WfTransferParams(proc.Activities[1].Descriptor); proc.MoveTo(pa); Assert.AreEqual(2, proc.CurrentActivity.BranchProcessGroups[0].Branches.Count, "当前节点的分支流程应为在撤回前的个数,即2"); Assert.AreEqual(branchProcessID1, proc.CurrentActivity.BranchProcessGroups[0].Branches[0].ID); Assert.AreEqual(branchProcessID2, proc.CurrentActivity.BranchProcessGroups[0].Branches[1].ID); }
/// <summary> /// 准备下一步的Assignees /// </summary> /// <param name="nextActivity"></param> /// <param name="transferParams"></param> private void PrepareActivityAssigneesFromTransferParams(WfActivityBase nextActivity, WfTransferParams transferParams) { nextActivity.Assignees.Clear(); nextActivity.Assignees.CopyFrom(transferParams.Assignees); nextActivity.Assignees.CopyFrom(GetDelegatedAssignees(transferParams.Assignees, this)); nextActivity.Assignees.Distinct((a1, a2) => string.Compare(a1.User.ID, a2.User.ID, true) == 0 && a1.AssigneeType == a2.AssigneeType); }
private static IWfProcess GetProcessInstance(bool movetoCompletedActivity) { IWfProcess process = GetProcessInstanceWithBranchProcessRunning(WfBranchProcessExecuteSequence.Parallel, WfBranchProcessBlockingType.WaitAnyoneBranchProcessComplete); process = WfRuntime.GetProcessByProcessID(process.ID); if (movetoCompletedActivity) { //使第二个节点可以正常流转 ProcessTestHelper.CompleteActivityBranchProcessesByBlockingType(process.CurrentActivity, WfBranchProcessBlockingType.WaitAnyoneBranchProcessComplete); ProcessTestHelper.ProcessPendingActivity(process.CurrentActivity.ID); IWfProcess wfProc = WfRuntime.GetProcessByProcessID(process.ID); Assert.AreEqual(WfActivityStatus.Running, wfProc.Activities[1].Status); Assert.IsTrue(ProcessTestHelper.ExistsActivityUserTasks(wfProc.CurrentActivity.ID, TaskStatus.Ban)); Assert.AreEqual(WfProcessStatus.Completed, wfProc.CurrentActivity.BranchProcessGroups[0].Branches[0].Status); Assert.AreEqual(WfProcessStatus.Running, wfProc.CurrentActivity.BranchProcessGroups[0].Branches[1].Status); //初始节点已完成,从第二个节点开始 for (int i = 2; i < process.Activities.Count; i++) { if (process.Activities[i].Descriptor.ActivityType != WfActivityType.CompletedActivity) { process = WfRuntime.GetProcessByProcessID(process.ID); WfTransferParams transferPara = new WfTransferParams(process.Activities[i].Descriptor); transferPara.Assignees.Add((IUser)OguObjectSettings.GetConfig().Objects["requestor"].Object); process.MoveTo(transferPara); WfRuntime.PersistWorkflows(); } } } process = WfRuntime.GetProcessByProcessID(process.ID); return process; }
public void MainStreamActivitiesWithDynamicActivity() { IWfProcess process = WfProcessTestCommon.StartupProcessWithAssignee(); string currentActivityID = process.CurrentActivity.ID; //新增点 WfActivityDescriptor actDesp = AddActivity(process); WfTransferParams tp = new WfTransferParams(actDesp); IUser user = (IUser)OguObjectSettings.GetConfig().Objects[OguObject.requestor.ToString()].Object; tp.Assignees.Add(user); process.MoveTo(tp); ProcessTestHelper.MoveToAndSaveNextActivity(OguObject.approver2, process); WfMainStreamActivityDescriptorCollection coll = process.Descriptor.GetMainStreamActivities(); Assert.AreEqual(6, coll.Count, "动态创建的点不在主流程里头"); Assert.AreEqual(7, process.Activities.Count, "流程中有7个点,其中一个是动态创建的点"); Assert.AreEqual(process.Activities[0].Descriptor.ToTransitions[0].ToActivity.Key, actDesp.Key); Assert.AreEqual(actDesp.ToTransitions[0].ToActivity.Key, process.CurrentActivity.Descriptor.Key); }
/// <summary> /// 通过Executor流转到默认的下一个活动,但是不保存 /// </summary> /// <param name="process"></param> /// <returns></returns> public static IWfActivity MoveToNextDefaultActivityWithNoPersistExecutor(IWfProcess process) { IWfTransitionDescriptor transition = process.CurrentActivity.Descriptor.ToTransitions.GetAllCanTransitTransitions(true).FirstOrDefault(); Assert.IsNotNull(transition, string.Format("活动{0}没有能够使用的出线", process.CurrentActivity.Descriptor.Key)); WfTransferParams transferParams = new WfTransferParams(transition.ToActivity); transferParams.FromTransitionDescriptor = transition; WfMoveToExecutor executor = new WfMoveToExecutor(process.CurrentActivity, process.CurrentActivity, transferParams); executor.ExecuteNotPersist(); return process.CurrentActivity; }