Exemple #1
0
 internal void Update(ScheduledJob fromJob)
 {
     if (this._job != null || fromJob == null)
     {
         return;
     }
     else
     {
         base.PSEndTime = fromJob.PSEndTime;
         JobState state = fromJob.JobStateInfo.State;
         if (this.Status.State != state)
         {
             base.SetJobState(state, null);
         }
         lock (base.SyncRoot)
         {
             this._statusInfo = new StatusInfo(fromJob.InstanceId, fromJob.Name, fromJob.Location, fromJob.Command, fromJob.StatusMessage, state, fromJob.HasMoreData, fromJob.PSBeginTime, fromJob.PSEndTime, fromJob._jobDefinition);
         }
         this.CopyOutput(fromJob.Output);
         this.CopyError(fromJob.Error);
         this.CopyWarning(fromJob.Warning);
         this.CopyVerbose(fromJob.Verbose);
         this.CopyProgress(fromJob.Progress);
         this.CopyDebug(fromJob.Debug);
         return;
     }
 }
        private static void SaveStatusToFile(ScheduledJob job, FileStream fs)
        {
            StatusInfo          statusInfo = new StatusInfo(job.InstanceId, job.Name, job.Location, job.Command, job.StatusMessage, job.JobStateInfo.State, job.HasMoreData, job.PSBeginTime, job.PSEndTime, job.Definition);
            XmlObjectSerializer netDataContractSerializer = new NetDataContractSerializer();

            netDataContractSerializer.WriteObject(fs, statusInfo);
            fs.Flush();
        }
Exemple #3
0
        /// <summary>
        /// Starts a job as defined by the contained ScheduledJobDefinition object.
        /// </summary>
        public override void StartJob()
        {
            lock (SyncRoot)
            {
                if (_job != null && !IsFinishedState(_job.JobStateInfo.State))
                {
                    string msg = StringUtil.Format(ScheduledJobErrorStrings.JobAlreadyRunning, _jobDefinition.Name);
                    throw new PSInvalidOperationException(msg);
                }

                _statusInfo   = null;
                _asyncJobStop = false;
                PSBeginTime   = DateTime.Now;

                if (_powerShell == null)
                {
                    InitialSessionState iss = InitialSessionState.CreateDefault2();
                    iss.Commands.Clear();
                    iss.Formats.Clear();
                    iss.Commands.Add(
                        new SessionStateCmdletEntry("Start-Job", typeof(Microsoft.PowerShell.Commands.StartJobCommand), null));

                    // Get the default host from the default runspace.
                    _host     = GetDefaultHost();
                    _runspace = RunspaceFactory.CreateRunspace(_host, iss);
                    _runspace.Open();
                    _powerShell          = System.Management.Automation.PowerShell.Create();
                    _powerShell.Runspace = _runspace;

                    // Indicate SetShouldExit to host.
                    AddSetShouldExitToHost();
                }
                else
                {
                    _powerShell.Commands.Clear();
                }

                _job = StartJobCommand(_powerShell);

                _job.StateChanged += new EventHandler <JobStateEventArgs>(HandleJobStateChanged);
                SetJobState(_job.JobStateInfo.State);

                // Add all child jobs to this object's list so that
                // the user and Receive-Job can retrieve results.
                foreach (Job childJob in _job.ChildJobs)
                {
                    this.ChildJobs.Add(childJob);
                }

                // Add this job to the local repository.
                ScheduledJobSourceAdapter.AddToRepository(this);
            } // lock
        }
Exemple #4
0
        private void DeserializeStatusInfo(SerializationInfo info)
        {
            StatusInfo value = (StatusInfo)info.GetValue("StatusInfo", typeof(StatusInfo));

            base.Name           = value.Name;
            base.PSBeginTime    = value.StartTime;
            base.PSEndTime      = value.StopTime;
            this._jobDefinition = value.Definition;
            base.SetJobState(value.State, null);
            lock (base.SyncRoot)
            {
                this._statusInfo = value;
            }
        }
Exemple #5
0
        private void DeserializeStatusInfo(SerializationInfo info)
        {
            StatusInfo statusInfo = (StatusInfo)info.GetValue("StatusInfo", typeof(StatusInfo));

            Name           = statusInfo.Name;
            PSBeginTime    = statusInfo.StartTime;
            PSEndTime      = statusInfo.StopTime;
            _jobDefinition = statusInfo.Definition;
            SetJobState(statusInfo.State, null);

            lock (SyncRoot)
            {
                _statusInfo = statusInfo;
            }
        }
