Ejemplo n.º 1
0
        private static ActivityExecutionStatus ExecuteActivity(Activity activity, ActivityExecutionContext context, bool locksAcquired)
        {
            TransactedContextFilter activityExecutorFromType = (TransactedContextFilter)ActivityExecutors.GetActivityExecutorFromType(typeof(TransactedContextFilter));

            if (!locksAcquired && !context.AcquireLocks(activityExecutorFromType))
            {
                return(activity.ExecutionStatus);
            }
            if (GetTransactionOptions(activity) != null)
            {
                context.CheckpointInstanceState();
            }
            return(activityExecutorFromType.NextActivityExecutorInChain(activity).Execute(activity, context));
        }
Ejemplo n.º 2
0
        void IActivityEventListener <EventArgs> .OnEvent(object sender, EventArgs e)
        {
            ActivityExecutionContext context = (ActivityExecutionContext)sender;

            // only if activity is still executing, then run it
            if (context.Activity.ExecutionStatus == ActivityExecutionStatus.Executing)
            {
                ActivityExecutionStatus newStatus = TransactedContextFilter.ExecuteActivity(context.Activity, context, true);
                if (newStatus == ActivityExecutionStatus.Closed)
                {
                    context.CloseActivity();
                }
            }
        }
Ejemplo n.º 3
0
        void IActivityEventListener <ActivityExecutionStatusChangedEventArgs> .OnEvent(object sender, ActivityExecutionStatusChangedEventArgs e)
        {
            ActivityExecutionContext context = sender as ActivityExecutionContext;

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

            if (context.Activity.HasPrimaryClosed && context.Activity.LockCountOnStatusChange == 1)
            {
                // get exception
                Exception exception = (Exception)context.Activity.GetValue(ActivityExecutionContext.CurrentExceptionProperty);
                if (exception != null)
                {
                    WorkflowTransactionOptions transactionOptions = TransactedContextFilter.GetTransactionOptions(context.Activity);
                    if (transactionOptions != null)
                    {
                        // request revert to checkpoint state
                        context.RequestRevertToCheckpointState(this.OnRevertInstanceState, new StateRevertedEventArgs(exception), false, null);
                    }
                    else
                    {
                        // release locks
                        context.ReleaseLocks(false);
                        context.Activity.UnregisterForStatusChange(Activity.LockCountOnStatusChangeChangedEvent, this);
                        context.Activity.ReleaseLockOnStatusChange(this);
                    }
                }
                else
                {
                    try
                    {
                        // 1st param is for transactional, means if the release lock on status change will try to persist the workflow instace
                        // if that fails, then locks will be reacquired, otherwise they will be released.
                        context.ReleaseLocks(true);
                        context.Activity.UnregisterForStatusChange(Activity.LockCountOnStatusChangeChangedEvent, this);
                        context.Activity.ReleaseLockOnStatusChange(this);
                        context.DisposeCheckpointState();
                    }
                    catch
                    {
                        // re-subscribe
                        context.Activity.RegisterForStatusChange(Activity.LockCountOnStatusChangeChangedEvent, this);
                        throw;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override ActivityExecutionStatus Execute(Activity activity, ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }
            if (!activity.SupportsTransaction)
            {
                throw new ArgumentException("activity");
            }

            // subscribe to the main activity
            activity.RegisterForStatusChange(Activity.LockCountOnStatusChangeChangedEvent, this);
            activity.HoldLockOnStatusChange(this);
            return(TransactedContextFilter.ExecuteActivity(activity, executionContext, false));
        }
Ejemplo n.º 5
0
        private static ActivityExecutionStatus ExecuteActivity(Activity activity, ActivityExecutionContext context, bool locksAcquired)
        {
            // acquire needed synchronization
            TransactedContextFilter executor = (TransactedContextFilter)ActivityExecutors.GetActivityExecutorFromType(typeof(TransactedContextFilter));

            if (!locksAcquired && !context.AcquireLocks(executor))
            {
                return(activity.ExecutionStatus);
            }

            // checkpoint for instance state
            //
            WorkflowTransactionOptions transaction = TransactedContextFilter.GetTransactionOptions(activity);

            if (transaction != null)
            {
                context.CheckpointInstanceState();
            }

            // delegate to the next executor for the activity
            return(executor.NextActivityExecutorInChain(activity).Execute(activity, context));
        }