Exemple #1
0
        public void Initialize(Activity definition, IDictionary <string, object> inputs, bool hasNameCollision)
        {
            this.rootActivity.SetValue(Activity.ActivityExecutionContextInfoProperty,
                                       new ActivityExecutionContextInfo(this.rootActivity.QualifiedName, this.GetNewContextActivityId(), instanceId, -1));
            this.rootActivity.SetValue(Activity.ActivityContextGuidProperty, instanceId);

            SetInputParameters(definition, this.rootActivity, inputs, hasNameCollision);

            ((IDependencyObjectAccessor)this.rootActivity).InitializeActivatingInstanceForRuntime(
                null,
                this);

            this.rootActivity.FixUpMetaProperties(definition);

            TimerQueue = new TimerEventSubscriptionCollection(this, this.instanceId);

            using (new ServiceEnvironment(this.rootActivity))
            {
                using (SetCurrentActivity(this.rootActivity))
                {
                    RegisterContextActivity(this.rootActivity);

                    using (ActivityExecutionContext executionContext = new ActivityExecutionContext(this.rootActivity, true))
                    {
                        executionContext.InitializeActivity(this.rootActivity);
                    }
                }
            }
        }
        public ActivityExecutionContext CreateExecutionContext(Activity activity)
        {
            if (this.ownerContext == null)
                throw new ObjectDisposedException("ActivityExecutionContextManager");

            if (activity == null)
                throw new ArgumentNullException("activity");

            if (!this.ownerContext.IsValidChild(activity, true))
                throw new ArgumentException(SR.GetString(SR.AEC_InvalidActivity), "activity");

            Activity copiedActivity = activity.Clone();
            ((IDependencyObjectAccessor)copiedActivity).InitializeInstanceForRuntime(this.ownerContext.Activity.WorkflowCoreRuntime);

            //Reset the cloned tree for execution.
            Queue<Activity> activityQueue = new Queue<Activity>();
            activityQueue.Enqueue(copiedActivity);

            while (activityQueue.Count != 0)
            {
                Activity clonedActivity = activityQueue.Dequeue();
                if (clonedActivity.ExecutionStatus != ActivityExecutionStatus.Initialized)
                {
                    clonedActivity.ResetAllKnownDependencyProperties();
                    CompositeActivity compositeActivity = clonedActivity as CompositeActivity;

                    if (compositeActivity != null)
                    {
                        for (int i = 0; i < compositeActivity.EnabledActivities.Count; ++i)
                        {
                            activityQueue.Enqueue(compositeActivity.EnabledActivities[i]);
                        }

                        ISupportAlternateFlow alternateFlow = compositeActivity as ISupportAlternateFlow;

                        if (alternateFlow != null)
                        {
                            for (int i = 0; i < alternateFlow.AlternateFlowActivities.Count; ++i)
                            {
                                activityQueue.Enqueue(alternateFlow.AlternateFlowActivities[i]);
                            }
                        }
                    }
                }
            }

            // get active context activities and add it to this one
            IList<Activity> activeContexts = (IList<Activity>)this.ownerContext.Activity.ContextActivity.GetValue(Activity.ActiveExecutionContextsProperty);
            if (activeContexts == null)
            {
                activeContexts = new List<Activity>();
                this.ownerContext.Activity.ContextActivity.SetValue(Activity.ActiveExecutionContextsProperty, activeContexts);
            }
            activeContexts.Add(copiedActivity);

            // prepare the copied activity as a context activity
            ActivityExecutionContextInfo contextInfo = new ActivityExecutionContextInfo(activity.QualifiedName, this.ownerContext.WorkflowCoreRuntime.GetNewContextActivityId(), Guid.NewGuid(), this.ownerContext.ContextId);
            copiedActivity.SetValue(Activity.ActivityExecutionContextInfoProperty, contextInfo);
            copiedActivity.SetValue(Activity.ActivityContextGuidProperty, contextInfo.ContextGuid);
            ActivityExecutionContext newExecutionContext = null;
            try
            {
                // inform workflow runtime
                this.ownerContext.Activity.WorkflowCoreRuntime.RegisterContextActivity(copiedActivity);

                // return the new context
                newExecutionContext = new ActivityExecutionContext(copiedActivity);
                this.executionContexts.Add(newExecutionContext);
                newExecutionContext.InitializeActivity(newExecutionContext.Activity);
                return newExecutionContext;
            }
            catch (Exception)
            {
                if (newExecutionContext != null)
                {
                    this.CompleteExecutionContext(newExecutionContext);
                }
                else
                {
                    activeContexts.Remove(copiedActivity);
                }
                throw;
            }
        }
 private void NotifyChangesToChildExecutors(IWorkflowCoreRuntime workflowCoreRuntime, Activity contextActivity, IList<WorkflowChangeAction> changeActions)
 {
     foreach (WorkflowChangeAction action in changeActions)
     {
         if (action is ActivityChangeAction)
         {
             CompositeActivity activity = contextActivity.TraverseDottedPathFromRoot(((ActivityChangeAction) action).OwnerActivityDottedPath) as CompositeActivity;
             if ((activity != null) && IsActivityExecutable(activity))
             {
                 ISupportWorkflowChanges activityExecutor = ActivityExecutors.GetActivityExecutor(activity) as ISupportWorkflowChanges;
                 if (activityExecutor == null)
                 {
                     throw new ApplicationException(SR.GetString("Error_WorkflowChangesNotSupported", new object[] { activity.GetType().FullName }));
                 }
                 using (workflowCoreRuntime.SetCurrentActivity(activity))
                 {
                     using (ActivityExecutionContext context = new ActivityExecutionContext(activity))
                     {
                         if (action is AddedActivityAction)
                         {
                             Activity activity2 = activity.Activities[((AddedActivityAction) action).Index];
                             if (IsActivityExecutable(activity2))
                             {
                                 activity2.OnActivityExecutionContextLoad(context.Activity.RootActivity.WorkflowCoreRuntime);
                                 context.InitializeActivity(activity2);
                                 activityExecutor.OnActivityAdded(context, activity2);
                             }
                         }
                         else if (action is RemovedActivityAction)
                         {
                             RemovedActivityAction action2 = (RemovedActivityAction) action;
                             if (IsActivityExecutable(action2.OriginalRemovedActivity))
                             {
                                 activityExecutor.OnActivityRemoved(context, action2.OriginalRemovedActivity);
                                 if (action2.OriginalRemovedActivity.ExecutionResult != ActivityExecutionResult.Uninitialized)
                                 {
                                     action2.OriginalRemovedActivity.Uninitialize(context.Activity.RootActivity.WorkflowCoreRuntime);
                                     action2.OriginalRemovedActivity.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Uninitialized);
                                 }
                                 action2.OriginalRemovedActivity.OnActivityExecutionContextUnload(context.Activity.RootActivity.WorkflowCoreRuntime);
                                 action2.OriginalRemovedActivity.Dispose();
                             }
                         }
                     }
                 }
             }
         }
     }
 }
        private void NotifyChangesToChildExecutors(IWorkflowCoreRuntime workflowCoreRuntime, Activity contextActivity, IList<WorkflowChangeAction> changeActions)
        {
            foreach (WorkflowChangeAction action in changeActions)
            {
                if (!(action is ActivityChangeAction))
                    continue;

                CompositeActivity ownerActivity = contextActivity.TraverseDottedPathFromRoot(((ActivityChangeAction)action).OwnerActivityDottedPath) as CompositeActivity;
                if (ownerActivity == null || !WorkflowChanges.IsActivityExecutable(ownerActivity))
                    continue;

                ISupportWorkflowChanges compositeActivityExecutor = ActivityExecutors.GetActivityExecutor(ownerActivity) as ISupportWorkflowChanges;
                if (compositeActivityExecutor == null)
                    throw new ApplicationException(SR.GetString(SR.Error_WorkflowChangesNotSupported, ownerActivity.GetType().FullName));

                using (workflowCoreRuntime.SetCurrentActivity(ownerActivity))
                {
                    using (ActivityExecutionContext executionContext = new ActivityExecutionContext(ownerActivity))
                    {
                        if (action is AddedActivityAction)
                        {
                            Activity addedActivity = ownerActivity.Activities[((AddedActivityAction)action).Index];
                            if (WorkflowChanges.IsActivityExecutable(addedActivity))
                            {
                                addedActivity.OnActivityExecutionContextLoad(executionContext.Activity.RootActivity.WorkflowCoreRuntime);
                                executionContext.InitializeActivity(addedActivity);
                                compositeActivityExecutor.OnActivityAdded(executionContext, addedActivity);
                            }
                        }
                        else if (action is RemovedActivityAction)
                        {
                            RemovedActivityAction removedActivityAction = (RemovedActivityAction)action;
                            if (WorkflowChanges.IsActivityExecutable(removedActivityAction.OriginalRemovedActivity))
                            {
                                compositeActivityExecutor.OnActivityRemoved(executionContext, removedActivityAction.OriginalRemovedActivity);
                                if (removedActivityAction.OriginalRemovedActivity.ExecutionResult != ActivityExecutionResult.Uninitialized)
                                {
                                    removedActivityAction.OriginalRemovedActivity.Uninitialize(executionContext.Activity.RootActivity.WorkflowCoreRuntime);
                                    removedActivityAction.OriginalRemovedActivity.SetValue(Activity.ExecutionResultProperty, ActivityExecutionResult.Uninitialized);
                                }
                                removedActivityAction.OriginalRemovedActivity.OnActivityExecutionContextUnload(executionContext.Activity.RootActivity.WorkflowCoreRuntime);
                                removedActivityAction.OriginalRemovedActivity.Dispose();
                            }
                        }
                    }
                }
            }
        }
        internal void RegisterWithRuntime(WorkflowRuntime workflowRuntime)
        {
            _isInstanceValid = true;
            _runtime = workflowRuntime;
            using (new ServiceEnvironment(this.rootActivity))
            {
                using (SetCurrentActivity(this.rootActivity))
                {
                    using (ActivityExecutionContext executionContext = new ActivityExecutionContext(this.rootActivity, true))
                        executionContext.InitializeActivity(this.rootActivity);
                }

                //
                // Tell the runtime that the instance is ready 
                // so that internal components can set up event subscriptions
                this._runtime.WorkflowExecutorCreated(this, false);

                //
                // Fire first events
                FireWorkflowExecutionEvent(this, WorkflowEventInternal.Creating);
            }
        }
 internal void RegisterWithRuntime(System.Workflow.Runtime.WorkflowRuntime workflowRuntime)
 {
     this._isInstanceValid = true;
     this._runtime = workflowRuntime;
     using (new ServiceEnvironment(this.rootActivity))
     {
         using (this.SetCurrentActivity(this.rootActivity))
         {
             using (ActivityExecutionContext context = new ActivityExecutionContext(this.rootActivity, true))
             {
                 context.InitializeActivity(this.rootActivity);
             }
         }
         this._runtime.WorkflowExecutorCreated(this, false);
         this.FireWorkflowExecutionEvent(this, WorkflowEventInternal.Creating);
     }
 }
        public void Initialize(Activity definition, IDictionary<string, object> inputs, bool hasNameCollision)
        {
            this.rootActivity.SetValue(Activity.ActivityExecutionContextInfoProperty,
                new ActivityExecutionContextInfo(this.rootActivity.QualifiedName, this.GetNewContextActivityId(), instanceId, -1));
            this.rootActivity.SetValue(Activity.ActivityContextGuidProperty, instanceId);

            SetInputParameters(definition, this.rootActivity, inputs, hasNameCollision);

            ((IDependencyObjectAccessor)this.rootActivity).InitializeActivatingInstanceForRuntime(
                null,
                this);

            this.rootActivity.FixUpMetaProperties(definition);

            TimerQueue = new TimerEventSubscriptionCollection(this, this.instanceId);

            using (new ServiceEnvironment(this.rootActivity))
            {
                using (SetCurrentActivity(this.rootActivity))
                {
                    RegisterContextActivity(this.rootActivity);

                    using (ActivityExecutionContext executionContext = new ActivityExecutionContext(this.rootActivity, true))
                    {
                        executionContext.InitializeActivity(this.rootActivity);
                    }
                }
            }
        }
 public ActivityExecutionContext CreateExecutionContext(Activity activity)
 {
     ActivityExecutionContext context2;
     if (this.ownerContext == null)
     {
         throw new ObjectDisposedException("ActivityExecutionContextManager");
     }
     if (activity == null)
     {
         throw new ArgumentNullException("activity");
     }
     if (!this.ownerContext.IsValidChild(activity, true))
     {
         throw new ArgumentException(SR.GetString("AEC_InvalidActivity"), "activity");
     }
     Activity item = activity.Clone();
     ((IDependencyObjectAccessor) item).InitializeInstanceForRuntime(this.ownerContext.Activity.WorkflowCoreRuntime);
     Queue<Activity> queue = new Queue<Activity>();
     queue.Enqueue(item);
     while (queue.Count != 0)
     {
         Activity activity3 = queue.Dequeue();
         if (activity3.ExecutionStatus != ActivityExecutionStatus.Initialized)
         {
             activity3.ResetAllKnownDependencyProperties();
             CompositeActivity activity4 = activity3 as CompositeActivity;
             if (activity4 != null)
             {
                 for (int i = 0; i < activity4.EnabledActivities.Count; i++)
                 {
                     queue.Enqueue(activity4.EnabledActivities[i]);
                 }
                 ISupportAlternateFlow flow = activity4;
                 if (flow != null)
                 {
                     for (int j = 0; j < flow.AlternateFlowActivities.Count; j++)
                     {
                         queue.Enqueue(flow.AlternateFlowActivities[j]);
                     }
                 }
             }
         }
     }
     IList<Activity> list = (IList<Activity>) this.ownerContext.Activity.ContextActivity.GetValue(Activity.ActiveExecutionContextsProperty);
     if (list == null)
     {
         list = new List<Activity>();
         this.ownerContext.Activity.ContextActivity.SetValue(Activity.ActiveExecutionContextsProperty, list);
     }
     list.Add(item);
     ActivityExecutionContextInfo info = new ActivityExecutionContextInfo(activity.QualifiedName, this.ownerContext.WorkflowCoreRuntime.GetNewContextActivityId(), Guid.NewGuid(), this.ownerContext.ContextId);
     item.SetValue(Activity.ActivityExecutionContextInfoProperty, info);
     item.SetValue(Activity.ActivityContextGuidProperty, info.ContextGuid);
     ActivityExecutionContext context = null;
     try
     {
         this.ownerContext.Activity.WorkflowCoreRuntime.RegisterContextActivity(item);
         context = new ActivityExecutionContext(item);
         this.executionContexts.Add(context);
         context.InitializeActivity(context.Activity);
         context2 = context;
     }
     catch (Exception)
     {
         if (context != null)
         {
             this.CompleteExecutionContext(context);
         }
         else
         {
             list.Remove(item);
         }
         throw;
     }
     return context2;
 }