private async Task <string> GetDeviceJobName(DeviceJob job) { try { var model = await _jobRepository.QueryByJobIDAsync(job.JobId); return(model.JobName); } catch { return($"[{job.JobId}]"); } }
/// <summary> /// Convert device job to model /// </summary> /// <param name="job"></param> /// <returns></returns> public static DeviceJobModel ToModel(this DeviceJob job) { return(new DeviceJobModel { CreatedDateTimeUtc = job.CreatedDateTimeUtc, DeviceId = job.DeviceId, EndTimeUtc = job.EndTimeUtc, Error = job.Error.ToModel(), LastUpdatedDateTimeUtc = job.LastUpdatedDateTimeUtc, // ModuleId = job.ModuleId, // TODO: Outcome = job.Outcome.ToModel(), StartTimeUtc = job.StartTimeUtc, Status = job.Status.ToModel() }); }
public DeviceJobServiceModel(DeviceJob deviceJob) { this.DeviceId = deviceJob.DeviceId; switch (deviceJob.Status) { case Azure.Devices.DeviceJobStatus.Pending: this.Status = DeviceJobStatus.Pending; break; case Azure.Devices.DeviceJobStatus.Scheduled: this.Status = DeviceJobStatus.Scheduled; break; case Azure.Devices.DeviceJobStatus.Running: this.Status = DeviceJobStatus.Running; break; case Azure.Devices.DeviceJobStatus.Completed: this.Status = DeviceJobStatus.Completed; break; case Azure.Devices.DeviceJobStatus.Failed: this.Status = DeviceJobStatus.Failed; break; case Azure.Devices.DeviceJobStatus.Canceled: this.Status = DeviceJobStatus.Canceled; break; } this.StartTimeUtc = deviceJob.StartTimeUtc; this.EndTimeUtc = deviceJob.EndTimeUtc; this.CreatedDateTimeUtc = deviceJob.CreatedDateTimeUtc; this.LastUpdatedDateTimeUtc = deviceJob.LastUpdatedDateTimeUtc; if (deviceJob.Outcome?.DeviceMethodResponse != null) { this.Outcome = new MethodResultServiceModel(deviceJob.Outcome.DeviceMethodResponse); } if (deviceJob.Error != null) { this.Error = new DeviceJobErrorServiceModel(deviceJob.Error); } }
public async Task <JobServiceModel> GetJobsAsync( string jobId, bool?includeDeviceDetails, DeviceJobStatus?deviceJobStatus) { var data = await this.client.GetAsync(DEVICE_JOBS_COLLECTION_ID, jobId); var result = this.CreatejobServiceModel(data); if (!includeDeviceDetails.HasValue || !includeDeviceDetails.Value) { return(result); } // Device job query by status of 'Completed' or 'Cancelled' will fail with InternalServerError // https://github.com/Azure/azure-iot-sdk-csharp/issues/257 var queryString = deviceJobStatus.HasValue ? string.Format(DEVICE_DETAILS_QUERYWITH_STATUS_FORMAT, jobId, deviceJobStatus.Value.ToString().ToLower()) : string.Format(DEVICE_DETAILS_QUERY_FORMAT, jobId); //var query = this.registryManager.CreateQuery(queryString); var deviceJobs = new List <DeviceJob>(); foreach (var devicejob in result.Devices) { var _devicejob = new DeviceJob(); var type = result.Type.ToString(); _devicejob.CreatedDateTimeUtc = devicejob.CreatedDateTimeUtc; _devicejob.DeviceId = devicejob.DeviceId; _devicejob.EndTimeUtc = devicejob.EndTimeUtc; _devicejob.JobType = (DeviceJobType)result.Type; //_devicejob.Error = devicejob.Error; _devicejob.LastUpdatedDateTimeUtc = devicejob.LastUpdatedDateTimeUtc; _devicejob.Status = (azureDeviceJobStatus)devicejob.Status; _devicejob.StartTimeUtc = devicejob.StartTimeUtc; //_devicejob.Outcome = devicejob.Outcome; _devicejob.JobId = jobId; deviceJobs.Add(_devicejob); } return(new JobServiceModel(result, deviceJobs)); }