Ejemplo n.º 1
0
        void IActivityEventListener <ActivityExecutionStatusChangedEventArgs> .OnEvent(object sender, ActivityExecutionStatusChangedEventArgs e)
        {
            ActivityExecutionContext context = sender as ActivityExecutionContext;

            if (context == null)
            {
                throw new ArgumentException();
            }

            e.Activity.UnregisterForStatusChange(Activity.ClosedEvent, this);
            if (e.Activity is EventHandlersActivity)
            {
                if (this.BodyActivity.ExecutionStatus == ActivityExecutionStatus.Closed)
                {
                    context.CloseActivity();
                }
                //else Eventhandlers faulted, let exception propagate up.
            }
            else
            {
                EventHandlersActivity eventHandlers = this.EventHandlersActivity;
                if (eventHandlers == null || eventHandlers.ExecutionStatus == ActivityExecutionStatus.Closed)
                {
                    context.CloseActivity();
                }
                else
                {
                    eventHandlers.UnsubscribeAndClose();
                }
            }
        }
        /// <summary>
        /// Defines the processing procedure when the subscribed-to event occurs.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">The previously typed event arguments.</param>
        void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs e)
        {
            ActivityExecutionContext ctx = sender as ActivityExecutionContext;

            if (ctx != null &&
                this.ExecutionStatus == ActivityExecutionStatus.Executing)
            {
                try
                {
                    ActivityExecutionStatus status = ProcessQueueElement(ctx);
                    if (status == ActivityExecutionStatus.Closed)
                    {
                        UnsubscribeFromQueueItemAvailable(ctx);
                        ctx.CloseActivity();
                    }
                    else if (status == ActivityExecutionStatus.Canceling)
                    {
                        UnsubscribeFromQueueItemAvailable(ctx);
                        ctx.CloseActivity();

                        throw new CustomWorkflowTerminateException(BusinessProcessExecutionResult.Declined);
                    }
                }
                finally
                {
                }
            }
        }
Ejemplo n.º 3
0
        void IActivityEventListener <ActivityExecutionStatusChangedEventArgs> .OnEvent(object sender, ActivityExecutionStatusChangedEventArgs e)
        {
            ActivityExecutionContext context = sender as ActivityExecutionContext;

            if (context == null)
            {
                throw new ArgumentException();
            }
            e.Activity.UnregisterForStatusChange(Activity.ClosedEvent, this);
            if (e.Activity is System.Workflow.Activities.EventHandlersActivity)
            {
                if (this.BodyActivity.ExecutionStatus == ActivityExecutionStatus.Closed)
                {
                    context.CloseActivity();
                }
            }
            else
            {
                System.Workflow.Activities.EventHandlersActivity eventHandlersActivity = this.EventHandlersActivity;
                if ((eventHandlersActivity == null) || (eventHandlersActivity.ExecutionStatus == ActivityExecutionStatus.Closed))
                {
                    context.CloseActivity();
                }
                else
                {
                    eventHandlersActivity.UnsubscribeAndClose();
                }
            }
        }
Ejemplo n.º 4
0
        protected override void OnWorkflowChangesCompleted(ActivityExecutionContext executionContext)
        {
            String activeChildQualifiedName = this.GetValue(ActiveChildQualifiedNameProperty) as String;

            if (activeChildQualifiedName != null && activeChildRemovedInDynamicUpdate)
            {   //We have our active child removed.
                if (this.ExecutionStatus == ActivityExecutionStatus.Canceling ||
                    (this.ExecutionStatus == ActivityExecutionStatus.Faulting) &&
                    (bool)this.GetValue(SequenceFaultingProperty))
                {
                    if (this.ExecutionStatus == ActivityExecutionStatus.Faulting)
                    {
                        this.RemoveProperty(SequenceFaultingProperty);
                    }

                    this.RemoveProperty(ActiveChildQualifiedNameProperty);
                    executionContext.CloseActivity();
                }
                else if (this.ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    if (!TryScheduleNextChild(executionContext))
                    {
                        OnSequenceComplete(executionContext);
                        executionContext.CloseActivity();
                    }
                }
            }
            activeChildRemovedInDynamicUpdate = false;
            base.OnWorkflowChangesCompleted(executionContext);
        }
