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> /// 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; }
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; } }
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 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); }