public void SingleStepWithDrawTest() { IUser user = (IUser)OguObjectSettings.GetConfig().Objects["approver2"].Object; string procResourceId = GetStartWorkflowResourceID(user); WfProcessCollection processes; for (int i = 0; i < 2; i++) { processes = WfRuntime.GetProcessByResourceID(procResourceId); MoveToExecutor(processes[0]); } processes = WfRuntime.GetProcessByResourceID(procResourceId); IWfProcess process = processes[0]; Assert.AreEqual(2, process.ElapsedActivities.Count); WfWithdrawExecutor exec = new WfWithdrawExecutor(process.CurrentActivity, process.CurrentActivity); exec.Execute(); processes = WfRuntime.GetProcessByResourceID(procResourceId); MoveToExecutor(processes[0]); processes = WfRuntime.GetProcessByResourceID(procResourceId); WfActivityCollection coll = processes[0].ElapsedActivities; Assert.AreEqual(coll[coll.Count - 1].Descriptor.ToTransitions[0].ToActivity.Key, processes[0].CurrentActivity.Descriptor.Key); //撤回的单步是指业务上的一步,如在上一步动态添加的两个点,则当前就会撤回到动态添加两个点的活动 }
protected override void OnModifyWorkflow(WfExecutorDataContext dataContext) { int targetActivityIndex = FindTargetActivityIndex(this.OriginalActivity); (targetActivityIndex >= 0).FalseThrow<WfRuntimeException>("活动(ID={0}, Key={1})不能撤回", this.OriginalActivity.ID, this.OriginalActivity.Descriptor.Key); WfActivityCollection clonedElapsedActivities = new WfActivityCollection(); IWfProcess process = this.OriginalActivity.Process; clonedElapsedActivities.CopyFrom(process.ElapsedActivities); dataContext["OriginalActivityID"] = process.CurrentActivity.ID; //将流程实例活动点的状态设置为未运行 this.OriginalActivity.Process.Withdraw(clonedElapsedActivities[targetActivityIndex], this.CancelAllBranchProcesses); //删除掉动态添加的点 for (int i = targetActivityIndex; i < clonedElapsedActivities.Count; i++) { IWfActivity act = clonedElapsedActivities[i]; process.Activities.FindAll(a => a.CreatorInstanceID == act.ID).ForEach(a => a.Delete()); } if (this.CancelProcess) process.CancelProcess(this.CancelAllBranchProcesses); }
/// <summary> /// /// </summary> /// <param name="info"></param> /// <param name="context"></param> protected WfProcess(SerializationInfo info, StreamingContext context) { this._ID = info.GetString("ID"); this._ResourceID = info.GetString("ResourceID"); this._Activities = (WfActivityCollection)info.GetValue("Activities", typeof(WfActivityCollection)); this._Context = (WfProcessContext)info.GetValue("Context", typeof(WfProcessContext)); this._Status = (WfProcessStatus)info.GetValue("Status", typeof(WfProcessStatus)); this._StartTime = info.GetDateTime("StartTime"); this._EndTime = info.GetDateTime("EndTime"); this._Creator = (IUser)info.GetValue("Creator", typeof(IUser)); this._OwnerDepartment = (IOrganization)info.GetValue("OwnerDepartment", typeof(IOrganization)); this._EntryInfo = (WfBranchProcessInfo)info.GetValue("EntryInfo", typeof(WfBranchProcessInfo)); this._LoadingType = (DataLoadingType)info.GetValue("LoadingType", typeof(DataLoadingType)); WfProcessContextCache.Instance[this._ID] = this; }
private WfProcessCollection GetDeletedProcesses(WfActivityCollection deletedActivities) { WfProcessCollection deletedProcesses = new WfProcessCollection(); foreach (IWfActivity activity in deletedActivities) { if (activity is IWfAnchorActivity) { foreach (IWfOperation operation in ((IWfAnchorActivity)activity).Operations) { foreach (WfBranchProcessInfo branchProcessInfo in operation.Branches) { deletedProcesses.Add(branchProcessInfo.Process); WfProcessCollection deletedSubProcesses = GetDeletedProcesses(branchProcessInfo.Process.Activities); foreach (IWfProcess subProcess in deletedSubProcesses) deletedProcesses.Add(subProcess); } } } } return deletedProcesses; }
private WfActivityCollection DoWithdraw(IWfActivity destinationActivity) { WfActivityCollection deletedActivities = new WfActivityCollection(); while (string.Compare(this.CurrentActivity.ID, destinationActivity.ID, true) != 0) { deletedActivities.Add(this.LastActivity); Activities.Remove(this.LastActivity); } return deletedActivities; }