public override bool Run(IWorkflowCoreRuntime workflowCoreRuntime)
        {
            // get state reader
            Activity contextActivity = workflowCoreRuntime.GetContextActivityForId(this.ContextId);
            Activity activity        = contextActivity.GetActivityByName(this.activityName);

            using (workflowCoreRuntime.SetCurrentActivity(activity))
            {
                using (ActivityExecutionContext activityExecutionContext = new ActivityExecutionContext(activity))
                {
                    ActivityExecutor activityExecutor = ActivityExecutors.GetActivityExecutor(activity);
                    switch (this.operation)
                    {
                    case ActivityOperationType.Execute:
                        if (activity.ExecutionStatus == ActivityExecutionStatus.Executing)
                        {
                            try
                            {
                                workflowCoreRuntime.RaiseActivityExecuting(activity);

                                ActivityExecutionStatus newStatus = activityExecutor.Execute(activity, activityExecutionContext);
                                if (newStatus == ActivityExecutionStatus.Closed)
                                {
                                    activityExecutionContext.CloseActivity();
                                }
                                else if (newStatus != ActivityExecutionStatus.Executing)
                                {
                                    throw new InvalidOperationException(SR.GetString(SR.InvalidExecutionStatus, activity.QualifiedName, newStatus.ToString(), ActivityExecutionStatus.Executing.ToString()));
                                }
                            }
                            catch (Exception e)
                            {
                                System.Workflow.Runtime.WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Execute of Activity {0} threw {1}", activity.QualifiedName, e.ToString());
                                throw;
                            }
                        }
                        break;

                    case ActivityOperationType.Cancel:
                        if (activity.ExecutionStatus == ActivityExecutionStatus.Canceling)
                        {
                            try
                            {
                                ActivityExecutionStatus newStatus = activityExecutor.Cancel(activity, activityExecutionContext);
                                if (newStatus == ActivityExecutionStatus.Closed)
                                {
                                    activityExecutionContext.CloseActivity();
                                }
                                else if (newStatus != ActivityExecutionStatus.Canceling)
                                {
                                    throw new InvalidOperationException(SR.GetString(SR.InvalidExecutionStatus, activity.QualifiedName, newStatus.ToString(), ActivityExecutionStatus.Canceling.ToString()));
                                }
                            }
                            catch (Exception e)
                            {
                                System.Workflow.Runtime.WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Cancel of Activity {0} threw {1}", activity.QualifiedName, e.ToString());
                                throw;
                            }
                        }
                        break;

                    case ActivityOperationType.Compensate:
                        if (activity.ExecutionStatus == ActivityExecutionStatus.Compensating)
                        {
                            try
                            {
                                ActivityExecutionStatus newStatus = activityExecutor.Compensate(activity, activityExecutionContext);
                                if (newStatus == ActivityExecutionStatus.Closed)
                                {
                                    activityExecutionContext.CloseActivity();
                                }
                                else if (newStatus != ActivityExecutionStatus.Compensating)
                                {
                                    throw new InvalidOperationException(SR.GetString(SR.InvalidExecutionStatus, activity.QualifiedName, newStatus.ToString(), ActivityExecutionStatus.Compensating.ToString()));
                                }
                            }
                            catch (Exception e)
                            {
                                System.Workflow.Runtime.WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Compensate of Activity {0} threw {1}", activity.QualifiedName, e.ToString());
                                throw;
                            }
                        }
                        break;

                    case ActivityOperationType.HandleFault:
                        if (activity.ExecutionStatus == ActivityExecutionStatus.Faulting)
                        {
                            try
                            {
                                ActivityExecutionStatus newStatus = activityExecutor.HandleFault(activity, activityExecutionContext, this.exceptionToDeliver);
                                if (newStatus == ActivityExecutionStatus.Closed)
                                {
                                    activityExecutionContext.CloseActivity();
                                }
                                else if (newStatus != ActivityExecutionStatus.Faulting)
                                {
                                    throw new InvalidOperationException(SR.GetString(SR.InvalidExecutionStatus, activity.QualifiedName, newStatus.ToString(), ActivityExecutionStatus.Faulting.ToString()));
                                }
                            }
                            catch (Exception e)
                            {
                                System.Workflow.Runtime.WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Compensate of Activity {0} threw {1}", activity.QualifiedName, e.ToString());
                                throw;
                            }
                        }
                        break;
                    }
                }
            }
            return(true);
        }
        public override bool Run(IWorkflowCoreRuntime workflowCoreRuntime)
        {
            Activity activityByName = workflowCoreRuntime.GetContextActivityForId(base.ContextId).GetActivityByName(this.activityName);

            using (workflowCoreRuntime.SetCurrentActivity(activityByName))
            {
                using (ActivityExecutionContext context = new ActivityExecutionContext(activityByName))
                {
                    ActivityExecutor activityExecutor = ActivityExecutors.GetActivityExecutor(activityByName);
                    switch (this.operation)
                    {
                    case ActivityOperationType.Execute:
                        if (activityByName.ExecutionStatus != ActivityExecutionStatus.Executing)
                        {
                            goto Label_0309;
                        }
                        try
                        {
                            workflowCoreRuntime.RaiseActivityExecuting(activityByName);
                            ActivityExecutionStatus status = activityExecutor.Execute(activityByName, context);
                            if (status == ActivityExecutionStatus.Closed)
                            {
                                context.CloseActivity();
                            }
                            else if (status != ActivityExecutionStatus.Executing)
                            {
                                throw new InvalidOperationException(SR.GetString("InvalidExecutionStatus", new object[] { activityByName.QualifiedName, status.ToString(), ActivityExecutionStatus.Executing.ToString() }));
                            }
                            goto Label_0309;
                        }
                        catch (Exception exception)
                        {
                            WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Execute of Activity {0} threw {1}", new object[] { activityByName.QualifiedName, exception.ToString() });
                            throw;
                        }
                        break;

                    case ActivityOperationType.Cancel:
                        break;

                    case ActivityOperationType.Compensate:
                        goto Label_01A4;

                    case ActivityOperationType.HandleFault:
                        goto Label_0248;

                    default:
                        goto Label_0309;
                    }
                    if (activityByName.ExecutionStatus != ActivityExecutionStatus.Canceling)
                    {
                        goto Label_0309;
                    }
                    try
                    {
                        ActivityExecutionStatus status2 = activityExecutor.Cancel(activityByName, context);
                        if (status2 == ActivityExecutionStatus.Closed)
                        {
                            context.CloseActivity();
                        }
                        else if (status2 != ActivityExecutionStatus.Canceling)
                        {
                            throw new InvalidOperationException(SR.GetString("InvalidExecutionStatus", new object[] { activityByName.QualifiedName, status2.ToString(), ActivityExecutionStatus.Canceling.ToString() }));
                        }
                        goto Label_0309;
                    }
                    catch (Exception exception2)
                    {
                        WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Cancel of Activity {0} threw {1}", new object[] { activityByName.QualifiedName, exception2.ToString() });
                        throw;
                    }
Label_01A4:
                    if (activityByName.ExecutionStatus != ActivityExecutionStatus.Compensating)
                    {
                        goto Label_0309;
                    }
                    try
                    {
                        ActivityExecutionStatus status3 = activityExecutor.Compensate(activityByName, context);
                        if (status3 == ActivityExecutionStatus.Closed)
                        {
                            context.CloseActivity();
                        }
                        else if (status3 != ActivityExecutionStatus.Compensating)
                        {
                            throw new InvalidOperationException(SR.GetString("InvalidExecutionStatus", new object[] { activityByName.QualifiedName, status3.ToString(), ActivityExecutionStatus.Compensating.ToString() }));
                        }
                        goto Label_0309;
                    }
                    catch (Exception exception3)
                    {
                        WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Compensate of Activity {0} threw {1}", new object[] { activityByName.QualifiedName, exception3.ToString() });
                        throw;
                    }
Label_0248:
                    if (activityByName.ExecutionStatus == ActivityExecutionStatus.Faulting)
                    {
                        try
                        {
                            ActivityExecutionStatus status4 = activityExecutor.HandleFault(activityByName, context, this.exceptionToDeliver);
                            if (status4 == ActivityExecutionStatus.Closed)
                            {
                                context.CloseActivity();
                            }
                            else if (status4 != ActivityExecutionStatus.Faulting)
                            {
                                throw new InvalidOperationException(SR.GetString("InvalidExecutionStatus", new object[] { activityByName.QualifiedName, status4.ToString(), ActivityExecutionStatus.Faulting.ToString() }));
                            }
                            goto Label_0309;
                        }
                        catch (Exception exception4)
                        {
                            WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 1, "Compensate of Activity {0} threw {1}", new object[] { activityByName.QualifiedName, exception4.ToString() });
                            throw;
                        }
                    }
                }
            }
Label_0309:
            return(true);
        }