Example #1
0
        protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            Activity bodyActivity = this.BodyActivity;

            System.Workflow.Activities.EventHandlersActivity eventHandlersActivity = this.EventHandlersActivity;
            if ((bodyActivity == null) && (eventHandlersActivity == null))
            {
                return(ActivityExecutionStatus.Closed);
            }
            bool flag = false;

            if ((bodyActivity != null) && (bodyActivity.ExecutionStatus == ActivityExecutionStatus.Executing))
            {
                executionContext.CancelActivity(bodyActivity);
                flag = true;
            }
            if ((eventHandlersActivity != null) && (eventHandlersActivity.ExecutionStatus == ActivityExecutionStatus.Executing))
            {
                executionContext.CancelActivity(eventHandlersActivity);
                flag = true;
            }
            if ((!flag && ((bodyActivity == null) || ((bodyActivity.ExecutionStatus != ActivityExecutionStatus.Faulting) && (bodyActivity.ExecutionStatus != ActivityExecutionStatus.Canceling)))) && ((eventHandlersActivity == null) || ((eventHandlersActivity.ExecutionStatus != ActivityExecutionStatus.Faulting) && (eventHandlersActivity.ExecutionStatus != ActivityExecutionStatus.Canceling))))
            {
                return(ActivityExecutionStatus.Closed);
            }
            return(base.ExecutionStatus);
        }
Example #2
0
        /// <summary>
        /// Called by the workflow runtime to cancel execution of an activity that is currently executing.
        /// </summary>
        /// <param name="executionContext">The <see cref="T:System.Workflow.ComponentModel.ActivityExecutionContext"/> containing the instance to cancel.</param>
        /// <returns>
        /// The status at the end of the operation, which determines whether the activity remains in the canceling state, or transitions to the closed state.
        /// </returns>
        protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }

            bool flag = true;

            for (int i = 0; i < base.EnabledActivities.Count; i++)
            {
                Activity activity = base.EnabledActivities[i];
                if (activity.ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    executionContext.CancelActivity(activity);
                    flag = false;
                }
                else if ((activity.ExecutionStatus == ActivityExecutionStatus.Canceling) || (activity.ExecutionStatus == ActivityExecutionStatus.Faulting))
                {
                    flag = false;
                }
            }

            if (!flag)
            {
                return(ActivityExecutionStatus.Canceling);
            }

            return(ActivityExecutionStatus.Closed);
        }
Example #3
0
        protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
        {
            bool flag = true;

            for (int i = 0; i < base.EnabledActivities.Count; i++)
            {
                Activity activity = base.EnabledActivities[i];
                if (activity.ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    flag = false;
                    executionContext.CancelActivity(activity);
                    break;
                }
                if ((activity.ExecutionStatus == ActivityExecutionStatus.Canceling) || (activity.ExecutionStatus == ActivityExecutionStatus.Faulting))
                {
                    flag = false;
                    break;
                }
            }
            if (!flag)
            {
                return(ActivityExecutionStatus.Canceling);
            }
            return(ActivityExecutionStatus.Closed);
        }
Example #4
0
        protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
        {
            if (null == executionContext)
            {
                throw new ArgumentNullException("executionContext");
            }

            bool cancelled = true;

            // Check all children to ensure that they are cancelled
            for (int childNum = 0; childNum < this.EnabledActivities.Count; childNum++)
            {
                Activity child = this.EnabledActivities[childNum];

                if (child.ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    executionContext.CancelActivity(child);
                    cancelled = false;
                }
                else if ((child.ExecutionStatus == ActivityExecutionStatus.Canceling) || (child.ExecutionStatus == ActivityExecutionStatus.Faulting))
                {
                    cancelled = false;
                }
            }

            return(cancelled ? ActivityExecutionStatus.Canceling : ActivityExecutionStatus.Closed);
        }
 protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
 {
     if (executionContext == null)
     {
         throw new ArgumentNullException("executionContext");
     }
     for (int i = base.EnabledActivities.Count - 1; i >= 0; i--)
     {
         Activity activity = base.EnabledActivities[i];
         if (activity.ExecutionStatus == ActivityExecutionStatus.Executing)
         {
             executionContext.CancelActivity(activity);
             return(ActivityExecutionStatus.Canceling);
         }
         if ((activity.ExecutionStatus == ActivityExecutionStatus.Canceling) || (activity.ExecutionStatus == ActivityExecutionStatus.Faulting))
         {
             return(ActivityExecutionStatus.Canceling);
         }
         if (activity.ExecutionStatus == ActivityExecutionStatus.Closed)
         {
             base.RemoveProperty(ActiveChildQualifiedNameProperty);
             return(ActivityExecutionStatus.Closed);
         }
     }
     return(ActivityExecutionStatus.Closed);
 }
        protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }

            bool canCloseNow = true;

            for (int i = 0; i < this.EnabledActivities.Count; ++i)
            {
                Activity childActivity = this.EnabledActivities[i];

                if (childActivity.ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    executionContext.CancelActivity(childActivity);
                    canCloseNow = false;
                }
                else if (childActivity.ExecutionStatus == ActivityExecutionStatus.Canceling || childActivity.ExecutionStatus == ActivityExecutionStatus.Faulting)
                {
                    canCloseNow = false;
                }
            }

            return(canCloseNow ? ActivityExecutionStatus.Closed : ActivityExecutionStatus.Canceling);
        }
