private void CreateChildJob(JobInvocationInfo specification, Activity activity, ContainerParentJob newJob, CommandParameterCollection commandParameterCollection, Dictionary<string, object> parameterDictionary, string computerName, string[] computerNames) { if (!string.IsNullOrEmpty(computerName)) { string[] childTargetComputerList = { computerName }; // Set the target computer for this child job... parameterDictionary[Constants.ComputerName] = childTargetComputerList; } var childSpecification = new JobInvocationInfo(specification.Definition, parameterDictionary); // Job objects will be disposed of on parent job removal. var childJob = new PSWorkflowJob(_runtime, childSpecification); childJob.JobMetadata = CreateJobMetadata(childJob, newJob.InstanceId, newJob.Id, newJob.Name, newJob.Command, computerNames); // Remove the parameter from the collection... for (int index = 0; index < commandParameterCollection.Count; index++) { if (string.Equals(commandParameterCollection[index].Name, Constants.ComputerName, StringComparison.OrdinalIgnoreCase)) { commandParameterCollection.RemoveAt(index); break; } } if (!string.IsNullOrEmpty(computerName)) { var computerNameParameter = new CommandParameter(Constants.ComputerName, computerName); commandParameterCollection.Add(computerNameParameter); } this.AddJob(childJob); childJob.LoadWorkflow(commandParameterCollection, activity, null); newJob.AddChildJob(childJob); StructuredTracer.ChildWorkflowJobAddition(childJob.InstanceId, newJob.InstanceId); Tracer.TraceJob(childJob); StructuredTracer.WorkflowJobCreated(newJob.InstanceId, childJob.InstanceId, childJob.WorkflowGuid); }
/// <summary> /// Workflow instance constructor. /// </summary> /// <param name="runtime"></param> /// <param name="definition">The workflow definition.</param> /// <param name="metadata">The metadata which includes parameters etc.</param> /// <param name="pipelineInput">This is input coming from pipeline, which is added to the input stream.</param> /// <param name="job"></param> internal PSWorkflowApplicationInstance( PSWorkflowRuntime runtime, PSWorkflowDefinition definition, PSWorkflowContext metadata, PSDataCollection<PSObject> pipelineInput, PSWorkflowJob job) { Tracer.WriteMessage("Creating Workflow instance."); InitializePSWorkflowApplicationInstance(runtime); this._definition = definition; this._metadatas = metadata; this._streams = new PowerShellStreams<PSObject, PSObject>(pipelineInput); RegisterHandlersForDataAdding(_streams); this._timers = new PSWorkflowTimer(this); this.creationMode = WorkflowInstanceCreationMode.Normal; _job = job; _stores = Runtime.Configuration.CreatePSWorkflowInstanceStore(this); this._remoteActivityState = new PSWorkflowRemoteActivityState(_stores); }
internal PSWorkflowJob CreateJobInternal(Guid jobInstanceId, Activity workflow, string command, string name, Dictionary<string, object> parameters, string xaml, Dictionary<string, object> creationContext) { AssertNotDisposed(); if (jobInstanceId == Guid.Empty) throw new ArgumentNullException("jobInstanceId"); if (workflow == null) throw new ArgumentNullException("workflow"); if (command == null) throw new ArgumentNullException("command"); if (name == null) throw new ArgumentNullException("name"); if (_wfJobTable.ContainsKey(jobInstanceId)) { ArgumentException exception = new ArgumentException(Resources.DuplicateInstanceId); Tracer.TraceException(exception); throw exception; } lock (lockObjects.GetLockObject(jobInstanceId)) { if (_wfJobTable.ContainsKey(jobInstanceId)) { ArgumentException exception = new ArgumentException(Resources.DuplicateInstanceId); Tracer.TraceException(exception); throw exception; } JobDefinition definition = new JobDefinition(typeof(WorkflowJobSourceAdapter), command, name); var parameterDictionary = new Dictionary<string, object>(StringComparer.CurrentCultureIgnoreCase); if (parameters != null) { foreach (KeyValuePair<string, object> param in parameters) { parameterDictionary.Add(param.Key, param.Value); } } string[] computerNames = null; bool gotComputerNames = false; object value; if (parameterDictionary.Count != 0 && parameterDictionary.TryGetValue(Constants.ComputerName, out value)) { if (LanguagePrimitives.TryConvertTo(value, CultureInfo.InvariantCulture, out computerNames)) gotComputerNames = computerNames != null; } if (gotComputerNames) { if (computerNames.Length > 1) throw new ArgumentException(Resources.OneComputerNameAllowed); parameterDictionary.Remove(Constants.ComputerName); } var childSpecification = new JobInvocationInfo(definition, parameterDictionary); childSpecification.Command = command; // If actual computernames were specified, then set the PSComputerName parameter. if (gotComputerNames) { var computerNameParameter = new CommandParameter(Constants.ComputerName, computerNames); childSpecification.Parameters[0].Add(computerNameParameter); } // Job objects will be disposed of on parent job removal. var childJob = new PSWorkflowJob(_runtime, childSpecification, jobInstanceId, creationContext); childJob.JobMetadata = CreateJobMetadataWithNoParentDefined(childJob, computerNames); childJob.LoadWorkflow(childSpecification.Parameters[0], workflow, xaml); this.AddJob(childJob); return childJob; } }
/// <summary> /// CreateJob /// </summary> /// <param name="jobInvocationInfo"></param> /// <param name="activity"></param> /// <returns></returns> internal ContainerParentJob CreateJob(JobInvocationInfo jobInvocationInfo, Activity activity) { if (jobInvocationInfo == null) throw new ArgumentNullException("jobInvocationInfo"); if (jobInvocationInfo.Definition == null) throw new ArgumentException(Resources.NewJobDefinitionNull, "jobInvocationInfo"); if (jobInvocationInfo.Command == null) throw new ArgumentException(Resources.NewJobDefinitionNull, "jobInvocationInfo"); DynamicActivity dynamicActivity = activity as DynamicActivity; Debug.Assert(dynamicActivity != null, "Passed workflow must be a DynamicActivity"); Tracer.WriteMessage(String.Format(CultureInfo.InvariantCulture, "WorkflowJobSourceAdapter: Creating Workflow job with definition: {0}", jobInvocationInfo.Definition.InstanceId)); // Create parent job. All PSWorkflowJob objects will be a child of some ContainerParentJob // This job will be disposed of when RemoveJob is called. ContainerParentJob newJob = new ContainerParentJob( jobInvocationInfo.Command, jobInvocationInfo.Name, WorkflowJobSourceAdapter.AdapterTypeName); foreach (CommandParameterCollection commandParameterCollection in jobInvocationInfo.Parameters) { var parameterDictionary = new Dictionary<string, object>(StringComparer.CurrentCultureIgnoreCase); foreach (CommandParameter param in commandParameterCollection) { parameterDictionary.Add(param.Name, param.Value); } string[] computerNames = null; bool gotComputerNames = false; object value; if (parameterDictionary.Count != 0 && parameterDictionary.TryGetValue(Constants.ComputerName, out value)) { if (LanguagePrimitives.TryConvertTo(value, CultureInfo.InvariantCulture, out computerNames)) gotComputerNames = computerNames != null; } StructuredTracer.ParentJobCreated(newJob.InstanceId); bool isComputerNameExists = false; if (dynamicActivity != null && dynamicActivity.Properties.Any(x => x.Name.Equals(Constants.ComputerName, StringComparison.CurrentCultureIgnoreCase))) { isComputerNameExists = true; } dynamicActivity = null; if (isComputerNameExists) { var childSpecification = new JobInvocationInfo(jobInvocationInfo.Definition, parameterDictionary); childSpecification.Command = newJob.Command; // If actual computernames were specified, then set the PSComputerName parameter. if (gotComputerNames) { var computerNameParameter = new CommandParameter(Constants.ComputerName, computerNames); childSpecification.Parameters[0].Add(computerNameParameter); } // Job objects will be disposed of on parent job removal. var childJob = new PSWorkflowJob(_runtime, childSpecification); childJob.JobMetadata = CreateJobMetadata(childJob, newJob.InstanceId, newJob.Id, newJob.Name, newJob.Command, computerNames); childJob.LoadWorkflow(commandParameterCollection, activity, null); this.AddJob(childJob); newJob.AddChildJob(childJob); StructuredTracer.ChildWorkflowJobAddition(childJob.InstanceId, newJob.InstanceId); StructuredTracer.WorkflowJobCreated(newJob.InstanceId, childJob.InstanceId, childJob.WorkflowGuid); } else { // Remove array of computerNames from collection. parameterDictionary.Remove(Constants.ComputerName); if (gotComputerNames) { foreach (var computerName in computerNames) { CreateChildJob(jobInvocationInfo, activity, newJob, commandParameterCollection, parameterDictionary, computerName, computerNames); } } else { CreateChildJob(jobInvocationInfo, activity, newJob, commandParameterCollection, parameterDictionary, null, computerNames); } } } StructuredTracer.JobCreationComplete(newJob.InstanceId, jobInvocationInfo.InstanceId); Tracer.TraceJob(newJob); return newJob; }
/// <summary> /// Add a job to the manager. /// </summary> /// <param name="job"></param> private void AddJob(PSWorkflowJob job) { Debug.Assert(job != null, "Null job passed"); if (_wfJobTable.ContainsKey(job.InstanceId)) { ArgumentException exception = new ArgumentException(Resources.DuplicateInstanceId); Tracer.TraceException(exception); throw exception; } _wfJobTable.TryAdd(job.InstanceId, job); }
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; } }
private static bool SearchAllFilterTypes(PSWorkflowJob job, WorkflowFilterTypes type, string key, out object value) { object obj = null; bool flag; PSWorkflowContext pSWorkflowContext = job.PSWorkflowInstance.PSWorkflowContext; value = null; if (pSWorkflowContext != null) { Dictionary<WorkflowFilterTypes, Dictionary<string, object>> workflowFilterTypes = new Dictionary<WorkflowFilterTypes, Dictionary<string, object>>(); workflowFilterTypes.Add(WorkflowFilterTypes.WorkflowSpecificParameters, pSWorkflowContext.WorkflowParameters); workflowFilterTypes.Add(WorkflowFilterTypes.JobMetadata, pSWorkflowContext.JobMetadata); workflowFilterTypes.Add(WorkflowFilterTypes.CommonParameters, pSWorkflowContext.PSWorkflowCommonParameters); workflowFilterTypes.Add(WorkflowFilterTypes.PrivateMetadata, pSWorkflowContext.PrivateMetadata); Dictionary<WorkflowFilterTypes, Dictionary<string, object>> workflowFilterTypes1 = workflowFilterTypes; Dictionary<WorkflowFilterTypes, Dictionary<string, object>>.KeyCollection.Enumerator enumerator = workflowFilterTypes1.Keys.GetEnumerator(); try { while (enumerator.MoveNext()) { WorkflowFilterTypes current = enumerator.Current; if (!type.HasFlag(current) || !PSWorkflowJobManager.SearchOneFilterType(workflowFilterTypes1[current], key, out obj)) { continue; } value = obj; flag = true; return flag; } return false; } finally { enumerator.Dispose(); } return flag; } else { return false; } }
private static bool SearchAllFilterTypes(PSWorkflowJob job, WorkflowFilterTypes type, string key, out object value) { PSWorkflowContext metadata = job.PSWorkflowInstance.PSWorkflowContext; value = null; if (metadata == null) return false; var searchTable = new Dictionary<WorkflowFilterTypes, Dictionary<string, object>> { {WorkflowFilterTypes.WorkflowSpecificParameters, metadata.WorkflowParameters}, {WorkflowFilterTypes.JobMetadata, metadata.JobMetadata}, {WorkflowFilterTypes.CommonParameters, metadata.PSWorkflowCommonParameters}, {WorkflowFilterTypes.PrivateMetadata, metadata.PrivateMetadata} }; foreach(var filter in searchTable.Keys) { object searchResult; if (!type.HasFlag(filter) || !SearchOneFilterType(searchTable[filter], key, out searchResult)) continue; value = searchResult; return true; } return false; }
internal PSWorkflowJob CreateJobInternal(Guid jobInstanceId, Activity workflow, string command, string name, Dictionary<string, object> parameters, string xaml) { object obj = null; PSWorkflowJob pSWorkflowJob; if (jobInstanceId != Guid.Empty) { if (workflow != null) { if (command != null) { if (name != null) { if (!this._wfJobTable.ContainsKey(jobInstanceId)) { lock (this.lockObjects.GetLockObject(jobInstanceId)) { if (!this._wfJobTable.ContainsKey(jobInstanceId)) { JobDefinition jobDefinition = new JobDefinition(typeof(WorkflowJobSourceAdapter), command, name); Dictionary<string, object> strs = new Dictionary<string, object>(StringComparer.CurrentCultureIgnoreCase); if (parameters != null) { foreach (KeyValuePair<string, object> parameter in parameters) { strs.Add(parameter.Key, parameter.Value); } } string[] strArrays = null; bool flag = false; if (strs.Count != 0 && strs.TryGetValue("PSComputerName", out obj) && LanguagePrimitives.TryConvertTo<string[]>(obj, CultureInfo.InvariantCulture, out strArrays)) { flag = strArrays != null; } if (flag) { if ((int)strArrays.Length <= 1) { strs.Remove("PSComputerName"); } else { throw new ArgumentException(Resources.OneComputerNameAllowed); } } JobInvocationInfo jobInvocationInfo = new JobInvocationInfo(jobDefinition, strs); jobInvocationInfo.Command = command; if (flag) { CommandParameter commandParameter = new CommandParameter("PSComputerName", strArrays); jobInvocationInfo.Parameters[0].Add(commandParameter); } PSWorkflowJob pSWorkflowJob1 = new PSWorkflowJob(this._runtime, jobInvocationInfo, jobInstanceId); pSWorkflowJob1.JobMetadata = PSWorkflowJobManager.CreateJobMetadataWithNoParentDefined(pSWorkflowJob1, strArrays); pSWorkflowJob1.LoadWorkflow(jobInvocationInfo.Parameters[0], workflow, xaml); this.AddJob(pSWorkflowJob1); pSWorkflowJob = pSWorkflowJob1; } else { ArgumentException argumentException = new ArgumentException(Resources.DuplicateInstanceId); PSWorkflowJobManager.Tracer.TraceException(argumentException); throw argumentException; } } return pSWorkflowJob; } else { ArgumentException argumentException1 = new ArgumentException(Resources.DuplicateInstanceId); PSWorkflowJobManager.Tracer.TraceException(argumentException1); throw argumentException1; } } else { throw new ArgumentNullException("name"); } } else { throw new ArgumentNullException("command"); } } else { throw new ArgumentNullException("workflow"); } } else { throw new ArgumentNullException("jobInstanceId"); } }
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; } }
internal ContainerParentJob CreateJob(JobInvocationInfo jobInvocationInfo, Activity activity) { object obj = null; if (jobInvocationInfo != null) { if (jobInvocationInfo.Definition != null) { if (jobInvocationInfo.Command != null) { DynamicActivity dynamicActivity = activity as DynamicActivity; object[] instanceId = new object[1]; instanceId[0] = jobInvocationInfo.Definition.InstanceId; PSWorkflowJobManager.Tracer.WriteMessage(string.Format(CultureInfo.InvariantCulture, "WorkflowJobSourceAdapter: Creating Workflow job with definition: {0}", instanceId)); ContainerParentJob containerParentJob = new ContainerParentJob(jobInvocationInfo.Command, jobInvocationInfo.Name, "PSWorkflowJob"); foreach (CommandParameterCollection commandParameterCollection in commandParameterCollection) { Dictionary<string, object> strs = new Dictionary<string, object>(StringComparer.CurrentCultureIgnoreCase); IEnumerator<CommandParameter> enumerator = commandParameterCollection.GetEnumerator(); using (enumerator) { while (enumerator.MoveNext()) { CommandParameter commandParameter = commandParameterCollection; strs.Add(commandParameter.Name, commandParameter.Value); } } string[] strArrays = null; bool flag = false; if (strs.Count != 0 && strs.TryGetValue("PSComputerName", out obj) && LanguagePrimitives.TryConvertTo<string[]>(obj, CultureInfo.InvariantCulture, out strArrays)) { flag = strArrays != null; } PSWorkflowJobManager.StructuredTracer.ParentJobCreated(containerParentJob.InstanceId); bool flag1 = false; if (dynamicActivity != null && dynamicActivity.Properties.Contains("PSComputerName")) { flag1 = true; } dynamicActivity = null; if (!flag1) { strs.Remove("PSComputerName"); if (!flag) { this.CreateChildJob(jobInvocationInfo, activity, containerParentJob, commandParameterCollection, strs, null, strArrays); } else { string[] strArrays1 = strArrays; for (int i = 0; i < (int)strArrays1.Length; i++) { string str = strArrays1[i]; this.CreateChildJob(jobInvocationInfo, activity, containerParentJob, commandParameterCollection, strs, str, strArrays); } } } else { JobInvocationInfo command = new JobInvocationInfo(jobInvocationInfo.Definition, strs); command.Command = containerParentJob.Command; if (flag) { CommandParameter commandParameter1 = new CommandParameter("PSComputerName", strArrays); command.Parameters[0].Add(commandParameter1); } PSWorkflowJob pSWorkflowJob = new PSWorkflowJob(this._runtime, command); pSWorkflowJob.JobMetadata = PSWorkflowJobManager.CreateJobMetadata(pSWorkflowJob, containerParentJob.InstanceId, containerParentJob.Id, containerParentJob.Name, containerParentJob.Command, strArrays); pSWorkflowJob.LoadWorkflow(commandParameterCollection, activity, null); this.AddJob(pSWorkflowJob); containerParentJob.AddChildJob(pSWorkflowJob); PSWorkflowJobManager.StructuredTracer.ChildWorkflowJobAddition(pSWorkflowJob.InstanceId, containerParentJob.InstanceId); PSWorkflowJobManager.StructuredTracer.WorkflowJobCreated(containerParentJob.InstanceId, pSWorkflowJob.InstanceId, pSWorkflowJob.WorkflowGuid); } } PSWorkflowJobManager.StructuredTracer.JobCreationComplete(containerParentJob.InstanceId, jobInvocationInfo.InstanceId); PSWorkflowJobManager.Tracer.TraceJob(containerParentJob); PSSQMAPI.InitiateWorkflowStateDataTracking(containerParentJob); return containerParentJob; } else { throw new ArgumentException(Resources.NewJobDefinitionNull, "jobInvocationInfo"); } } else { throw new ArgumentException(Resources.NewJobDefinitionNull, "jobInvocationInfo"); } } else { throw new ArgumentNullException("jobInvocationInfo"); } }
private void CreateChildJob(JobInvocationInfo specification, Activity activity, ContainerParentJob newJob, CommandParameterCollection commandParameterCollection, Dictionary<string, object> parameterDictionary, string computerName, string[] computerNames) { if (!string.IsNullOrEmpty(computerName)) { string[] strArrays = new string[1]; strArrays[0] = computerName; string[] strArrays1 = strArrays; parameterDictionary["PSComputerName"] = strArrays1; } JobInvocationInfo jobInvocationInfo = new JobInvocationInfo(specification.Definition, parameterDictionary); PSWorkflowJob pSWorkflowJob = new PSWorkflowJob(this._runtime, jobInvocationInfo); pSWorkflowJob.JobMetadata = PSWorkflowJobManager.CreateJobMetadata(pSWorkflowJob, newJob.InstanceId, newJob.Id, newJob.Name, newJob.Command, computerNames); int num = 0; while (num < commandParameterCollection.Count) { if (!string.Equals(commandParameterCollection[num].Name, "PSComputerName", StringComparison.OrdinalIgnoreCase)) { num++; } else { commandParameterCollection.RemoveAt(num); break; } } if (!string.IsNullOrEmpty(computerName)) { CommandParameter commandParameter = new CommandParameter("PSComputerName", computerName); commandParameterCollection.Add(commandParameter); } this.AddJob(pSWorkflowJob); pSWorkflowJob.LoadWorkflow(commandParameterCollection, activity, null); newJob.AddChildJob(pSWorkflowJob); PSWorkflowJobManager.StructuredTracer.ChildWorkflowJobAddition(pSWorkflowJob.InstanceId, newJob.InstanceId); PSWorkflowJobManager.Tracer.TraceJob(pSWorkflowJob); PSWorkflowJobManager.StructuredTracer.WorkflowJobCreated(newJob.InstanceId, pSWorkflowJob.InstanceId, pSWorkflowJob.WorkflowGuid); }
private void AddJob(PSWorkflowJob job) { if (!this._wfJobTable.ContainsKey(job.InstanceId)) { this._wfJobTable.TryAdd(job.InstanceId, job); return; } else { ArgumentException argumentException = new ArgumentException(Resources.DuplicateInstanceId); PSWorkflowJobManager.Tracer.TraceException(argumentException); throw argumentException; } }
internal PSWorkflowApplicationInstance(PSWorkflowRuntime runtime, PSWorkflowDefinition definition, PSWorkflowContext metadata, PSDataCollection<PSObject> pipelineInput, PSWorkflowJob job) { this.Tracer = PowerShellTraceSourceFactory.GetTraceSource(); this.wfAppNeverLoaded = true; this.ReactivateSync = new object(); if (runtime != null) { this.Tracer.WriteMessage("Creating Workflow instance."); this._definition = definition; this._metadatas = metadata; this._streams = new PowerShellStreams<PSObject, PSObject>(pipelineInput); this.RegisterHandlersForDataAdding(this._streams); this._timers = new PSWorkflowTimer(this); this.creationMode = WorkflowInstanceCreationMode.Normal; this.PersistAfterNextPSActivity = false; this.suspendAtNextCheckpoint = false; this._job = job; 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"); } }
private void JobActionWorker(AsyncOperation asyncOp, PSWorkflowJob.ActionType action, string reason, string label) { Exception exception = null; try { PSWorkflowJob.ActionType actionType = action; switch (actionType) { case PSWorkflowJob.ActionType.Start: { this.DoStartJobLogic(null); break; } case PSWorkflowJob.ActionType.Stop: { this.DoStopJob(); break; } case PSWorkflowJob.ActionType.Suspend: { this.DoSuspendJob(); break; } case PSWorkflowJob.ActionType.Resume: { this.DoResumeJob(label); break; } case PSWorkflowJob.ActionType.Abort: { this.DoAbortJob(reason); break; } case PSWorkflowJob.ActionType.Terminate: { this.DoTerminateJob(reason); break; } } } catch (Exception exception2) { Exception exception1 = exception2; exception = exception1; } AsyncCompletedEventArgs asyncCompletedEventArg = new AsyncCompletedEventArgs(exception, false, asyncOp.UserSuppliedState); PSWorkflowJob.AsyncCompleteContainer asyncCompleteContainer = new PSWorkflowJob.AsyncCompleteContainer(); asyncCompleteContainer.EventArgs = asyncCompletedEventArg; asyncCompleteContainer.Action = action; PSWorkflowJob.AsyncCompleteContainer asyncCompleteContainer1 = asyncCompleteContainer; asyncOp.PostOperationCompleted(new SendOrPostCallback(this.JobActionAsyncCompleted), asyncCompleteContainer1); }