/// <summary> /// Gets called when the parent model element of the current model element is about to change /// </summary> /// <param name="oldParent">The old parent model element</param> /// <param name="newParent">The new parent model element</param> protected override void OnParentChanging(IModelElement newParent, IModelElement oldParent) { IBranchAction oldBranchAction_AbstractBranchTransition = ModelHelper.CastAs <IBranchAction>(oldParent); IBranchAction newBranchAction_AbstractBranchTransition = ModelHelper.CastAs <IBranchAction>(newParent); ValueChangedEventArgs e = new ValueChangedEventArgs(oldBranchAction_AbstractBranchTransition, newBranchAction_AbstractBranchTransition); this.OnBranchAction_AbstractBranchTransitionChanging(e); this.OnPropertyChanging("BranchAction_AbstractBranchTransition", e, _branchAction_AbstractBranchTransitionReference); }
/// <summary> /// Executes the specified activity. /// </summary> /// <param name="activity">The activity.</param> protected override void ExecuteActivity(Activity activity) { activity.OnInitialize(this); //执行当前动作 activity.OnExecute(this); //如果工作流动作完成,那么移动到下一步状态 if (activity.ExecutionStatus == ActivityExecutionStatus.Closed) { //添加当前动作到动作列表中 executedActivities.Add(activity); if (activity is IBranchAction) { //分支动作,需要获取分支执行后选定的状态 IBranchAction branch = (IBranchAction)activity; MoveOn(branch.GetSelectedState()); } else { //顺序动作,从动作针对的事件名称中获取状态 ApprovalEvent currentEvent = CurrentState.GetEventByName(activity.EventName); MoveOn(currentEvent.NextStateNames[0]); } } //保存 Save(); if (this.stateRecordNames.Count > 0) { WorkflowRuntime.Current.OnWorkflowExecuted(new StateChangedEventArgs(this, this.stateRecordNames[stateRecordNames.Count - 1], stateName)); } //如果是子流程的执行完成,那么还有判断其父流程是否也已经执行完毕,如果执行完毕,那么设置其父流程的下一步状态 if (this.CurrentStatus == WorkflowExecutionStatus.Closed && parentId != null && parentId != Guid.Empty) { StateMachineWorkflowInstance parentInstance = (StateMachineWorkflowInstance)WorkflowRuntime.Current.GetInstance(parentId); parentInstance.OnChildFinished(this); } else if (this.CurrentStatus == WorkflowExecutionStatus.Aborted) { WorkflowRuntime.Current.OnWorkflowTerminated(new StateChangedEventArgs(this, this.stateRecordNames[stateRecordNames.Count - 1], stateName)); } if (IsEnd()) { WorkflowRuntime.Current.OnWorkflowCompleted(new StateChangedEventArgs(this, this.stateRecordNames[stateRecordNames.Count - 1], stateName)); } }
/// <summary> /// Gets called when the parent model element of the current model element changes /// </summary> /// <param name="oldParent">The old parent model element</param> /// <param name="newParent">The new parent model element</param> protected override void OnParentChanged(IModelElement newParent, IModelElement oldParent) { IBranchAction oldBranchAction_AbstractBranchTransition = ModelHelper.CastAs <IBranchAction>(oldParent); IBranchAction newBranchAction_AbstractBranchTransition = ModelHelper.CastAs <IBranchAction>(newParent); if ((oldBranchAction_AbstractBranchTransition != null)) { oldBranchAction_AbstractBranchTransition.Branches_Branch.Remove(this); } if ((newBranchAction_AbstractBranchTransition != null)) { newBranchAction_AbstractBranchTransition.Branches_Branch.Add(this); } ValueChangedEventArgs e = new ValueChangedEventArgs(oldBranchAction_AbstractBranchTransition, newBranchAction_AbstractBranchTransition); this.OnBranchAction_AbstractBranchTransitionChanged(e); this.OnPropertyChanged("BranchAction_AbstractBranchTransition", e, _branchAction_AbstractBranchTransitionReference); base.OnParentChanged(newParent, oldParent); }
/// <summary> /// Adds the given element to the collection /// </summary> /// <param name="item">The item to add</param> public override void Add(IModelElement item) { if ((this._parent.BranchAction_AbstractBranchTransition == null)) { IBranchAction branchAction_AbstractBranchTransitionCasted = item.As <IBranchAction>(); if ((branchAction_AbstractBranchTransitionCasted != null)) { this._parent.BranchAction_AbstractBranchTransition = branchAction_AbstractBranchTransitionCasted; return; } } if ((this._parent.BranchBehaviour_BranchTransition == null)) { IResourceDemandingBehaviour branchBehaviour_BranchTransitionCasted = item.As <IResourceDemandingBehaviour>(); if ((branchBehaviour_BranchTransitionCasted != null)) { this._parent.BranchBehaviour_BranchTransition = branchBehaviour_BranchTransitionCasted; return; } } }