private void InvokeDelegate(Activity currentContextActivity, Activity targetContextActivity, T e, bool sync, bool transacted)
        {
            ActivityExecutorDelegateOperation <T> item = null;

            if (this.delegateValue != null)
            {
                item = new ActivityExecutorDelegateOperation <T>(this.activityQualifiedName, this.delegateValue, e, this.ContextId);
            }
            else
            {
                item = new ActivityExecutorDelegateOperation <T>(this.activityQualifiedName, this.eventListener, e, this.ContextId);
            }
            bool flag = this.MayInvokeDelegateNow(currentContextActivity);

            if (flag && sync)
            {
                Activity activity = targetContextActivity.GetActivityByName(this.activityQualifiedName);
                using (currentContextActivity.WorkflowCoreRuntime.SetCurrentActivity(activity))
                {
                    item.SynchronousInvoke = true;
                    item.Run(currentContextActivity.WorkflowCoreRuntime);
                    return;
                }
            }
            Activity activityByName = targetContextActivity.GetActivityByName(this.activityQualifiedName);

            currentContextActivity.WorkflowCoreRuntime.ScheduleItem(item, ActivityExecutionContext.IsInAtomicTransaction(activityByName), transacted, !flag);
        }
コード例 #2
0
        private bool MayInvokeDelegateNow(Activity currentContextActivity)
        {
            // Ok to invoke right away if
            // subscriber wants to participate in the current transaction
            if ((this.activityQualifiedName == null) || (this.wantInTransact))
            {
                return(true);
            }

            // If not in atomic scope at all,
            if (!ActivityExecutionContext.IsInAtomicTransaction(currentContextActivity.WorkflowCoreRuntime.CurrentActivity))
            {
                return(true);
            }

            // Has not started executing yet, queue it up for now
            // Not letting it leak out for recv case any more
            Activity targetContextActivity = currentContextActivity.WorkflowCoreRuntime.GetContextActivityForId(this.contextId);

            if (targetContextActivity == null)
            {
                return(false);
            }

            // or in atomic and subscriber in same scope,
            // or in an atomic scope that's not in executing state, e.g. need to fire Scope closed status
            Activity targetActivity = targetContextActivity.GetActivityByName(this.activityQualifiedName, true);

            if (targetActivity == null)
            {
                return(false);
            }

            if (ActivityExecutionContext.IsInAtomicTransaction(targetActivity) &&
                ActivityExecutionContext.IsInAtomicTransaction(currentContextActivity.WorkflowCoreRuntime.CurrentActivity))
            {
                return(true);
            }

            // If the activity receiving the subscription is the scope itself
            if (targetActivity.MetaEquals(currentContextActivity))
            {
                return(true);
            }

            return(false);
        }
        private bool MayInvokeDelegateNow(Activity currentContextActivity)
        {
            if ((this.activityQualifiedName == null) || this.wantInTransact)
            {
                return(true);
            }
            if (!ActivityExecutionContext.IsInAtomicTransaction(currentContextActivity.WorkflowCoreRuntime.CurrentActivity))
            {
                return(true);
            }
            Activity contextActivityForId = currentContextActivity.WorkflowCoreRuntime.GetContextActivityForId(this.contextId);

            if (contextActivityForId == null)
            {
                return(false);
            }
            Activity activityByName = contextActivityForId.GetActivityByName(this.activityQualifiedName, true);

            if (activityByName == null)
            {
                return(false);
            }
            return((ActivityExecutionContext.IsInAtomicTransaction(activityByName) && ActivityExecutionContext.IsInAtomicTransaction(currentContextActivity.WorkflowCoreRuntime.CurrentActivity)) || activityByName.MetaEquals(currentContextActivity));
        }
コード例 #4
0
        private void InvokeDelegate(Activity currentContextActivity, Activity targetContextActivity, T e, bool sync, bool transacted)
        {
            ActivityExecutorDelegateOperation delegateOperation = null;

            if (this.delegateValue != null)
            {
                delegateOperation = new ActivityExecutorDelegateOperation(this.activityQualifiedName, this.delegateValue, e, this.ContextId);
            }
            else
            {
                delegateOperation = new ActivityExecutorDelegateOperation(this.activityQualifiedName, this.eventListener, e, this.ContextId);
            }

            bool mayInvokeDelegateNow = MayInvokeDelegateNow(currentContextActivity);

            if (mayInvokeDelegateNow && sync)
            {
                Activity targetActivity = targetContextActivity.GetActivityByName(this.activityQualifiedName);
                using (currentContextActivity.WorkflowCoreRuntime.SetCurrentActivity(targetActivity))
                {
                    delegateOperation.SynchronousInvoke = true;
                    delegateOperation.Run(currentContextActivity.WorkflowCoreRuntime);
                }
            }
            else
            {
                // If in atomic and subscriber not in same scope
                // Queue it on the subscriber's baseExecutor
                Activity targetActivity = targetContextActivity.GetActivityByName(this.activityQualifiedName);
                currentContextActivity.WorkflowCoreRuntime.ScheduleItem(delegateOperation, ActivityExecutionContext.IsInAtomicTransaction(targetActivity), transacted, !mayInvokeDelegateNow);
            }
        }