Example #7
0
        private bool TryCancelChild(ActivityExecutionContext outerProvider, ChildExecutionStateInfo childStateInfo)
        {
            bool flag = false;
            ActivityExecutionContextManager executionContextManager = outerProvider.ExecutionContextManager;
            ActivityExecutionContext        executionContext        = this.GetExecutionContext(executionContextManager, childStateInfo.RunId);

            if (executionContext != null)
            {
                switch (executionContext.Activity.ExecutionStatus)
                {
                case ActivityExecutionStatus.Executing:
                    executionContext.CancelActivity(executionContext.Activity);
                    return(true);

                case ActivityExecutionStatus.Canceling:
                case ActivityExecutionStatus.Faulting:
                    return(true);

                case ActivityExecutionStatus.Closed:
                case ActivityExecutionStatus.Compensating:
                    return(flag);
                }
                return(flag);
            }
            if ((base.ExecutionStatus != ActivityExecutionStatus.Executing) && (childStateInfo.Status == ChildRunStatus.PendingExecute))
            {
                childStateInfo.Status = ChildRunStatus.Completed;
            }
            return(flag);
        }
Example #8
0
        /// <summary>
        /// Cancel the activity. Loop through all enabled activities, and for any that are currently
        /// executing ask them to cancel.
        /// </summary>
        /// <param name="executionContext"></param>
        /// <returns>The status of the activity</returns>
        protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
        {
            if (null == executionContext)
            {
                throw new ArgumentNullException("executionContext");
            }

            bool completed = true;

            for (int pos = 0; pos < base.EnabledActivities.Count; pos++)
            {
                Activity act = base.EnabledActivities[pos];
                if (act.ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    executionContext.CancelActivity(act);
                    completed = false;
                }
                else if ((act.ExecutionStatus == ActivityExecutionStatus.Canceling) || (act.ExecutionStatus == ActivityExecutionStatus.Faulting))
                {
                    completed = false;
                }
            }
            if (!completed)
            {
                return(ActivityExecutionStatus.Canceling);
            }
            else
            {
                return(ActivityExecutionStatus.Closed);
            }
        }
        protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }

            if (this.EnabledActivities.Count == 0)
            {
                return(ActivityExecutionStatus.Closed);
            }

            Activity childActivity = this.EnabledActivities[0];
            ActivityExecutionContextManager contextManager = executionContext.ExecutionContextManager;
            ActivityExecutionContext        childContext   = contextManager.GetExecutionContext(childActivity);

            if (childContext != null)
            {
                if (childContext.Activity.ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    childContext.CancelActivity(childContext.Activity);
                }

                return(ActivityExecutionStatus.Canceling);
            }
            return(ActivityExecutionStatus.Closed);
        }
Example #10
0
        /// <summary>
        ///	This override function cancels the execution of the child activity if cancel is called
        /// on the ForEach activity itself.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        protected override ActivityExecutionStatus Cancel(ActivityExecutionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("activity execution context is null.");
            }

            // If there is no child activity, the ForEach activity is closed.
            if (this.EnabledActivities.Count == 0)
            {
                return(ActivityExecutionStatus.Closed);
            }

            Activity childActivity = this.EnabledActivities[0];
            ActivityExecutionContext childContext =
                context.ExecutionContextManager.GetExecutionContext(childActivity);

            if (childContext != null)
            {
                if (childContext.Activity.ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    // Cancel the executing child activity.
                    childContext.CancelActivity(childContext.Activity);
                }

                return(ActivityExecutionStatus.Canceling);
            }
            return(ActivityExecutionStatus.Closed);
        }
