protected sealed override void OnActivityChangeRemove(ActivityExecutionContext executionContext, Activity removedActivity) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } if (removedActivity == null) { throw new ArgumentNullException("removedActivity"); } ListenActivity activity = executionContext.Activity as ListenActivity; if (((activity.ExecutionStatus == ActivityExecutionStatus.Executing) && (activity.ActivityState != null)) && !activity.IsListenTrigerred) { EventDrivenActivity activity2 = removedActivity as EventDrivenActivity; for (int i = 0; i < activity.ActivityState.Count; i++) { ListenEventActivitySubscriber parentEventHandler = activity.ActivityState[i]; if (parentEventHandler.eventDrivenActivity.QualifiedName.Equals(activity2.QualifiedName)) { activity2.EventActivity.Unsubscribe(executionContext, parentEventHandler); activity.ActivityState.RemoveAt(i); return; } } } else if (this.IsListenTrigerred && (removedActivity.ExecutionStatus == ActivityExecutionStatus.Closed)) { this.activeBranchRemoved = true; } }
protected override sealed void OnActivityChangeRemove(ActivityExecutionContext executionContext, Activity removedActivity) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } if (removedActivity == null) { throw new ArgumentNullException("removedActivity"); } ListenActivity listen = executionContext.Activity as ListenActivity; if (listen.ExecutionStatus == ActivityExecutionStatus.Executing && listen.ActivityState != null && !listen.IsListenTrigerred) { EventDrivenActivity eda = removedActivity as EventDrivenActivity; for (int i = 0; i < listen.ActivityState.Count; ++i) { ListenEventActivitySubscriber listenEventSubscriber = listen.ActivityState[i]; if (listenEventSubscriber.eventDrivenActivity.QualifiedName.Equals(eda.QualifiedName)) { eda.EventActivity.Unsubscribe(executionContext, listenEventSubscriber); listen.ActivityState.RemoveAt(i); return; } } } else if (this.IsListenTrigerred && removedActivity.ExecutionStatus == ActivityExecutionStatus.Closed) { activeBranchRemoved = true; } }
protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } if (this.ActivityState == null) { return(ActivityExecutionStatus.Closed); } try { if (this.IsListenTrigerred) { //We need to cancel the active running branch for (int i = 0; i < this.EnabledActivities.Count; ++i) { EventDrivenActivity eventDriven = this.EnabledActivities[i] as EventDrivenActivity; if (eventDriven.ExecutionStatus == ActivityExecutionStatus.Executing) { executionContext.CancelActivity(eventDriven); return(ActivityExecutionStatus.Canceling); } //If the branch is faulting let it close. else if (eventDriven.ExecutionStatus == ActivityExecutionStatus.Faulting) { return(ActivityExecutionStatus.Canceling); } } } else { //Everything is passive. Lets unsubscribe all and close. for (int i = 0; i < this.ActivityState.Count; ++i) { EventDrivenActivity eventDrivenChild = this.EnabledActivities[i] as EventDrivenActivity; ListenEventActivitySubscriber eventActivitySubscriber = this.ActivityState[i]; eventDrivenChild.EventActivity.Unsubscribe(executionContext, eventActivitySubscriber); } } } finally { // We null out ActivityState in the finally block to ensure that if // eventDrivenChild.EventActivity.Unsubscribe above throws then the // Cancel method does not get called repeatedly. this.ActivityState = null; } return(ActivityExecutionStatus.Closed); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } List <ListenEventActivitySubscriber> list = new List <ListenEventActivitySubscriber>(); this.ActivityState = list; for (int i = 0; i < base.EnabledActivities.Count; i++) { EventDrivenActivity eventDriven = base.EnabledActivities[i] as EventDrivenActivity; ListenEventActivitySubscriber parentEventHandler = new ListenEventActivitySubscriber(eventDriven); eventDriven.EventActivity.Subscribe(executionContext, parentEventHandler); list.Add(parentEventHandler); } return(ActivityExecutionStatus.Executing); }
protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } if (this.ActivityState != null) { try { if (this.IsListenTrigerred) { for (int i = 0; i < base.EnabledActivities.Count; i++) { EventDrivenActivity activity = base.EnabledActivities[i] as EventDrivenActivity; if (activity.ExecutionStatus == ActivityExecutionStatus.Executing) { executionContext.CancelActivity(activity); return(ActivityExecutionStatus.Canceling); } if (activity.ExecutionStatus == ActivityExecutionStatus.Faulting) { return(ActivityExecutionStatus.Canceling); } } } else { for (int j = 0; j < this.ActivityState.Count; j++) { EventDrivenActivity activity2 = base.EnabledActivities[j] as EventDrivenActivity; ListenEventActivitySubscriber parentEventHandler = this.ActivityState[j]; activity2.EventActivity.Unsubscribe(executionContext, parentEventHandler); } } } finally { this.ActivityState = null; } } return(ActivityExecutionStatus.Closed); }
protected sealed override void OnActivityChangeAdd(ActivityExecutionContext executionContext, Activity addedActivity) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } if (addedActivity == null) { throw new ArgumentNullException("addedActivity"); } ListenActivity activity = executionContext.Activity as ListenActivity; if (((activity.ExecutionStatus == ActivityExecutionStatus.Executing) && (activity.ActivityState != null)) && !activity.IsListenTrigerred) { EventDrivenActivity eventDriven = addedActivity as EventDrivenActivity; ListenEventActivitySubscriber parentEventHandler = new ListenEventActivitySubscriber(eventDriven); eventDriven.EventActivity.Subscribe(executionContext, parentEventHandler); activity.ActivityState.Insert(activity.EnabledActivities.IndexOf(addedActivity), parentEventHandler); } }
void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs e) { if (sender == null) { throw new ArgumentNullException("sender"); } if (e == null) { throw new ArgumentNullException("e"); } ActivityExecutionContext context = sender as ActivityExecutionContext; if (context == null) { throw new ArgumentException(SR.Error_SenderMustBeActivityExecutionContext, "sender"); } ListenActivity parentActivity = context.Activity as ListenActivity; if (!parentActivity.IsListenTrigerred && parentActivity.ExecutionStatus != ActivityExecutionStatus.Canceling && parentActivity.ExecutionStatus != ActivityExecutionStatus.Closed) { //Check whether it is still live in tree. if (!parentActivity.EnabledActivities.Contains(eventDrivenActivity))//Activity is dynamically removed. { return; } parentActivity.IsListenTrigerred = true; for (int i = 0; i < parentActivity.EnabledActivities.Count; ++i) { EventDrivenActivity eventDriven = parentActivity.EnabledActivities[i] as EventDrivenActivity; ListenEventActivitySubscriber eventSubscriber = parentActivity.ActivityState[i]; eventDriven.EventActivity.Unsubscribe(context, eventSubscriber); } eventDrivenActivity.RegisterForStatusChange(Activity.ClosedEvent, parentActivity); context.ExecuteActivity(eventDrivenActivity); } }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } List <ListenEventActivitySubscriber> eventActivitySubscribers = new List <ListenEventActivitySubscriber>(); this.ActivityState = eventActivitySubscribers; //Subscribe to all EventDriven Children. for (int i = 0; i < this.EnabledActivities.Count; ++i) { EventDrivenActivity eventDriven = this.EnabledActivities[i] as EventDrivenActivity; ListenEventActivitySubscriber eventActivitySubscriber = new ListenEventActivitySubscriber(eventDriven); eventDriven.EventActivity.Subscribe(executionContext, eventActivitySubscriber); eventActivitySubscribers.Add(eventActivitySubscriber); } return(ActivityExecutionStatus.Executing); }
protected override sealed void OnActivityChangeAdd(ActivityExecutionContext executionContext, Activity addedActivity) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } if (addedActivity == null) { throw new ArgumentNullException("addedActivity"); } Debug.Assert(addedActivity is EventDrivenActivity, "Listen only contains EventDriven activities"); ListenActivity listen = executionContext.Activity as ListenActivity; if (listen.ExecutionStatus == ActivityExecutionStatus.Executing && listen.ActivityState != null && !listen.IsListenTrigerred) { EventDrivenActivity eda = addedActivity as EventDrivenActivity; ListenEventActivitySubscriber eventActivitySubscriber = new ListenEventActivitySubscriber(eda); eda.EventActivity.Subscribe(executionContext, eventActivitySubscriber); listen.ActivityState.Insert(listen.EnabledActivities.IndexOf(addedActivity), eventActivitySubscriber); } }