Exemple #6
0
        private void SerializeStatusInfo(SerializationInfo info)
        {
            StatusInfo statusInfo = new StatusInfo(
                InstanceId,
                Name,
                Location,
                Command,
                StatusMessage,
                (_job != null) ? _job.JobStateInfo.State : JobStateInfo.State,
                HasMoreData,
                PSBeginTime,
                PSEndTime,
                _jobDefinition);

            info.AddValue("StatusInfo", statusInfo);
        }
Exemple #7
0
        /// <summary>
        /// Method to update a ScheduledJob based on new state and
        /// result data from a provided Job.
        /// </summary>
        /// <param name="fromJob">ScheduledJob to update from.</param>
        internal void Update(ScheduledJob fromJob)
        {
            // We do not update "live" jobs.
            if (_job != null || fromJob == null)
            {
                return;
            }

            //
            // Update status.
            //
            PSEndTime = fromJob.PSEndTime;
            JobState state = fromJob.JobStateInfo.State;

            if (Status.State != state)
            {
                SetJobState(state, null);
            }

            lock (SyncRoot)
            {
                _statusInfo = new StatusInfo(
                    fromJob.InstanceId,
                    fromJob.Name,
                    fromJob.Location,
                    fromJob.Command,
                    fromJob.StatusMessage,
                    state,
                    fromJob.HasMoreData,
                    fromJob.PSBeginTime,
                    fromJob.PSEndTime,
                    fromJob._jobDefinition);
            }

            //
            // Update results.
            //
            CopyOutput(fromJob.Output);
            CopyError(fromJob.Error);
            CopyWarning(fromJob.Warning);
            CopyVerbose(fromJob.Verbose);
            CopyProgress(fromJob.Progress);
            CopyDebug(fromJob.Debug);
            CopyInformation(fromJob.Information);
        }
Exemple #8
0
 public override void StartJob()
 {
     lock (base.SyncRoot)
     {
         if (this._job == null || this.IsFinishedState(this._job.JobStateInfo.State))
         {
             this._statusInfo   = null;
             this._asyncJobStop = false;
             base.PSBeginTime   = new DateTime?(DateTime.Now);
             if (this._powerShell != null)
             {
                 this._powerShell.Commands.Clear();
             }
             else
             {
                 InitialSessionState initialSessionState = InitialSessionState.CreateDefault2();
                 initialSessionState.Commands.Clear();
                 initialSessionState.Formats.Clear();
                 initialSessionState.Commands.Add(new SessionStateCmdletEntry("Start-Job", typeof(StartJobCommand), null));
                 this._host     = this.GetDefaultHost();
                 this._runspace = RunspaceFactory.CreateRunspace(this._host, initialSessionState);
                 this._runspace.Open();
                 this._powerShell          = System.Management.Automation.PowerShell.Create();
                 this._powerShell.Runspace = this._runspace;
                 this.AddSetShouldExitToHost();
             }
             this._job = this.StartJobCommand(this._powerShell);
             this._job.StateChanged += new EventHandler <JobStateEventArgs>(this.HandleJobStateChanged);
             base.SetJobState(this._job.JobStateInfo.State);
             foreach (Job childJob in this._job.ChildJobs)
             {
                 base.ChildJobs.Add(childJob);
             }
             ScheduledJobSourceAdapter.AddToRepository(this);
         }
         else
         {
             string str = StringUtil.Format(ScheduledJobErrorStrings.JobAlreadyRunning, this._jobDefinition.Name);
             throw new PSInvalidOperationException(str);
         }
     }
 }
Exemple #9
0
        private void SerializeStatusInfo(SerializationInfo info)
        {
            JobState state;
            Guid     instanceId    = base.InstanceId;
            string   name          = base.Name;
            string   location      = this.Location;
            string   command       = this.Command;
            string   statusMessage = this.StatusMessage;

            if (this._job != null)
            {
                state = this._job.JobStateInfo.State;
            }
            else
            {
                state = base.JobStateInfo.State;
            }
            StatusInfo statusInfo = new StatusInfo(instanceId, name, location, command, statusMessage, state, this.HasMoreData, base.PSBeginTime, base.PSEndTime, this._jobDefinition);

            info.AddValue("StatusInfo", statusInfo);
        }
		private static void SaveStatusToFile(ScheduledJob job, FileStream fs)
		{
			StatusInfo statusInfo = new StatusInfo(job.InstanceId, job.Name, job.Location, job.Command, job.StatusMessage, job.JobStateInfo.State, job.HasMoreData, job.PSBeginTime, job.PSEndTime, job.Definition);
			XmlObjectSerializer netDataContractSerializer = new NetDataContractSerializer();
			netDataContractSerializer.WriteObject(fs, statusInfo);
			fs.Flush();
		}