Example #11
0
        public static ActivityExecutionStatus Cancel(CompositeActivity activity, ActivityExecutionContext executionContext)
        {
            for (int i = (activity.EnabledActivities.Count - 1); i >= 0; i--)
            {
                Activity childActivity = activity.EnabledActivities[i];

                if (childActivity.ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    executionContext.CancelActivity(childActivity);
                    return activity.ExecutionStatus;
                }

                if (childActivity.ExecutionStatus == ActivityExecutionStatus.Canceling ||
                    childActivity.ExecutionStatus == ActivityExecutionStatus.Faulting)
                {
                    return activity.ExecutionStatus;
                }

                if (childActivity.ExecutionStatus == ActivityExecutionStatus.Closed)
                {
                    activity.RemoveProperty(ActiveChildQualifiedNameProperty);
                    return ActivityExecutionStatus.Closed;
                }
            }
            return ActivityExecutionStatus.Closed;
        }
Example #12
0
        internal bool Cleanup(ConditionedActivityGroup cag, ActivityExecutionContext context)
        {
            // the completion condition has fired, or we are canceling
            // either way, we want to cleanup
            ConditionedActivityGroupStateInfo state = cag.CAGState;

            state.Completed = true;

            // cancel any children currently running
            bool childrenActive = false;
            Dictionary <string, CAGChildStats> childrenStats = state.ChildrenStats;

            foreach (Activity act in cag.EnabledActivities)
            {
                // reset any Pending Execution for all child activity
                if (childrenStats[act.QualifiedName].State == CAGChildState.Pending)
                {
                    childrenStats[act.QualifiedName].State = CAGChildState.Idle;
                }

                // find the run-time activity
                ActivityExecutionContext childContext = GetChildExecutionContext(context, act, false);
                if (childContext != null)
                {
                    // child must be running somewhere
                    Activity activity = GetRuntimeInitializedActivity(context, act);
                    switch (activity.ExecutionStatus)
                    {
                    case ActivityExecutionStatus.Executing:
                        // schedule cancellation on child
                        childContext.CancelActivity(activity);
                        childrenActive = true;
                        break;

                    case ActivityExecutionStatus.Canceling:
                    case ActivityExecutionStatus.Faulting:
                        childrenActive = true;
                        break;

                    case ActivityExecutionStatus.Closed:
                        CleanupChildAtClosure(context, activity);
                        break;

                    default:
                        // unhook our handler
                        // others will be removed when we get the complete/cancel notification
                        act.UnregisterForStatusChange(Activity.ClosedEvent, this);
                        break;
                    }
                }
            }

            // if the CAG is quiet, we are all done
            if (!childrenActive)
            {
                context.CloseActivity();
            }
            return(!childrenActive);
        }
Example #13
0
        protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }

            if (this.ActivityState == null)
            {
                return(ActivityExecutionStatus.Closed);
            }

            bool scopeCompleted = this.IsScopeCompleted;
            bool canCloseNow    = true;

            for (int i = 0; i < this.EnabledActivities.Count; ++i)
            {
                EventDrivenActivity childActivity = this.EnabledActivities[i] as EventDrivenActivity;
                EventHandlerEventActivitySubscriber eventActivitySubscriber = this.ActivityState[i] as EventHandlerEventActivitySubscriber;

                eventActivitySubscriber.PendingExecutionCount = 0;

                ActivityExecutionContextManager contextManager = executionContext.ExecutionContextManager;
                ActivityExecutionContext        childContext   = contextManager.GetExecutionContext(childActivity);

                if (childContext != null)
                {
                    switch (childContext.Activity.ExecutionStatus)
                    {
                    case ActivityExecutionStatus.Canceling:
                    case ActivityExecutionStatus.Faulting:
                        canCloseNow = false;
                        break;

                    case ActivityExecutionStatus.Executing:
                        childContext.CancelActivity(childContext.Activity);
                        canCloseNow = false;
                        break;
                    }
                }

                if (!scopeCompleted) //UnSubscribe from event.
                {
                    childActivity.EventActivity.Unsubscribe(executionContext, eventActivitySubscriber);
                }
            }

            if (canCloseNow)
            {
                this.ActivityState = null;
                return(ActivityExecutionStatus.Closed);
            }
            else
            {
                return(this.ExecutionStatus);
            }
        }
