Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
		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");
			}
		}
Exemplo n.º 3
0
        /// <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;
        }
Exemplo n.º 4
0
		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);
		}