Ejemplo n.º 5
0
        protected override void OnWorkflowChangesCompleted(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            base.OnWorkflowChangesCompleted(executionContext);
            if (this.ActivityState != null)
            {
                switch (base.ExecutionStatus)
                {
                case ActivityExecutionStatus.Executing:
                    if (this.IsScopeCompleted && this.AllHandlersAreQuiet(this, executionContext))
                    {
                        executionContext.CloseActivity();
                    }
                    return;

                case ActivityExecutionStatus.Canceling:
                case ActivityExecutionStatus.Faulting:
                    if (this.AllHandlersAreQuiet(this, executionContext))
                    {
                        executionContext.CloseActivity();
                    }
                    return;

                case ActivityExecutionStatus.Closed:
                case ActivityExecutionStatus.Compensating:
                    return;
                }
            }
        }
Ejemplo n.º 6
0
        protected override void OnWorkflowChangesCompleted(ActivityExecutionContext executionContext)
        {
            base.OnWorkflowChangesCompleted(executionContext);

            switch (this.ExecutionStatus)
            {
            case ActivityExecutionStatus.Executing:
                if (bodyActivityRemovedInDynamicUpdate)
                {
                    if (EventHandlersActivity == null || EventHandlersActivity.ExecutionStatus == ActivityExecutionStatus.Closed)
                    {
                        executionContext.CloseActivity();
                    }
                    else if (EventHandlersActivity.ExecutionStatus == ActivityExecutionStatus.Executing)
                    {
                        EventHandlersActivity.UnsubscribeAndClose();
                    }
                }
                if (eventHandlersRemovedInDynamicUpdate)
                {
                    if (BodyActivity == null || BodyActivity.ExecutionStatus == ActivityExecutionStatus.Closed)
                    {
                        executionContext.CloseActivity();
                    }
                }
                break;

            default:
                break;
            }
            eventHandlersRemovedInDynamicUpdate = false;
            bodyActivityRemovedInDynamicUpdate  = false;
        }
Ejemplo n.º 7
0
        void IActivityEventListener <ActivityExecutionStatusChangedEventArgs> .OnEvent(Object sender, ActivityExecutionStatusChangedEventArgs 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");
            }

            e.Activity.UnregisterForStatusChange(Activity.ClosedEvent, this);

            SequenceActivity sequenceActivity = context.Activity as SequenceActivity;

            if (sequenceActivity == null)
            {
                throw new ArgumentException("sender");
            }

            if (sequenceActivity.ExecutionStatus == ActivityExecutionStatus.Canceling ||
                (sequenceActivity.ExecutionStatus == ActivityExecutionStatus.Faulting) &&
                (bool)this.GetValue(SequenceFaultingProperty))
            {
                if (sequenceActivity.ExecutionStatus == ActivityExecutionStatus.Faulting)
                {
                    this.RemoveProperty(SequenceFaultingProperty);
                }

                this.RemoveProperty(ActiveChildQualifiedNameProperty);
                context.CloseActivity();
            }
            else if (sequenceActivity.ExecutionStatus == ActivityExecutionStatus.Executing)
            {
                if (!TryScheduleNextChild(context))
                {
                    OnSequenceComplete(context);
                    context.CloseActivity();
                }
            }
        }