Example #14
0
        protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }

            Activity bodyActivity = this.BodyActivity;
            EventHandlersActivity eventHandlers = this.EventHandlersActivity;

            if (bodyActivity == null && eventHandlers == null)
            {
                return(ActivityExecutionStatus.Closed);
            }

            bool cancelScheduled = false;

            // check the status of body
            if (bodyActivity != null && bodyActivity.ExecutionStatus == ActivityExecutionStatus.Executing)
            {
                executionContext.CancelActivity(bodyActivity);
                cancelScheduled = true;
            }
            //Check the status of EventHandlers
            if (eventHandlers != null && eventHandlers.ExecutionStatus == ActivityExecutionStatus.Executing)
            {
                executionContext.CancelActivity(eventHandlers);
                cancelScheduled = true;
            }

            if (cancelScheduled ||
                (bodyActivity != null && (bodyActivity.ExecutionStatus == ActivityExecutionStatus.Faulting ||
                                          bodyActivity.ExecutionStatus == ActivityExecutionStatus.Canceling)) ||
                (eventHandlers != null && (eventHandlers.ExecutionStatus == ActivityExecutionStatus.Faulting ||
                                           eventHandlers.ExecutionStatus == ActivityExecutionStatus.Canceling))
                )
            {
                return(this.ExecutionStatus);
            }
            return(ActivityExecutionStatus.Closed);
        }
        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);
        }
 public ActivityExecutionStatus Cancel()
 {
     using (ActivityExecutionContext context = new ActivityExecutionContext(this.rootActivity, true))
     {
         if (this.rootActivity.ExecutionStatus == ActivityExecutionStatus.Executing)
         {
             context.CancelActivity(this.rootActivity);
         }
     }
     this.scheduler.Run();
     return(this.TranslateExecutionStatus());
 }
Example #17
0
        /// <summary>
        /// Processes the closed even for any activities.
        /// </summary>
        /// <param name="executionContext">The execution context.</param>
        /// <param name="closedActivity">The closed activity.</param>
        /// <returns></returns>
        private ActivityExecutionStatus ProcessClosedEvenForAnyActivities(ActivityExecutionContext executionContext, Activity closedActivity)
        {
            for (int i = 0; i < base.EnabledActivities.Count; i++)
            {
                Activity activity = base.EnabledActivities[i];

                if (base.EnabledActivities[i].ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    executionContext.CancelActivity(activity);
                }
            }

            return(ActivityExecutionStatus.Closed);
        }
        internal bool Cleanup(ConditionedActivityGroup cag, ActivityExecutionContext context)
        {
            ConditionedActivityGroupStateInfo cAGState = cag.CAGState;

            cAGState.Completed = true;
            bool flag = false;
            Dictionary <string, CAGChildStats> childrenStats = cAGState.ChildrenStats;

            foreach (Activity activity in cag.EnabledActivities)
            {
                if (childrenStats[activity.QualifiedName].State == CAGChildState.Pending)
                {
                    childrenStats[activity.QualifiedName].State = CAGChildState.Idle;
                }
                ActivityExecutionContext context2 = GetChildExecutionContext(context, activity, false);
                if (context2 != null)
                {
                    Activity runtimeInitializedActivity = this.GetRuntimeInitializedActivity(context, activity);
                    switch (runtimeInitializedActivity.ExecutionStatus)
                    {
                    case ActivityExecutionStatus.Executing:
                    {
                        context2.CancelActivity(runtimeInitializedActivity);
                        flag = true;
                        continue;
                    }

                    case ActivityExecutionStatus.Canceling:
                    case ActivityExecutionStatus.Faulting:
                    {
                        flag = true;
                        continue;
                    }

                    case ActivityExecutionStatus.Closed:
                    {
                        this.CleanupChildAtClosure(context, runtimeInitializedActivity);
                        continue;
                    }
                    }
                    activity.UnregisterForStatusChange(Activity.ClosedEvent, this);
                }
            }
            if (!flag)
            {
                context.CloseActivity();
            }
            return(!flag);
        }
