Ejemplo n.º 1
0
 protected Job()
 {
     this.stateInfo     = new System.Management.Automation.JobStateInfo(JobState.NotStarted);
     this.finished      = new ManualResetEvent(false);
     this.guid          = Guid.NewGuid();
     this.syncObject    = new object();
     this.results       = new PSDataCollection <PSStreamObject>();
     this.resultsOwner  = true;
     this.error         = new PSDataCollection <ErrorRecord>();
     this.errorOwner    = true;
     this.progress      = new PSDataCollection <ProgressRecord>();
     this.progressOwner = true;
     this.verbose       = new PSDataCollection <VerboseRecord>();
     this.verboseOwner  = true;
     this.warning       = new PSDataCollection <WarningRecord>();
     this.warningOwner  = true;
     this.debug         = new PSDataCollection <DebugRecord>();
     this.debugOwner    = true;
     this.output        = new PSDataCollection <PSObject>();
     this.outputOwner   = true;
     this._beginTime    = null;
     this._endTime      = null;
     this._jobTypeName  = string.Empty;
     this.sessionId     = Interlocked.Increment(ref _jobIdSeed);
 }
Ejemplo n.º 2
0
 public JobStateEventArgs(System.Management.Automation.JobStateInfo jobStateInfo, System.Management.Automation.JobStateInfo previousJobStateInfo)
 {
     if (jobStateInfo == null)
     {
         throw PSTraceSource.NewArgumentNullException("jobStateInfo");
     }
     this._jobStateInfo = jobStateInfo;
     this._previousJobStateInfo = previousJobStateInfo;
 }
Ejemplo n.º 3
0
 public JobStateEventArgs(System.Management.Automation.JobStateInfo jobStateInfo, System.Management.Automation.JobStateInfo previousJobStateInfo)
 {
     if (jobStateInfo == null)
     {
         throw PSTraceSource.NewArgumentNullException("jobStateInfo");
     }
     this._jobStateInfo         = jobStateInfo;
     this._previousJobStateInfo = previousJobStateInfo;
 }
Ejemplo n.º 4
0
 internal void SetJobState(JobState state, Exception reason)
 {
     using (PowerShellTraceSource source = PowerShellTraceSourceFactory.GetTraceSource())
     {
         this.AssertNotDisposed();
         bool flag = false;
         System.Management.Automation.JobStateInfo stateInfo = this.stateInfo;
         lock (this.syncObject)
         {
             this.stateInfo = new System.Management.Automation.JobStateInfo(state, reason);
             if (state == JobState.Running)
             {
                 if (!this.PSBeginTime.HasValue)
                 {
                     this.PSBeginTime = new DateTime?(DateTime.Now);
                 }
             }
             else if (this.IsFinishedState(state))
             {
                 flag = true;
                 if (!this.PSEndTime.HasValue)
                 {
                     this.PSEndTime = new DateTime?(DateTime.Now);
                 }
             }
         }
         if (flag)
         {
             this.CloseAllStreams();
         }
         try
         {
             source.WriteMessage("Job", "SetJobState", Guid.Empty, this, "Invoking StateChanged event", null);
             this.StateChanged.SafeInvoke <JobStateEventArgs>(this, new JobStateEventArgs(this.stateInfo.Clone(), stateInfo));
         }
         catch (Exception exception)
         {
             source.WriteMessage("Job", "SetJobState", Guid.Empty, this, "Some Job StateChange event handler threw an unhandled exception.", null);
             source.TraceException(exception);
             CommandProcessorBase.CheckForSevereException(exception);
         }
         if (flag)
         {
             lock (this.syncObject)
             {
                 if (this.finished != null)
                 {
                     this.finished.Set();
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 protected Job(string command, string name, JobIdentifier token)
 {
     this.stateInfo     = new System.Management.Automation.JobStateInfo(JobState.NotStarted);
     this.finished      = new ManualResetEvent(false);
     this.guid          = Guid.NewGuid();
     this.syncObject    = new object();
     this.results       = new PSDataCollection <PSStreamObject>();
     this.resultsOwner  = true;
     this.error         = new PSDataCollection <ErrorRecord>();
     this.errorOwner    = true;
     this.progress      = new PSDataCollection <ProgressRecord>();
     this.progressOwner = true;
     this.verbose       = new PSDataCollection <VerboseRecord>();
     this.verboseOwner  = true;
     this.warning       = new PSDataCollection <WarningRecord>();
     this.warningOwner  = true;
     this.debug         = new PSDataCollection <DebugRecord>();
     this.debugOwner    = true;
     this.output        = new PSDataCollection <PSObject>();
     this.outputOwner   = true;
     this._beginTime    = null;
     this._endTime      = null;
     this._jobTypeName  = string.Empty;
     if (token == null)
     {
         throw PSTraceSource.NewArgumentNullException("token", "remotingerroridstrings", "JobIdentifierNull", new object[0]);
     }
     if (token.Id > _jobIdSeed)
     {
         throw PSTraceSource.NewArgumentException("token", "remotingerroridstrings", "JobIdNotYetAssigned", new object[] { token.Id });
     }
     this.command   = command;
     this.sessionId = token.Id;
     this.guid      = token.InstanceId;
     if (!string.IsNullOrEmpty(name))
     {
         this.name = name;
     }
     else
     {
         this.name = this.AutoGenerateJobName();
     }
 }
Ejemplo n.º 6
0
 public JobStateEventArgs(System.Management.Automation.JobStateInfo jobStateInfo) : this(jobStateInfo, null)
 {
 }