Ejemplo n.º 8
0
        void q_QueueItemAvailable(object sender, QueueEventArgs e)
        {
            ActivityExecutionContext aec = sender as ActivityExecutionContext;

            if (aec != null)
            {
                WorkflowQueuingService qs = aec.GetService <WorkflowQueuingService>();

                WorkflowQueue q = qs.GetWorkflowQueue(e.QueueName);
                //get the outparameters from the workflow
                object o = q.Dequeue();
                //delete the queue
                qs.DeleteWorkflowQueue(e.QueueName);
                Dictionary <string, object> outparams = o as Dictionary <string, object>;
                if (outparams != null)
                {
                    foreach (KeyValuePair <string, object> item in outparams)
                    {
                        if (this.Parameters.Contains(item.Key))
                        {
                            //modify the value
                            this.Parameters[item.Key].SetValue(WorkflowParameterBinding.ValueProperty, item.Value);
                        }
                    }
                }
                aec.CloseActivity();
            }
        }
        void IActivityEventListener <ActivityExecutionStatusChangedEventArgs> .OnEvent(object sender, ActivityExecutionStatusChangedEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }
            ActivityExecutionContext context = sender as ActivityExecutionContext;

            if (context == null)
            {
                throw new ArgumentException(SR.Error_SenderMustBeActivityExecutionContext, "sender");
            }
            e.Activity.UnregisterForStatusChange(Activity.ClosedEvent, this);
            ActivityExecutionContextManager executionContextManager = context.ExecutionContextManager;

            executionContextManager.CompleteExecutionContext(executionContextManager.GetExecutionContext(e.Activity));
            if (!this.TryNextIteration(context))
            {
                context.CloseActivity();
            }
        }
Ejemplo n.º 10
0
        void IActivityEventListener <ActivityExecutionStatusChangedEventArgs> .OnEvent(object sender, ActivityExecutionStatusChangedEventArgs e)
        {
            ActivityExecutionContext context = sender as
                                               ActivityExecutionContext;

            if (e.ExecutionStatus == ActivityExecutionStatus.Closed)
            {
                e.Activity.UnregisterForStatusChange(Activity.ClosedEvent, this);
                LoggerActivity lgr      = context.Activity as LoggerActivity;
                bool           finished = true;
                for (int childNum = 0; childNum < lgr.EnabledActivities.Count;
                     childNum++)
                {
                    Activity child = lgr.EnabledActivities[childNum];
                    if ((child.ExecutionStatus != ActivityExecutionStatus.
                         Initialized) && (child.ExecutionStatus !=
                                          ActivityExecutionStatus.Closed))
                    {
                        finished = false;
                    }
                }
                if (finished)
                {
                    context.CloseActivity();
                }
            }
        }
Ejemplo n.º 11
0
        protected sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }

            ActivityExecutionStatus status = ExecuteForActivity(executionContext, this.InterfaceType, this.MethodName);

            if (status == ActivityExecutionStatus.Closed)
            {
                UnsubscribeForActivity(executionContext);
                executionContext.CloseActivity();
                return(status);
            }

            // cannot resolve queue name or message not available
            // hence subscribe for message arrival
            if (!this.ActivitySubscribed)
            {
                this.ActivitySubscribed = CorrelationService.Subscribe(executionContext, this, this.InterfaceType, this.MethodName, this, this.WorkflowInstanceId);
            }

            return(ActivityExecutionStatus.Executing);
        }
Ejemplo n.º 12
0
        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");
            }

            if (this.ExecutionStatus != ActivityExecutionStatus.Closed)
            {
                System.Diagnostics.Debug.Assert(this.SubscriptionID != Guid.Empty);

                WorkflowQueuingService qService = context.GetService <WorkflowQueuingService>();
                qService.GetWorkflowQueue(e.QueueName).Dequeue();
                qService.DeleteWorkflowQueue(e.QueueName);
                context.CloseActivity();
            }
        }
 protected internal sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
 {
     executionContext.CloseActivity();
     string error = this.Error;
     executionContext.SuspendWorkflowInstance(error);
     return ActivityExecutionStatus.Closed;
 }
        void IActivityEventListener <ActivityExecutionStatusChangedEventArgs> .OnEvent(object sender, ActivityExecutionStatusChangedEventArgs 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");
            }
            ParallelActivity activity = context.Activity as ParallelActivity;

            e.Activity.UnregisterForStatusChange(Activity.ClosedEvent, this);
            bool flag = true;

            for (int i = 0; i < activity.EnabledActivities.Count; i++)
            {
                Activity activity2 = activity.EnabledActivities[i];
                if ((activity2.ExecutionStatus != ActivityExecutionStatus.Initialized) && (activity2.ExecutionStatus != ActivityExecutionStatus.Closed))
                {
                    flag = false;
                    break;
                }
            }
            if (flag)
            {
                context.CloseActivity();
            }
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        protected internal override sealed ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            executionContext.CloseActivity();

            string suspendReason = this.Error;
            executionContext.SuspendWorkflowInstance(suspendReason);
            return ActivityExecutionStatus.Closed;
        }
