public static ConcreteJob CreateFromPSObject(Collection<PSObject> objJob) { if (objJob == null || objJob.Count == 0) return null; ConcreteJob job = new ConcreteJob(); job.Id = objJob[0].GetProperty<int>("Id").ToString(); job.JobState = objJob[0].GetEnum<ConcreteJobState>("JobStateInfo"); job.Caption = objJob[0].GetProperty<string>("Name"); job.Description = objJob[0].GetProperty<string>("Command"); job.StartTime = objJob[0].GetProperty<DateTime>("PSBeginTime"); job.ElapsedTime = objJob[0].GetProperty<DateTime?>("PSEndTime") ?? DateTime.Now; // PercentComplete job.PercentComplete = 0; var progress = (PSDataCollection<ProgressRecord>)objJob[0].GetProperty("Progress"); if (progress != null && progress.Count > 0) job.PercentComplete = progress[0].PercentComplete; // Errors var errors = (PSDataCollection<ErrorRecord>)objJob[0].GetProperty("Error"); if (errors != null && errors.Count > 0) { job.ErrorDescription = errors[0].ErrorDetails.Message + ". " + errors[0].ErrorDetails.RecommendedAction; job.ErrorCode = errors[0].Exception != null ? -1 : 0; } return job; }
public static ConcreteJob CreateFromPSObject(Collection <PSObject> objJob) { if (objJob == null || objJob.Count == 0) { return(null); } ConcreteJob job = new ConcreteJob(); job.Id = objJob[0].GetProperty <int>("Id").ToString(); job.JobState = objJob[0].GetEnum <ConcreteJobState>("JobStateInfo"); job.Caption = objJob[0].GetProperty <string>("Name"); job.Description = objJob[0].GetProperty <string>("Command"); job.StartTime = objJob[0].GetProperty <DateTime>("PSBeginTime"); job.ElapsedTime = objJob[0].GetProperty <DateTime?>("PSEndTime") ?? DateTime.Now; // PercentComplete job.PercentComplete = 0; var progress = (PSDataCollection <ProgressRecord>)objJob[0].GetProperty("Progress"); if (progress != null && progress.Count > 0) { job.PercentComplete = progress[0].PercentComplete; } // Errors var errors = (PSDataCollection <ErrorRecord>)objJob[0].GetProperty("Error"); if (errors != null && errors.Count > 0) { job.ErrorDescription = errors[0].ErrorDetails.Message + ". " + errors[0].ErrorDetails.RecommendedAction; job.ErrorCode = errors[0].Exception != null ? -1 : 0; } return(job); }
private bool JobCompleted(ConcreteJob job) { bool jobCompleted = true; while (job.JobState == ConcreteJobState.Starting || job.JobState == ConcreteJobState.Running) { System.Threading.Thread.Sleep(200); job = GetJob(job.Id); } if (job.JobState != ConcreteJobState.Completed) { jobCompleted = false; } return jobCompleted; }
private ConcreteJob CreateJobFromWmiObject(ManagementBaseObject objJob) { if (objJob == null || objJob.Properties.Count == 0) return null; ConcreteJob job = new ConcreteJob(); job.Id = (string)objJob["InstanceID"]; job.JobState = (ConcreteJobState)Convert.ToInt32(objJob["JobState"]); job.Caption = (string)objJob["Caption"]; job.Description = (string)objJob["Description"]; job.StartTime = Wmi.ToDateTime((string)objJob["StartTime"]); // TODO proper parsing of WMI time spans, e.g. 00000000000001.325247:000 job.ElapsedTime = DateTime.Now; //wmi.ToDateTime((string)objJob["ElapsedTime"]); job.ErrorCode = Convert.ToInt32(objJob["ErrorCode"]); job.ErrorDescription = (string)objJob["ErrorDescription"]; job.PercentComplete = Convert.ToInt32(objJob["PercentComplete"]); return job; }
private static bool JobCompleted(VirtualizationServer2012 vs, ConcreteJob job) { TaskManager.IndicatorMaximum = 100; bool jobCompleted = true; while (job.JobState == ConcreteJobState.Starting || job.JobState == ConcreteJobState.Running) { System.Threading.Thread.Sleep(1000); job = vs.GetJob(job.Id); TaskManager.IndicatorCurrent = job.PercentComplete; } if (job.JobState != ConcreteJobState.Completed) { jobCompleted = false; } TaskManager.IndicatorCurrent = 0; // reset indicator return jobCompleted; }
private static void LogJobResult(ResultObject res, ConcreteJob job) { res.ErrorCodes.Add(VirtualizationErrorCodes.JOB_FAILED_ERROR + ":" + job.ErrorDescription); }
private static bool JobCompleted(VirtualizationServerForPrivateCloud vs, ConcreteJob job) { TaskManager.IndicatorMaximum = 100; bool jobCompleted = true; while (job.JobState == ConcreteJobState.Starting || job.JobState == ConcreteJobState.Running) { System.Threading.Thread.Sleep(1000); VMInfo vm = vs.GetVirtualMachine(job.Id); TaskManager.IndicatorCurrent = 50; if (vm.State == job.TargetState) { job.JobState = ConcreteJobState.Completed; } else if(vm.ProvisioningStatus == VirtualMachineProvisioningStatus.Error) { job.JobState = ConcreteJobState.Exception; } } if (job.JobState != ConcreteJobState.Completed) { jobCompleted = false; } TaskManager.IndicatorCurrent = 0; // reset indicator return jobCompleted; }