private void AutoRemoveJobIfRequired(System.Management.Automation.Job job)
 {
     if ((this._autoRemoveJob && this._jobsSpecifiedInParameters.Contains(job.InstanceId)) && job.IsFinishedState(job.JobStateInfo.State))
     {
         if (job.HasMoreData)
         {
             this._tracer.WriteMessage("ReceiveJobCommand", "AutoRemoveJobIfRequired", Guid.Empty, job, "Job has data and is being removed.", new string[0]);
         }
         Job2 job2 = job as Job2;
         if (job2 != null)
         {
             try
             {
                 base.JobManager.RemoveJob(job2, this, false, true);
                 job.Dispose();
             }
             catch (Exception exception)
             {
                 this.AddRemoveErrorToResults(job2, exception);
             }
         }
         else
         {
             try
             {
                 base.JobRepository.Remove(job);
                 job.Dispose();
             }
             catch (ArgumentException exception2)
             {
                 this.AddRemoveErrorToResults(job, exception2);
             }
         }
     }
 }
Beispiel #2
0
 private void RemoveJobAndDispose(System.Management.Automation.Job job, bool jobIsJob2)
 {
     try
     {
         if (jobIsJob2)
         {
             base.JobManager.RemoveJob(job as Job2, this, true, false);
         }
         else
         {
             base.JobRepository.Remove(job);
         }
         job.Dispose();
     }
     catch (ArgumentException exception)
     {
         ArgumentException exception2 = new ArgumentException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.CannotRemoveJob, new object[0]), exception);
         base.WriteError(new ErrorRecord(exception2, "CannotRemoveJob", ErrorCategory.InvalidOperation, job));
     }
 }
Beispiel #3
0
        private void childJob_StateChanged(object sender, JobStateEventArgs e)
        {
            Job completedChildJob = (Job)sender;

            if ((e.PreviousJobStateInfo.State == JobState.Blocked) && (e.JobStateInfo.State != JobState.Blocked))
            {
                bool flag = false;
                lock (this._lockObject)
                {
                    this._countOfBlockedChildJobs--;
                    if (this._countOfBlockedChildJobs == 0)
                    {
                        flag = true;
                    }
                }
                if (flag)
                {
                    base.SetJobState(JobState.Running);
                }
            }
            switch (e.JobStateInfo.State)
            {
            case JobState.Completed:
            case JobState.Failed:
            case JobState.Stopped:
                completedChildJob.StateChanged -= new EventHandler <JobStateEventArgs>(this.childJob_StateChanged);
                this.MakeRoomForRunningOtherJobs(completedChildJob);
                lock (this._lockObject)
                {
                    if (e.JobStateInfo.State == JobState.Failed)
                    {
                        this._countOfFailedChildJobs++;
                    }
                    else if (e.JobStateInfo.State == JobState.Stopped)
                    {
                        this._countOfStoppedChildJobs++;
                    }
                    else if (e.JobStateInfo.State == JobState.Completed)
                    {
                        this._countOfSuccessfullyCompletedChildJobs++;
                    }
                    if (this._actionsForUnblockingChildAdditions.Count > 0)
                    {
                        Action action = this._actionsForUnblockingChildAdditions.Dequeue();
                        if (action != null)
                        {
                            action();
                        }
                    }
                    if (this._cmdletMode)
                    {
                        foreach (PSStreamObject obj2 in completedChildJob.Results.ReadAll())
                        {
                            base.Results.Add(obj2);
                        }
                        base.ChildJobs.Remove(completedChildJob);
                        this._setOfChildJobsThatCanAddMoreChildJobs.Remove(completedChildJob.InstanceId);
                        completedChildJob.Dispose();
                    }
                }
                this.ReportProgress(!this.IsThrottlingJobCompleted);
                break;

            case JobState.Blocked:
                lock (this._lockObject)
                {
                    this._countOfBlockedChildJobs++;
                }
                base.SetJobState(JobState.Blocked);
                break;
            }
            this.FigureOutIfThrottlingJobIsCompleted();
        }