Ejemplo n.º 17
0
        protected internal override sealed ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            executionContext.CloseActivity();

            string terminateReason = this.Error;
            executionContext.TerminateWorkflowInstance(new WorkflowTerminatedException(terminateReason));
            return ActivityExecutionStatus.Closed;
        }
Ejemplo n.º 18
0
 protected override void OnWorkflowChangesCompleted(ActivityExecutionContext executionContext)
 {
     base.OnWorkflowChangesCompleted(executionContext);
     if (this.activeBranchRemoved)
     {
         executionContext.CloseActivity();
     }
     this.activeBranchRemoved = false;
 }
Ejemplo n.º 19
0
        // When a child activity is closed, it's removed from the execution context,
        // and the execution proceed to the next iteration.
        private void OnChildClose(Object sender, ActivityExecutionStatusChangedEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("OnChildClose parameter 'e' is null.");
            }
            if (sender == null)
            {
                throw new ArgumentNullException("OnChildClose parameter 'sender' is null.");
            }

            ActivityExecutionContext context = sender as ActivityExecutionContext;

            if (context == null)
            {
                throw new ArgumentException("OnChildClose parameter 'sender' is not ActivityExecutionContext.");
            }

            ForEach foreachActivity = context.Activity as ForEach;

            if (foreachActivity == null)
            {
                throw new ArgumentException("OnChildClose parameter 'sender' does not contain a 'ForEach' activity.");
            }

            // Remove the event handler first.
            e.Activity.Closed -= this.OnChildClose;

            // Then remove the child activity from the execution context.
            context.ExecutionContextManager.CompleteExecutionContext(context.ExecutionContextManager.GetExecutionContext(e.Activity));

            // Move on to the next iteration.
            if (this.ExecutionStatus == ActivityExecutionStatus.Canceling)
            {
                context.CloseActivity();
            }
            else if (this.ExecutionStatus == ActivityExecutionStatus.Executing)
            {
                if (!ExecuteNext(context))
                {
                    context.CloseActivity();
                }
            }
        }
Ejemplo n.º 20
0
        private void HandleExternalEvent(Object sender, QueueEventArgs args)
        {
            ThreadMonitor.WriteToConsole(Thread.CurrentThread, "WaitForMessageActivity", "WaitForMessageActivity: Processed External Event");

            object data = this.workflowQueue.Dequeue();

            ActivityExecutionContext context = sender as ActivityExecutionContext;

            context.CloseActivity();
        }