Example #19
0
        protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            if (this.ActivityState == null)
            {
                return(ActivityExecutionStatus.Closed);
            }
            bool isScopeCompleted = this.IsScopeCompleted;
            bool flag2            = true;

            for (int i = 0; i < base.EnabledActivities.Count; i++)
            {
                EventDrivenActivity activity = base.EnabledActivities[i] as EventDrivenActivity;
                EventHandlerEventActivitySubscriber parentEventHandler = this.ActivityState[i];
                parentEventHandler.PendingExecutionCount = 0;
                ActivityExecutionContext context = executionContext.ExecutionContextManager.GetExecutionContext(activity);
                if (context != null)
                {
                    switch (context.Activity.ExecutionStatus)
                    {
                    case ActivityExecutionStatus.Executing:
                        context.CancelActivity(context.Activity);
                        flag2 = false;
                        break;

                    case ActivityExecutionStatus.Canceling:
                    case ActivityExecutionStatus.Faulting:
                        flag2 = false;
                        break;
                    }
                }
                if (!isScopeCompleted)
                {
                    activity.EventActivity.Unsubscribe(executionContext, parentEventHandler);
                }
            }
            if (flag2)
            {
                this.ActivityState = null;
                return(ActivityExecutionStatus.Closed);
            }
            return(base.ExecutionStatus);
        }
Example #20
0
 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);
 }
Example #21
0
        bool TryCancelChild(ActivityExecutionContext outerProvider, ChildExecutionStateInfo childStateInfo)
        {
            // schedule cancellation of the child in the inner execution context
            bool fScheduledCancel = false;

            // returns true iff scheduled cancel on one execution of the template
            // false if execution already closed

            // get the execution context for this run
            ActivityExecutionContextManager contextManager = outerProvider.ExecutionContextManager;
            ActivityExecutionContext        innerProvider  = GetExecutionContext(contextManager, childStateInfo.RunId);

            if (innerProvider != null)
            {
                switch (innerProvider.Activity.ExecutionStatus)
                {
                case ActivityExecutionStatus.Executing:
                    // schedule cancellation on child
                    innerProvider.CancelActivity(innerProvider.Activity);
                    fScheduledCancel = true;
                    break;

                case ActivityExecutionStatus.Canceling:
                case ActivityExecutionStatus.Faulting:
                    fScheduledCancel = true;
                    break;

                default:
                    // do nothing
                    break;
                }
            }
            else
            {
                //Finish the run if it is pending for execution.
                if (this.ExecutionStatus != ActivityExecutionStatus.Executing && childStateInfo.Status == ChildRunStatus.PendingExecute)
                {
                    childStateInfo.Status = ChildRunStatus.Completed;
                }
            }
            return(fScheduledCancel);
        }
Example #22
0
        protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
        {
            ActivityExecutionStatus __status = ActivityExecutionStatus.Closed;

            foreach (IfElseBranchActivityCustom branch in this.EnabledActivities)
            {
                if (branch.ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    __status = ActivityExecutionStatus.Canceling;
                    executionContext.CancelActivity(branch);
                    break;
                }
                if ((branch.ExecutionStatus == ActivityExecutionStatus.Canceling) || (branch.ExecutionStatus == ActivityExecutionStatus.Faulting))
                {
                    __status = ActivityExecutionStatus.Canceling;
                    break;
                }
            }
            return(__status);
        }
        protected override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
        {
            bool canCloseNow = true;

            for (int i = 0; i < this.EnabledActivities.Count; ++i)
            {
                Activity childBranch = this.EnabledActivities[i];

                if (childBranch.ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    canCloseNow = false;
                    executionContext.CancelActivity(childBranch);
                    break;
                }
                else if (childBranch.ExecutionStatus == ActivityExecutionStatus.Canceling || childBranch.ExecutionStatus == ActivityExecutionStatus.Faulting)
                {
                    canCloseNow = false;
                    break;
                }
            }
            return(canCloseNow ? ActivityExecutionStatus.Closed : ActivityExecutionStatus.Canceling);
        }
        public ActivityExecutionStatus Cancel()
        {
            using (ActivityExecutionContext activityExecutionContext = new ActivityExecutionContext(this.rootActivity, true))
            {

                if (this.rootActivity.ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    activityExecutionContext.CancelActivity(this.rootActivity);
                }
            }
            scheduler.Run();
            return TranslateExecutionStatus();
        }