public async Task <JobServiceModel> GetJobsAsync( string jobId, bool?includeDeviceDetails, DeviceJobStatus?deviceJobStatus) { var result = await this.jobClient.GetJobAsync(jobId); if (!includeDeviceDetails.HasValue || !includeDeviceDetails.Value) { return(new JobServiceModel(result)); } var queryString = deviceJobStatus.HasValue ? string.Format(DEVICE_DETAILS_QUERYWITH_STATUS_FORMAT, jobId, deviceJobStatus) : string.Format(DEVICE_DETAILS_QUERY_FORMAT, jobId); var query = this.registryManager.CreateQuery(queryString); var deviceJobs = new List <DeviceJob>(); while (query.HasMoreResults) { deviceJobs.AddRange(await query.GetNextAsDeviceJobAsync()); } return(new JobServiceModel(result, deviceJobs)); }
public async Task <JobServiceModel> GetJobsAsync( string jobId, bool?includeDeviceDetails, DeviceJobStatus?deviceJobStatus) { var result = await this.tenantConnectionHelper.GetJobClient().GetJobAsync(jobId); if (!includeDeviceDetails.HasValue || !includeDeviceDetails.Value) { return(new JobServiceModel(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(DeviceDetailsQueryWithStatusFormat, jobId, deviceJobStatus.Value.ToString().ToLower()) : string.Format(DeviceDetailsQueryFormat, jobId); var query = this.tenantConnectionHelper.GetRegistry().CreateQuery(queryString); var deviceJobs = new List <DeviceJob>(); while (query.HasMoreResults) { deviceJobs.AddRange(await query.GetNextAsDeviceJobAsync()); } return(new JobServiceModel(result, deviceJobs)); }
Uri BuildQueryJobUri(DeviceJobType?jobType, DeviceJobStatus?jobStatus, int?pageSize, string continuationToken) { StringBuilder stringBuilder = new StringBuilder(JobsQueryFormat.FormatInvariant(ClientApiVersionHelper.ApiVersionQueryString)); if (jobType != null) { stringBuilder.Append("&jobType={0}".FormatInvariant(WebUtility.UrlEncode(jobType.ToString()))); } if (jobStatus != null) { stringBuilder.Append("&jobStatus={0}".FormatInvariant(WebUtility.UrlEncode(jobStatus.ToString()))); } if (pageSize != null) { stringBuilder.Append("&pageSize={0}".FormatInvariant(pageSize)); } if (!string.IsNullOrWhiteSpace(continuationToken)) { stringBuilder.Append("&continuationToken={0}".FormatInvariant(WebUtility.UrlEncode(continuationToken))); } return(new Uri(stringBuilder.ToString(), UriKind.Relative)); }
public async Task <JobApiModel> GetJobAsync( string jobId, [FromQuery] bool?includeDeviceDetails, [FromQuery] DeviceJobStatus?deviceJobStatus) { var result = await this.jobs.GetJobsAsync(jobId, includeDeviceDetails, deviceJobStatus); return(new JobApiModel(result)); }
Task <QueryResult> GetJobsAsync(DeviceJobType?jobType, DeviceJobStatus?jobStatus, int?pageSize, string continuationToken, CancellationToken cancellationToken) { this.EnsureInstanceNotClosed(); return(this.httpClientHelper.GetAsync <QueryResult>( BuildQueryJobUri(jobType, jobStatus, pageSize, continuationToken), null, null, cancellationToken)); }
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)); }
/// <summary> /// Get IQuery through which job responses for specified jobType and jobStatus are retrieved page by page, /// and specify page size /// </summary> /// <param name="jobType">The job type to query. Could be null if not querying.</param> /// <param name="jobStatus">The job status to query. Could be null if not querying.</param> /// <param name="pageSize">Number of job responses in a page</param> /// <returns></returns> public abstract IQuery CreateQuery(DeviceJobType?jobType, DeviceJobStatus?jobStatus, int?pageSize);
/// <summary> /// Get IQuery through which job responses for specified jobType and jobStatus are retrieved page by page /// </summary> /// <param name="jobType">The job type to query. Could be null if not querying.</param> /// <param name="jobStatus">The job status to query. Could be null if not querying.</param> /// <returns></returns> public abstract IQuery CreateQuery(DeviceJobType?jobType, DeviceJobStatus?jobStatus);
public override IQuery CreateQuery(DeviceJobType?jobType, DeviceJobStatus?jobStatus, int?pageSize) { return(new Query((token) => this.GetJobsAsync(jobType, jobStatus, pageSize, token, CancellationToken.None))); }
public override IQuery CreateQuery(DeviceJobType?jobType, DeviceJobStatus?jobStatus) { return(CreateQuery(jobType, jobStatus, null)); }