Ejemplo n.º 21
0
        void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs e)
        {
            ActivityExecutionContext context  = (ActivityExecutionContext)sender;
            WebServiceInputActivity  activity = context.Activity as WebServiceInputActivity;

            if ((activity.ExecutionStatus == ActivityExecutionStatus.Executing) && (this.ExecuteForActivity(context, activity.InterfaceType, activity.MethodName) == ActivityExecutionStatus.Closed))
            {
                this.UnsubscribeForActivity(context);
                context.CloseActivity();
            }
        }
 public static void OnWorkflowChangesCompleted(CompositeActivity activity, ActivityExecutionContext executionContext)
 {
     string str = activity.GetValue(ActiveChildQualifiedNameProperty) as string;
     bool flag = (bool) activity.GetValue(ActiveChildRemovedProperty);
     if (((str != null) && flag) && (((activity.ExecutionStatus == ActivityExecutionStatus.Canceling) || (activity.ExecutionStatus == ActivityExecutionStatus.Faulting)) || ((activity.ExecutionStatus == ActivityExecutionStatus.Executing) && !TryScheduleNextChild(activity, executionContext))))
     {
         activity.RemoveProperty(ActiveChildQualifiedNameProperty);
         executionContext.CloseActivity();
     }
     activity.RemoveProperty(ActiveChildRemovedProperty);
 }
 protected override void OnWorkflowChangesCompleted(ActivityExecutionContext executionContext)
 {
     if ((base.GetValue(ActiveChildQualifiedNameProperty) is string) && this.activeChildRemovedInDynamicUpdate)
     {
         if ((base.ExecutionStatus == ActivityExecutionStatus.Canceling) || ((base.ExecutionStatus == ActivityExecutionStatus.Faulting) && ((bool)base.GetValue(SequenceFaultingProperty))))
         {
             if (base.ExecutionStatus == ActivityExecutionStatus.Faulting)
             {
                 base.RemoveProperty(SequenceFaultingProperty);
             }
             base.RemoveProperty(ActiveChildQualifiedNameProperty);
             executionContext.CloseActivity();
         }
         else if ((base.ExecutionStatus == ActivityExecutionStatus.Executing) && !this.TryScheduleNextChild(executionContext))
         {
             this.OnSequenceComplete(executionContext);
             executionContext.CloseActivity();
         }
     }
     this.activeChildRemovedInDynamicUpdate = false;
     base.OnWorkflowChangesCompleted(executionContext);
 }
Ejemplo n.º 24
0
        private void HandleChildActivityClosed(object sender, ActivityExecutionStatusChangedEventArgs eventArgs)
        {
            ActivityExecutionContext context = sender as ActivityExecutionContext;

            if (context == null)
            {
                throw new ArgumentException(SR.Error_SenderMustBeActivityExecutionContext, "sender");
            }
            if (eventArgs == null)
            {
                throw new ArgumentNullException("eventArgs");
            }
            Activity      childActivity = eventArgs.Activity;
            StateActivity activity      = (StateActivity)context.Activity;

            GetExecutionState(context).SchedulerBusy = false;
            CleanupChildAtClosure(context, childActivity);
            switch (activity.ExecutionStatus)
            {
            case ActivityExecutionStatus.Executing:
                if (!(childActivity is EventDrivenActivity))
                {
                    StateInitializationActivity stateInitialization = childActivity as StateInitializationActivity;
                    if (stateInitialization != null)
                    {
                        HandleStateInitializationCompleted(context, stateInitialization);
                        return;
                    }
                    if (childActivity is StateFinalizationActivity)
                    {
                        HandleStateFinalizationCompleted(context);
                        return;
                    }
                    if (childActivity is StateActivity)
                    {
                        HandleSubStateCompleted(context);
                        return;
                    }
                    InvalidChildActivity(activity);
                    return;
                }
                HandleEventDrivenCompleted(context);
                return;

            case ActivityExecutionStatus.Canceling:
            case ActivityExecutionStatus.Faulting:
                context.CloseActivity();
                return;
            }
            throw new InvalidOperationException(SR.GetInvalidActivityStatus(context.Activity));
        }
Ejemplo n.º 25
0
        private void OnUnsubscribeAndClose(object sender, EventArgs args)
        {
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            ActivityExecutionContext context = (ActivityExecutionContext)sender;

            if (context == null)
            {
                throw new ArgumentException("sender");
            }

            EventHandlersActivity handlers = context.Activity as EventHandlersActivity;

            if (context.Activity.ExecutionStatus != ActivityExecutionStatus.Executing)
            {
                return;
            }

            Debug.Assert(!handlers.IsScopeCompleted, "Only notified of scope body completion once");
            handlers.IsScopeCompleted = true;

            ActivityExecutionContextManager contextManager = context.ExecutionContextManager;
            bool readyToClose = true;

            for (int i = 0; i < handlers.EnabledActivities.Count; ++i)
            {
                EventDrivenActivity evtDriven = handlers.EnabledActivities[i] as EventDrivenActivity;
                EventHandlerEventActivitySubscriber eventSubscriber = handlers.ActivityState[i];
                evtDriven.EventActivity.Unsubscribe(context, eventSubscriber);

                if (contextManager.GetExecutionContext(evtDriven) != null || handlers.ActivityState[i].PendingExecutionCount != 0)
                {
                    readyToClose = false;
                }
            }

            if (readyToClose)
            {
                handlers.ActivityState = null;
                context.CloseActivity();
            }
        }
        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);
        }
