Exemplo n.º 1
0
        // Used to recreate the root schedule executor from its persisted state
        private void ReloadHelper(Activity rootActivity)
        {
            // assign activity state
            this.rootActivity = rootActivity;
            this.InstanceId = (Guid)rootActivity.GetValue(WorkflowInstanceIdProperty);

            // set workflow executor
            this.rootActivity.SetValue(WorkflowExecutor.WorkflowExecutorProperty, this);

            this._schedulerLock = LockFactory.CreateWorkflowSchedulerLock(this.InstanceId);

            this.schedulingContext = new Scheduler(this, false);
            this.qService = new WorkflowQueuingService(this);

            WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "Workflow Runtime: WorkflowExecutor: Loading instance {0}", this.InstanceIdString);
            DiagnosticStackTrace("load request");

            using (new ServiceEnvironment(this.rootActivity))
            {

                // check if this instance can be loaded
                switch (this.WorkflowStatus)
                {
                    case WorkflowStatus.Completed:
                    case WorkflowStatus.Terminated:
                        WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "Workflow Runtime: WorkflowExecutor: attempt to load a completed/terminated instance: {0}", this.InstanceIdString);
                        throw new InvalidOperationException(
                            ExecutionStringManager.InvalidAttemptToLoad);

                    default:
                        break;
                }

                // new nonSerialized members
                _resourceManager = new VolatileResourceManager();
                _runtime = _workflowInstance.WorkflowRuntime;

                // register all dynamic activities for loading
                Queue<Activity> dynamicActivitiesQueue = new Queue<Activity>();
                dynamicActivitiesQueue.Enqueue(this.rootActivity);
                while (dynamicActivitiesQueue.Count > 0)
                {
                    Activity dynamicActivity = dynamicActivitiesQueue.Dequeue();
                    ((IDependencyObjectAccessor)dynamicActivity).InitializeInstanceForRuntime(this);
                    this.RegisterDynamicActivity(dynamicActivity, true);

                    IList<Activity> nestedDynamicActivities = (IList<Activity>)dynamicActivity.GetValue(Activity.ActiveExecutionContextsProperty);
                    if (nestedDynamicActivities != null)
                    {
                        foreach (Activity nestedDynamicActivity in nestedDynamicActivities)
                            dynamicActivitiesQueue.Enqueue(nestedDynamicActivity);
                    }
                }
            }

            this.isInstanceIdle = (bool)this.rootActivity.GetValue(IsIdleProperty);
            RefreshWorkflowDefinition();
        }
 public void AddResourceManager(VolatileResourceManager resourceManager)
 {
     this.Activity.AddResourceManager(this.nativeActivityContext, resourceManager);
 }
 private void ReloadHelper(Activity rootActivity)
 {
     this.rootActivity = rootActivity;
     this.InstanceId = (Guid) rootActivity.GetValue(WorkflowInstanceIdProperty);
     this.rootActivity.SetValue(WorkflowExecutorProperty, this);
     this._schedulerLock = LockFactory.CreateWorkflowSchedulerLock(this.InstanceId);
     this.schedulingContext = new System.Workflow.Runtime.Scheduler(this, false);
     this.qService = new WorkflowQueuingService(this);
     WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "Workflow Runtime: WorkflowExecutor: Loading instance {0}", new object[] { this.InstanceIdString });
     using (new ServiceEnvironment(this.rootActivity))
     {
         switch (this.WorkflowStatus)
         {
             case System.Workflow.Runtime.WorkflowStatus.Completed:
             case System.Workflow.Runtime.WorkflowStatus.Terminated:
                 WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "Workflow Runtime: WorkflowExecutor: attempt to load a completed/terminated instance: {0}", new object[] { this.InstanceIdString });
                 throw new InvalidOperationException(ExecutionStringManager.InvalidAttemptToLoad);
         }
         this._resourceManager = new VolatileResourceManager();
         this._runtime = this._workflowInstance.WorkflowRuntime;
         Queue<Activity> queue = new Queue<Activity>();
         queue.Enqueue(this.rootActivity);
         while (queue.Count > 0)
         {
             Activity dynamicActivity = queue.Dequeue();
             ((IDependencyObjectAccessor) dynamicActivity).InitializeInstanceForRuntime(this);
             this.RegisterDynamicActivity(dynamicActivity, true);
             IList<Activity> list = (IList<Activity>) dynamicActivity.GetValue(Activity.ActiveExecutionContextsProperty);
             if (list != null)
             {
                 foreach (Activity activity2 in list)
                 {
                     queue.Enqueue(activity2);
                 }
             }
         }
     }
     this.isInstanceIdle = (bool) this.rootActivity.GetValue(IsIdleProperty);
     this.RefreshWorkflowDefinition();
 }
        void PrivateInitialize(Activity rootActivity, Guid instanceId, IList<PropertyInfo> outputProperties, Activity workflowDefinition)
        {
            this.instanceId = instanceId;
            this.rootActivity = rootActivity;
            this.contextActivityMap = new Dictionary<int, Activity>();
            this.scheduler = new Scheduler(this);
            this.workflowQueuingService = new WorkflowQueuingService(this);
            this.outputProperties = outputProperties;
            this.resourceManager = new VolatileResourceManager();

            this.rootActivity.SetValue(System.Workflow.ComponentModel.Activity.WorkflowDefinitionProperty, workflowDefinition);
            this.rootActivity.SetValue(WorkflowExecutor.WorkflowExecutorProperty, this);
        }