internal WorkflowInstance(Guid instanceId, System.Workflow.Runtime.WorkflowRuntime workflowRuntime)
 {
     if (instanceId == Guid.Empty)
     {
         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, ExecutionStringManager.CantBeEmptyGuid, new object[] { "instanceId" }));
     }
     if (workflowRuntime == null)
     {
         throw new ArgumentNullException("workflowRuntime");
     }
     this._instanceId = instanceId;
     this._runtime = workflowRuntime;
 }
 internal WorkflowInstance(Guid instanceId, System.Workflow.Runtime.WorkflowRuntime workflowRuntime)
 {
     if (instanceId == Guid.Empty)
     {
         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, ExecutionStringManager.CantBeEmptyGuid, new object[] { "instanceId" }));
     }
     if (workflowRuntime == null)
     {
         throw new ArgumentNullException("workflowRuntime");
     }
     this._instanceId = instanceId;
     this._runtime    = workflowRuntime;
 }
 internal void ReRegisterWithRuntime(System.Workflow.Runtime.WorkflowRuntime workflowRuntime)
 {
     using (new SchedulerLockGuard(this._schedulerLock, this))
     {
         this._isInstanceValid = true;
         this._runtime = workflowRuntime;
         using (new ServiceEnvironment(this.rootActivity))
         {
             this._runtime.WorkflowExecutorCreated(this, true);
             this.TimerQueue.Executor = this;
             this.TimerQueue.ResumeDelivery();
             if (this.WorkflowStatus == System.Workflow.Runtime.WorkflowStatus.Running)
             {
                 this.Scheduler.CanRun = true;
             }
             this.FireWorkflowExecutionEvent(this, WorkflowEventInternal.Loading);
         }
     }
 }
 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 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);
     }
 }
 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);
         }
     }
 }
 internal void Initialize(Activity rootActivity, System.Workflow.Runtime.WorkflowRuntime runtime, WorkflowExecutor previousWorkflowExecutor)
 {
     this._workflowInstance = previousWorkflowExecutor.WorkflowInstance;
     this.ReloadHelper(rootActivity);
     this.IsInstanceValid = true;
     this._runtime = runtime;
     this._runtime.WorkflowExecutorCreated(this, true);
     this.TimerQueue.Executor = this;
     this.TimerQueue.ResumeDelivery();
     this._executorLock = previousWorkflowExecutor._executorLock;
     this._msgDeliveryLock = previousWorkflowExecutor._msgDeliveryLock;
     this._schedulerLock = previousWorkflowExecutor._schedulerLock;
     ScheduleWork.Executor = this;
 }