Ejemplo n.º 27
0
 protected override void OnWorkflowChangesCompleted(ActivityExecutionContext executionContext)
 {
     base.OnWorkflowChangesCompleted(executionContext);
     if (base.ExecutionStatus == ActivityExecutionStatus.Executing)
     {
         if (this.bodyActivityRemovedInDynamicUpdate)
         {
             if ((this.EventHandlersActivity == null) || (this.EventHandlersActivity.ExecutionStatus == ActivityExecutionStatus.Closed))
             {
                 executionContext.CloseActivity();
             }
             else if (this.EventHandlersActivity.ExecutionStatus == ActivityExecutionStatus.Executing)
             {
                 this.EventHandlersActivity.UnsubscribeAndClose();
             }
         }
         if (this.eventHandlersRemovedInDynamicUpdate && ((this.BodyActivity == null) || (this.BodyActivity.ExecutionStatus == ActivityExecutionStatus.Closed)))
         {
             executionContext.CloseActivity();
         }
     }
     this.eventHandlersRemovedInDynamicUpdate = false;
     this.bodyActivityRemovedInDynamicUpdate  = false;
 }
Ejemplo n.º 28
0
        void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs e)
        {
            Console.WriteLine("OnQueueItemAvailable #1");

            // If activity is not scheduled for execution, do nothing
            if (this.ExecutionStatus == ActivityExecutionStatus.Executing)
            {
                Console.WriteLine("OnQueueItemAvailable #2");

                ActivityExecutionContext context = sender as ActivityExecutionContext;
                if (this.ProcessQueueItem(context))
                {
                    context.CloseActivity();
                }
            }
        }
        void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs e)
        {
            ActivityExecutionContext    context  = (ActivityExecutionContext)sender;
            HandleExternalEventActivity activity = context.Activity as HandleExternalEventActivity;

            if (activity.ExecutionStatus == ActivityExecutionStatus.Executing)
            {
                object[] args = null;
                if (InboundActivityHelper.ExecuteForActivity(this, context, this.InterfaceType, this.EventName, out args) == ActivityExecutionStatus.Closed)
                {
                    this.RaiseEvent(args);
                    this.UnsubscribeForActivity(context);
                    context.CloseActivity();
                }
            }
        }
Ejemplo n.º 30
0
        private static void Complete(ActivityExecutionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            StateActivity activity = (StateActivity)context.Activity;
            StateMachineExecutionState executionState = GetExecutionState(activity);

            if (StateMachineHelpers.IsLeafState(activity))
            {
                executionState.PreviousStateName = activity.Name;
            }
            CleanUp(context);
            executionState.SchedulerBusy = true;
            context.CloseActivity();
        }
Ejemplo n.º 31
0
        void IActivityEventListener <ActivityExecutionStatusChangedEventArgs> .OnEvent(object sender, ActivityExecutionStatusChangedEventArgs 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");
            }
            context.CloseActivity();
        }
