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(); }
internal void Initialize(Activity rootActivity, WorkflowExecutor invokerExec, string invokeActivityID, Guid instanceId, IDictionary<string, object> namedArguments, System.Workflow.Runtime.WorkflowInstance workflowInstance) { this.rootActivity = rootActivity; this.InstanceId = instanceId; this.rootActivity.SetValue(ContextIdProperty, 0); this.rootActivity.SetValue(WorkflowInstanceIdProperty, instanceId); this.WorkflowStatus = System.Workflow.Runtime.WorkflowStatus.Created; this.rootActivity.SetValue(Activity.ActivityExecutionContextInfoProperty, new ActivityExecutionContextInfo(this.rootActivity.QualifiedName, this.GetNewContextId(), instanceId, -1)); this.rootActivity.SetValue(Activity.ActivityContextGuidProperty, instanceId); this.rootActivity.SetValue(IsIdleProperty, true); this.isInstanceIdle = true; this.rootActivity.SetValue(WorkflowExecutorProperty, this); this.RefreshWorkflowDefinition(); Activity workflowDefinition = this.WorkflowDefinition; if (workflowDefinition == null) { throw new InvalidOperationException("workflowDefinition"); } ((IDependencyObjectAccessor) this.rootActivity).InitializeActivatingInstanceForRuntime(null, this); this.rootActivity.FixUpMetaProperties(workflowDefinition); this._runtime = workflowInstance.WorkflowRuntime; if (invokerExec != null) { List<string> list = new List<string>(); System.Workflow.Runtime.TrackingCallingState state = (System.Workflow.Runtime.TrackingCallingState) invokerExec.rootActivity.GetValue(TrackingCallingStateProperty); if ((state != null) && (state.CallerActivityPathProxy != null)) { foreach (string str in state.CallerActivityPathProxy) { list.Add(str); } } list.Add(invokeActivityID); System.Workflow.Runtime.TrackingCallingState state2 = new System.Workflow.Runtime.TrackingCallingState { CallerActivityPathProxy = list, CallerWorkflowInstanceId = invokerExec.InstanceId, CallerContextGuid = ((ActivityExecutionContextInfo) ContextActivityUtils.ContextActivity(invokerExec.CurrentActivity).GetValue(Activity.ActivityExecutionContextInfoProperty)).ContextGuid }; if (invokerExec.CurrentActivity.Parent == null) { state2.CallerParentContextGuid = state2.CallerContextGuid; } else { state2.CallerParentContextGuid = ((ActivityExecutionContextInfo) ContextActivityUtils.ContextActivity(invokerExec.CurrentActivity.Parent).GetValue(Activity.ActivityExecutionContextInfoProperty)).ContextGuid; } this.rootActivity.SetValue(TrackingCallingStateProperty, state2); } this._setInArgsOnCompanion(namedArguments); this.schedulingContext = new System.Workflow.Runtime.Scheduler(this, true); this._schedulerLock = LockFactory.CreateWorkflowSchedulerLock(this.InstanceId); this.qService = new WorkflowQueuingService(this); this._workflowInstance = workflowInstance; this.TimerQueue = new TimerEventSubscriptionCollection(this, this.InstanceId); using (new ServiceEnvironment(this.rootActivity)) { using (this.SetCurrentActivity(this.rootActivity)) { this.RegisterDynamicActivity(this.rootActivity, false); } } }