internal bool LoadJobWithIdentifier(PSWorkflowId storedInstanceId) { PSWorkflowInstance instance = _runtime.Configuration.CreatePSWorkflowInstance(storedInstanceId); try { instance.InstanceStore.Load(WorkflowStoreComponents.JobState | WorkflowStoreComponents.Metadata); } catch (Exception e) { Tracer.TraceException(e); instance.JobStateRetrieved = false; instance.PSWorkflowContext = new PSWorkflowContext(); } if (!instance.JobStateRetrieved) { instance.RemoveInstance(); return false; } string command; string name; Guid instanceId; if (!WorkflowJobSourceAdapter.GetJobInfoFromMetadata(instance, out command, out name, out instanceId)) { instance.RemoveInstance(); return false; } if (instance.Timer != null) { if (instance.Timer.CheckIfTimerHasReachedAlready(WorkflowTimerType.ElapsedTimer)) { instance.RemoveInstance(); return false; } // starting the elapsed timer immediately. instance.Timer.StartTimer(WorkflowTimerType.ElapsedTimer); } if (_wfJobTable.ContainsKey(instanceId)) { return true; } lock (lockObjects.GetLockObject(instanceId)) { if (_wfJobTable.ContainsKey(instanceId)) { return true; } PSWorkflowJob newjob = new PSWorkflowJob(_runtime, command, name, instanceId); newjob.PSWorkflowInstance = instance; instance.PSWorkflowJob = newjob; newjob.RestoreFromWorkflowInstance(instance); newjob.WorkflowInstanceLoaded = true; newjob.ConfigureWorkflowHandlers(); if (!_wfJobTable.ContainsKey(newjob.InstanceId)) { AddJob(newjob); } return true; } }
/// <summary> /// Workflow instance constructor for shutdown or crashed workflows. /// </summary> /// <param name="runtime"></param> /// <param name="instanceId"></param> internal PSWorkflowApplicationInstance(PSWorkflowRuntime runtime, PSWorkflowId instanceId) { Tracer.WriteMessage("Creating Workflow instance after crash and shutdown workflow."); InitializePSWorkflowApplicationInstance(runtime); this._definition = null; this._metadatas = null; this._streams = null; this._timers = null; this.id = instanceId.Guid; this.creationMode = WorkflowInstanceCreationMode.AfterCrashOrShutdown; _stores = Runtime.Configuration.CreatePSWorkflowInstanceStore(this); this._remoteActivityState = null; }
/// <summary> /// LoadJob /// </summary> /// <param name="storedInstanceId"></param> /// <returns></returns> public PSWorkflowJob LoadJob(PSWorkflowId storedInstanceId) { AssertNotDisposed(); if (storedInstanceId == null) throw new ArgumentNullException("storedInstanceId"); if(LoadJobWithIdentifier(storedInstanceId)) { return Get(null, storedInstanceId.Guid); } return null; }
public virtual PSWorkflowInstance CreatePSWorkflowInstance(PSWorkflowId instanceId) { return(new PSWorkflowApplicationInstance(this.Runtime, instanceId)); }
internal bool LoadJobWithIdentifier(PSWorkflowId storedInstanceId) { string str = null; string str1 = null; Guid guid; bool flag; PSWorkflowInstance pSWorkflowContext = this._runtime.Configuration.CreatePSWorkflowInstance(storedInstanceId); try { pSWorkflowContext.InstanceStore.Load(WorkflowStoreComponents.Metadata | WorkflowStoreComponents.JobState); } catch (Exception exception1) { Exception exception = exception1; PSWorkflowJobManager.Tracer.TraceException(exception); pSWorkflowContext.JobStateRetrieved = false; pSWorkflowContext.PSWorkflowContext = new PSWorkflowContext(); } if (pSWorkflowContext.JobStateRetrieved) { if (WorkflowJobSourceAdapter.GetJobInfoFromMetadata(pSWorkflowContext, out str, out str1, out guid)) { if (pSWorkflowContext.Timer != null) { if (!pSWorkflowContext.Timer.CheckIfTimerHasReachedAlready(WorkflowTimerType.ElapsedTimer)) { pSWorkflowContext.Timer.StartTimer(WorkflowTimerType.ElapsedTimer); } else { pSWorkflowContext.RemoveInstance(); return false; } } if (!this._wfJobTable.ContainsKey(guid)) { lock (this.lockObjects.GetLockObject(guid)) { if (!this._wfJobTable.ContainsKey(guid)) { PSWorkflowJob pSWorkflowJob = new PSWorkflowJob(this._runtime, str, str1, guid); pSWorkflowJob.PSWorkflowInstance = pSWorkflowContext; pSWorkflowContext.PSWorkflowJob = pSWorkflowJob; pSWorkflowJob.RestoreFromWorkflowInstance(pSWorkflowContext); pSWorkflowJob.WorkflowInstanceLoaded = true; pSWorkflowJob.ConfigureWorkflowHandlers(); if (!this._wfJobTable.ContainsKey(pSWorkflowJob.InstanceId)) { this.AddJob(pSWorkflowJob); } flag = true; } else { flag = true; } } return flag; } else { return true; } } else { pSWorkflowContext.RemoveInstance(); return false; } } else { pSWorkflowContext.RemoveInstance(); return false; } }
public PSWorkflowJob LoadJob(PSWorkflowId storedInstanceId) { if (storedInstanceId != null) { if (!this.LoadJobWithIdentifier(storedInstanceId)) { return null; } else { Guid? nullable = null; return this.Get(nullable, new Guid?(storedInstanceId.Guid)); } } else { throw new ArgumentNullException("storedInstanceId"); } }
internal PSWorkflowApplicationInstance(PSWorkflowRuntime runtime, PSWorkflowId instanceId) { this.Tracer = PowerShellTraceSourceFactory.GetTraceSource(); this.wfAppNeverLoaded = true; this.ReactivateSync = new object(); if (runtime != null) { this.Tracer.WriteMessage("Creating Workflow instance after crash and shutdown workflow."); this._definition = null; this._metadatas = null; this._streams = null; this._timers = null; this.id = instanceId.Guid; this.creationMode = WorkflowInstanceCreationMode.AfterCrashOrShutdown; this.PersistAfterNextPSActivity = false; this.suspendAtNextCheckpoint = false; base.Runtime = runtime; this._stores = base.Runtime.Configuration.CreatePSWorkflowInstanceStore(this); this.asyncExecutionCollection = new Dictionary<string, PSActivityContext>(); base.ForceDisableStartOrEndPersistence = false; return; } else { throw new ArgumentNullException("runtime"); } }