Ejemplo n.º 32
0
        void IActivityEventListener <ActivityExecutionStatusChangedEventArgs> .OnEvent(object sender, ActivityExecutionStatusChangedEventArgs 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("Sender must be ActivityExecutionContext", "sender");
            }

            BlockActivity activity = context.Activity as BlockActivity;

            e.Activity.UnregisterForStatusChange(Activity.ClosedEvent, this);

            ActivityExecutionStatus result = ActivityExecutionStatus.Initialized;

            switch (this.Type)
            {
            case BlockActivityType.All:
                result = ProcessClosedEvenForAllActivities(context, e.Activity);
                break;

            case BlockActivityType.Any:
                result = ProcessClosedEvenForAnyActivities(context, e.Activity);
                break;

            default:
                throw new ArgumentOutOfRangeException("Unknown Type");
            }

            if (result == ActivityExecutionStatus.Closed)
            {
                context.CloseActivity();
            }
        }
Ejemplo n.º 33
0
        void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs e)
        {
            ActivityExecutionContext context  = (ActivityExecutionContext)sender;
            WebServiceInputActivity  activity = context.Activity as WebServiceInputActivity;

            // if activity is not scheduled for execution do not dequeue the message
            if (activity.ExecutionStatus != ActivityExecutionStatus.Executing)
            {
                return;
            }

            ActivityExecutionStatus status = ExecuteForActivity(context, activity.InterfaceType, activity.MethodName);

            if (status == ActivityExecutionStatus.Closed)
            {
                UnsubscribeForActivity(context);
                context.CloseActivity();
            }
        }
Ejemplo n.º 34
0
        public void OnEvent(object sender, ActivityExecutionStatusChangedEventArgs e)
        {
            if (sender == null)
            {
                throw new ArgumentNullException("sender");
            }
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            ActivityExecutionContext __context = sender as ActivityExecutionContext;

            if (__context == null)
            {
                // TODO : Get the exception message from the System.Workflow.Activities.StringResources.resources resource file.
                throw new ArgumentException("The sender parameter must be of type ActivityExecutionContext.");
            }
            __context.CloseActivity();
        }
Ejemplo n.º 35
0
        // This function executes the ForEach activity.  It advances the current index of the collection.
        // If the end of the collection is reached, return false.  Otherwise, it executes any child activity
        // and return true.
        private bool ExecuteNext(ActivityExecutionContext context)
        {
            // First, move to the next position.
            if (!this.Enumerator.MoveNext())
                return false;

            // Fire the Iterating event.
            base.RaiseEvent(IteratingEvent, this, EventArgs.Empty);

            // Execute the child activity.
            if (this.EnabledActivities.Count > 0)
            {
                // Add the child activity to the execution context and setup the event handler to 
                // listen to the child Close event.
                // A new instance of the child activity is created for each iteration.
                ActivityExecutionContext innerContext = 
                    context.ExecutionContextManager.CreateExecutionContext(this.EnabledActivities[0]);
                innerContext.Activity.Closed += this.OnChildClose;

                // Execute the child activity again.  
                innerContext.ExecuteActivity(innerContext.Activity);
            }
            else
            {
                // an empty foreach loop. 
                // If the ForEach activity is still executing, then execute the next one.
                if (this.ExecutionStatus == ActivityExecutionStatus.Executing)
                {
                    if (!ExecuteNext(context))
                        context.CloseActivity();
                }
            }
            return true;
        }
Ejemplo n.º 36
0
        public static void OnWorkflowChangesCompleted(CompositeActivity activity, ActivityExecutionContext executionContext)
        {
            String activeChildQualifiedName = activity.GetValue(ActiveChildQualifiedNameProperty) as String;
            bool activeChildRemovedInDynamicUpdate = (bool)activity.GetValue(ActiveChildRemovedProperty);

            if (activeChildQualifiedName != null && activeChildRemovedInDynamicUpdate)
            {   //We have our active child removed.    
                if (activity.ExecutionStatus == ActivityExecutionStatus.Canceling ||
                activity.ExecutionStatus == ActivityExecutionStatus.Faulting ||
                activity.ExecutionStatus == ActivityExecutionStatus.Executing && !TryScheduleNextChild(activity, executionContext))
                {
                    activity.RemoveProperty(ActiveChildQualifiedNameProperty);
                    executionContext.CloseActivity();
                }
            }
            activity.RemoveProperty(ActiveChildRemovedProperty);
        }
        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;
        }