| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | // <auto-generated/> |
| | 5 | |
|
| | 6 | | #nullable disable |
| | 7 | |
|
| | 8 | | using System; |
| | 9 | | using System.Collections.Generic; |
| | 10 | | using System.Text.Json; |
| | 11 | | using System.Threading; |
| | 12 | | using System.Threading.Tasks; |
| | 13 | | using Azure; |
| | 14 | | using Azure.Core; |
| | 15 | | using Azure.Core.Pipeline; |
| | 16 | | using Azure.Iot.Hub.Service.Models; |
| | 17 | |
|
| | 18 | | namespace Azure.Iot.Hub.Service |
| | 19 | | { |
| | 20 | | internal partial class JobsRestClient |
| | 21 | | { |
| | 22 | | private Uri endpoint; |
| | 23 | | private string apiVersion; |
| | 24 | | private ClientDiagnostics _clientDiagnostics; |
| | 25 | | private HttpPipeline _pipeline; |
| | 26 | |
|
| | 27 | | /// <summary> Initializes a new instance of JobsRestClient. </summary> |
| | 28 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 29 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 30 | | /// <param name="endpoint"> server parameter. </param> |
| | 31 | | /// <param name="apiVersion"> Api Version. </param> |
| | 32 | | /// <exception cref="ArgumentNullException"> <paramref name="apiVersion"/> is null. </exception> |
| 0 | 33 | | public JobsRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null, string ap |
| | 34 | | { |
| 0 | 35 | | endpoint ??= new Uri("https://fully-qualified-iothubname.azure-devices.net"); |
| 0 | 36 | | if (apiVersion == null) |
| | 37 | | { |
| 0 | 38 | | throw new ArgumentNullException(nameof(apiVersion)); |
| | 39 | | } |
| | 40 | |
|
| 0 | 41 | | this.endpoint = endpoint; |
| 0 | 42 | | this.apiVersion = apiVersion; |
| 0 | 43 | | _clientDiagnostics = clientDiagnostics; |
| 0 | 44 | | _pipeline = pipeline; |
| 0 | 45 | | } |
| | 46 | |
|
| | 47 | | internal HttpMessage CreateCreateImportExportJobRequest(JobProperties jobProperties) |
| | 48 | | { |
| 0 | 49 | | var message = _pipeline.CreateMessage(); |
| 0 | 50 | | var request = message.Request; |
| 0 | 51 | | request.Method = RequestMethod.Post; |
| 0 | 52 | | var uri = new RawRequestUriBuilder(); |
| 0 | 53 | | uri.Reset(endpoint); |
| 0 | 54 | | uri.AppendPath("/jobs/create", false); |
| 0 | 55 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 56 | | request.Uri = uri; |
| 0 | 57 | | request.Headers.Add("Content-Type", "application/json"); |
| 0 | 58 | | var content = new Utf8JsonRequestContent(); |
| 0 | 59 | | content.JsonWriter.WriteObjectValue(jobProperties); |
| 0 | 60 | | request.Content = content; |
| 0 | 61 | | return message; |
| | 62 | | } |
| | 63 | |
|
| | 64 | | /// <summary> Creates a new import or export job on the IoT Hub. See https://docs.microsoft.com/en-us/azure/iot- |
| | 65 | | /// <param name="jobProperties"> The job specifications. </param> |
| | 66 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 67 | | /// <exception cref="ArgumentNullException"> <paramref name="jobProperties"/> is null. </exception> |
| | 68 | | public async Task<Response<JobProperties>> CreateImportExportJobAsync(JobProperties jobProperties, CancellationT |
| | 69 | | { |
| 0 | 70 | | if (jobProperties == null) |
| | 71 | | { |
| 0 | 72 | | throw new ArgumentNullException(nameof(jobProperties)); |
| | 73 | | } |
| | 74 | |
|
| 0 | 75 | | using var message = CreateCreateImportExportJobRequest(jobProperties); |
| 0 | 76 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 77 | | switch (message.Response.Status) |
| | 78 | | { |
| | 79 | | case 200: |
| | 80 | | { |
| | 81 | | JobProperties value = default; |
| 0 | 82 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 83 | | value = JobProperties.DeserializeJobProperties(document.RootElement); |
| 0 | 84 | | return Response.FromValue(value, message.Response); |
| | 85 | | } |
| | 86 | | default: |
| 0 | 87 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 88 | | } |
| 0 | 89 | | } |
| | 90 | |
|
| | 91 | | /// <summary> Creates a new import or export job on the IoT Hub. See https://docs.microsoft.com/en-us/azure/iot- |
| | 92 | | /// <param name="jobProperties"> The job specifications. </param> |
| | 93 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 94 | | /// <exception cref="ArgumentNullException"> <paramref name="jobProperties"/> is null. </exception> |
| | 95 | | public Response<JobProperties> CreateImportExportJob(JobProperties jobProperties, CancellationToken cancellation |
| | 96 | | { |
| 0 | 97 | | if (jobProperties == null) |
| | 98 | | { |
| 0 | 99 | | throw new ArgumentNullException(nameof(jobProperties)); |
| | 100 | | } |
| | 101 | |
|
| 0 | 102 | | using var message = CreateCreateImportExportJobRequest(jobProperties); |
| 0 | 103 | | _pipeline.Send(message, cancellationToken); |
| 0 | 104 | | switch (message.Response.Status) |
| | 105 | | { |
| | 106 | | case 200: |
| | 107 | | { |
| | 108 | | JobProperties value = default; |
| 0 | 109 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 110 | | value = JobProperties.DeserializeJobProperties(document.RootElement); |
| 0 | 111 | | return Response.FromValue(value, message.Response); |
| | 112 | | } |
| | 113 | | default: |
| 0 | 114 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 115 | | } |
| 0 | 116 | | } |
| | 117 | |
|
| | 118 | | internal HttpMessage CreateGetImportExportJobsRequest() |
| | 119 | | { |
| 0 | 120 | | var message = _pipeline.CreateMessage(); |
| 0 | 121 | | var request = message.Request; |
| 0 | 122 | | request.Method = RequestMethod.Get; |
| 0 | 123 | | var uri = new RawRequestUriBuilder(); |
| 0 | 124 | | uri.Reset(endpoint); |
| 0 | 125 | | uri.AppendPath("/jobs", false); |
| 0 | 126 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 127 | | request.Uri = uri; |
| 0 | 128 | | return message; |
| | 129 | | } |
| | 130 | |
|
| | 131 | | /// <summary> Gets the status of all import and export jobs in the IoT Hub. See https://docs.microsoft.com/en-us |
| | 132 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 133 | | public async Task<Response<IReadOnlyList<JobProperties>>> GetImportExportJobsAsync(CancellationToken cancellatio |
| | 134 | | { |
| 0 | 135 | | using var message = CreateGetImportExportJobsRequest(); |
| 0 | 136 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 137 | | switch (message.Response.Status) |
| | 138 | | { |
| | 139 | | case 200: |
| | 140 | | { |
| | 141 | | IReadOnlyList<JobProperties> value = default; |
| 0 | 142 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 143 | | List<JobProperties> array = new List<JobProperties>(); |
| 0 | 144 | | foreach (var item in document.RootElement.EnumerateArray()) |
| | 145 | | { |
| 0 | 146 | | array.Add(JobProperties.DeserializeJobProperties(item)); |
| | 147 | | } |
| 0 | 148 | | value = array; |
| 0 | 149 | | return Response.FromValue(value, message.Response); |
| | 150 | | } |
| | 151 | | default: |
| 0 | 152 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 153 | | } |
| 0 | 154 | | } |
| | 155 | |
|
| | 156 | | /// <summary> Gets the status of all import and export jobs in the IoT Hub. See https://docs.microsoft.com/en-us |
| | 157 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 158 | | public Response<IReadOnlyList<JobProperties>> GetImportExportJobs(CancellationToken cancellationToken = default) |
| | 159 | | { |
| 0 | 160 | | using var message = CreateGetImportExportJobsRequest(); |
| 0 | 161 | | _pipeline.Send(message, cancellationToken); |
| 0 | 162 | | switch (message.Response.Status) |
| | 163 | | { |
| | 164 | | case 200: |
| | 165 | | { |
| | 166 | | IReadOnlyList<JobProperties> value = default; |
| 0 | 167 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 168 | | List<JobProperties> array = new List<JobProperties>(); |
| 0 | 169 | | foreach (var item in document.RootElement.EnumerateArray()) |
| | 170 | | { |
| 0 | 171 | | array.Add(JobProperties.DeserializeJobProperties(item)); |
| | 172 | | } |
| 0 | 173 | | value = array; |
| 0 | 174 | | return Response.FromValue(value, message.Response); |
| | 175 | | } |
| | 176 | | default: |
| 0 | 177 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 178 | | } |
| 0 | 179 | | } |
| | 180 | |
|
| | 181 | | internal HttpMessage CreateGetImportExportJobRequest(string id) |
| | 182 | | { |
| 0 | 183 | | var message = _pipeline.CreateMessage(); |
| 0 | 184 | | var request = message.Request; |
| 0 | 185 | | request.Method = RequestMethod.Get; |
| 0 | 186 | | var uri = new RawRequestUriBuilder(); |
| 0 | 187 | | uri.Reset(endpoint); |
| 0 | 188 | | uri.AppendPath("/jobs/", false); |
| 0 | 189 | | uri.AppendPath(id, true); |
| 0 | 190 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 191 | | request.Uri = uri; |
| 0 | 192 | | return message; |
| | 193 | | } |
| | 194 | |
|
| | 195 | | /// <summary> Gets the status of an import or export job in the IoT Hub. See https://docs.microsoft.com/en-us/az |
| | 196 | | /// <param name="id"> The unique identifier of the job. </param> |
| | 197 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 198 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 199 | | public async Task<Response<JobProperties>> GetImportExportJobAsync(string id, CancellationToken cancellationToke |
| | 200 | | { |
| 0 | 201 | | if (id == null) |
| | 202 | | { |
| 0 | 203 | | throw new ArgumentNullException(nameof(id)); |
| | 204 | | } |
| | 205 | |
|
| 0 | 206 | | using var message = CreateGetImportExportJobRequest(id); |
| 0 | 207 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 208 | | switch (message.Response.Status) |
| | 209 | | { |
| | 210 | | case 200: |
| | 211 | | { |
| | 212 | | JobProperties value = default; |
| 0 | 213 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 214 | | value = JobProperties.DeserializeJobProperties(document.RootElement); |
| 0 | 215 | | return Response.FromValue(value, message.Response); |
| | 216 | | } |
| | 217 | | default: |
| 0 | 218 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 219 | | } |
| 0 | 220 | | } |
| | 221 | |
|
| | 222 | | /// <summary> Gets the status of an import or export job in the IoT Hub. See https://docs.microsoft.com/en-us/az |
| | 223 | | /// <param name="id"> The unique identifier of the job. </param> |
| | 224 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 225 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 226 | | public Response<JobProperties> GetImportExportJob(string id, CancellationToken cancellationToken = default) |
| | 227 | | { |
| 0 | 228 | | if (id == null) |
| | 229 | | { |
| 0 | 230 | | throw new ArgumentNullException(nameof(id)); |
| | 231 | | } |
| | 232 | |
|
| 0 | 233 | | using var message = CreateGetImportExportJobRequest(id); |
| 0 | 234 | | _pipeline.Send(message, cancellationToken); |
| 0 | 235 | | switch (message.Response.Status) |
| | 236 | | { |
| | 237 | | case 200: |
| | 238 | | { |
| | 239 | | JobProperties value = default; |
| 0 | 240 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 241 | | value = JobProperties.DeserializeJobProperties(document.RootElement); |
| 0 | 242 | | return Response.FromValue(value, message.Response); |
| | 243 | | } |
| | 244 | | default: |
| 0 | 245 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 246 | | } |
| 0 | 247 | | } |
| | 248 | |
|
| | 249 | | internal HttpMessage CreateCancelImportExportJobRequest(string id) |
| | 250 | | { |
| 0 | 251 | | var message = _pipeline.CreateMessage(); |
| 0 | 252 | | var request = message.Request; |
| 0 | 253 | | request.Method = RequestMethod.Delete; |
| 0 | 254 | | var uri = new RawRequestUriBuilder(); |
| 0 | 255 | | uri.Reset(endpoint); |
| 0 | 256 | | uri.AppendPath("/jobs/", false); |
| 0 | 257 | | uri.AppendPath(id, true); |
| 0 | 258 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 259 | | request.Uri = uri; |
| 0 | 260 | | return message; |
| | 261 | | } |
| | 262 | |
|
| | 263 | | /// <summary> Cancels an import or export job in the IoT Hub. </summary> |
| | 264 | | /// <param name="id"> The unique identifier of the job. </param> |
| | 265 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 266 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 267 | | public async Task<Response<object>> CancelImportExportJobAsync(string id, CancellationToken cancellationToken = |
| | 268 | | { |
| 0 | 269 | | if (id == null) |
| | 270 | | { |
| 0 | 271 | | throw new ArgumentNullException(nameof(id)); |
| | 272 | | } |
| | 273 | |
|
| 0 | 274 | | using var message = CreateCancelImportExportJobRequest(id); |
| 0 | 275 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 276 | | switch (message.Response.Status) |
| | 277 | | { |
| | 278 | | case 200: |
| | 279 | | { |
| | 280 | | object value = default; |
| 0 | 281 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 282 | | value = document.RootElement.GetObject(); |
| 0 | 283 | | return Response.FromValue(value, message.Response); |
| | 284 | | } |
| | 285 | | case 204: |
| 0 | 286 | | return Response.FromValue<object>(null, message.Response); |
| | 287 | | default: |
| 0 | 288 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 289 | | } |
| 0 | 290 | | } |
| | 291 | |
|
| | 292 | | /// <summary> Cancels an import or export job in the IoT Hub. </summary> |
| | 293 | | /// <param name="id"> The unique identifier of the job. </param> |
| | 294 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 295 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 296 | | public Response<object> CancelImportExportJob(string id, CancellationToken cancellationToken = default) |
| | 297 | | { |
| 0 | 298 | | if (id == null) |
| | 299 | | { |
| 0 | 300 | | throw new ArgumentNullException(nameof(id)); |
| | 301 | | } |
| | 302 | |
|
| 0 | 303 | | using var message = CreateCancelImportExportJobRequest(id); |
| 0 | 304 | | _pipeline.Send(message, cancellationToken); |
| 0 | 305 | | switch (message.Response.Status) |
| | 306 | | { |
| | 307 | | case 200: |
| | 308 | | { |
| | 309 | | object value = default; |
| 0 | 310 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 311 | | value = document.RootElement.GetObject(); |
| 0 | 312 | | return Response.FromValue(value, message.Response); |
| | 313 | | } |
| | 314 | | case 204: |
| 0 | 315 | | return Response.FromValue<object>(null, message.Response); |
| | 316 | | default: |
| 0 | 317 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 318 | | } |
| 0 | 319 | | } |
| | 320 | |
|
| | 321 | | internal HttpMessage CreateGetScheduledJobRequest(string id) |
| | 322 | | { |
| 0 | 323 | | var message = _pipeline.CreateMessage(); |
| 0 | 324 | | var request = message.Request; |
| 0 | 325 | | request.Method = RequestMethod.Get; |
| 0 | 326 | | var uri = new RawRequestUriBuilder(); |
| 0 | 327 | | uri.Reset(endpoint); |
| 0 | 328 | | uri.AppendPath("/jobs/v2/", false); |
| 0 | 329 | | uri.AppendPath(id, true); |
| 0 | 330 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 331 | | request.Uri = uri; |
| 0 | 332 | | return message; |
| | 333 | | } |
| | 334 | |
|
| | 335 | | /// <summary> Gets details of a scheduled job from the IoT Hub. See https://docs.microsoft.com/en-us/azure/iot-h |
| | 336 | | /// <param name="id"> The unique identifier of the job. </param> |
| | 337 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 338 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 339 | | public async Task<Response<JobResponse>> GetScheduledJobAsync(string id, CancellationToken cancellationToken = d |
| | 340 | | { |
| 0 | 341 | | if (id == null) |
| | 342 | | { |
| 0 | 343 | | throw new ArgumentNullException(nameof(id)); |
| | 344 | | } |
| | 345 | |
|
| 0 | 346 | | using var message = CreateGetScheduledJobRequest(id); |
| 0 | 347 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 348 | | switch (message.Response.Status) |
| | 349 | | { |
| | 350 | | case 200: |
| | 351 | | { |
| | 352 | | JobResponse value = default; |
| 0 | 353 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 354 | | value = JobResponse.DeserializeJobResponse(document.RootElement); |
| 0 | 355 | | return Response.FromValue(value, message.Response); |
| | 356 | | } |
| | 357 | | default: |
| 0 | 358 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 359 | | } |
| 0 | 360 | | } |
| | 361 | |
|
| | 362 | | /// <summary> Gets details of a scheduled job from the IoT Hub. See https://docs.microsoft.com/en-us/azure/iot-h |
| | 363 | | /// <param name="id"> The unique identifier of the job. </param> |
| | 364 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 365 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 366 | | public Response<JobResponse> GetScheduledJob(string id, CancellationToken cancellationToken = default) |
| | 367 | | { |
| 0 | 368 | | if (id == null) |
| | 369 | | { |
| 0 | 370 | | throw new ArgumentNullException(nameof(id)); |
| | 371 | | } |
| | 372 | |
|
| 0 | 373 | | using var message = CreateGetScheduledJobRequest(id); |
| 0 | 374 | | _pipeline.Send(message, cancellationToken); |
| 0 | 375 | | switch (message.Response.Status) |
| | 376 | | { |
| | 377 | | case 200: |
| | 378 | | { |
| | 379 | | JobResponse value = default; |
| 0 | 380 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 381 | | value = JobResponse.DeserializeJobResponse(document.RootElement); |
| 0 | 382 | | return Response.FromValue(value, message.Response); |
| | 383 | | } |
| | 384 | | default: |
| 0 | 385 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 386 | | } |
| 0 | 387 | | } |
| | 388 | |
|
| | 389 | | internal HttpMessage CreateCreateScheduledJobRequest(string id, JobRequest jobRequest) |
| | 390 | | { |
| 0 | 391 | | var message = _pipeline.CreateMessage(); |
| 0 | 392 | | var request = message.Request; |
| 0 | 393 | | request.Method = RequestMethod.Put; |
| 0 | 394 | | var uri = new RawRequestUriBuilder(); |
| 0 | 395 | | uri.Reset(endpoint); |
| 0 | 396 | | uri.AppendPath("/jobs/v2/", false); |
| 0 | 397 | | uri.AppendPath(id, true); |
| 0 | 398 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 399 | | request.Uri = uri; |
| 0 | 400 | | request.Headers.Add("Content-Type", "application/json"); |
| 0 | 401 | | var content = new Utf8JsonRequestContent(); |
| 0 | 402 | | content.JsonWriter.WriteObjectValue(jobRequest); |
| 0 | 403 | | request.Content = content; |
| 0 | 404 | | return message; |
| | 405 | | } |
| | 406 | |
|
| | 407 | | /// <summary> Creates a new job to schedule twin updates or direct methods on the IoT Hub at a scheduled time. S |
| | 408 | | /// <param name="id"> The unique identifier of the job. </param> |
| | 409 | | /// <param name="jobRequest"> The job request info. </param> |
| | 410 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 411 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> or <paramref name="jobRequest"/> is null. </e |
| | 412 | | public async Task<Response<JobResponse>> CreateScheduledJobAsync(string id, JobRequest jobRequest, CancellationT |
| | 413 | | { |
| 0 | 414 | | if (id == null) |
| | 415 | | { |
| 0 | 416 | | throw new ArgumentNullException(nameof(id)); |
| | 417 | | } |
| 0 | 418 | | if (jobRequest == null) |
| | 419 | | { |
| 0 | 420 | | throw new ArgumentNullException(nameof(jobRequest)); |
| | 421 | | } |
| | 422 | |
|
| 0 | 423 | | using var message = CreateCreateScheduledJobRequest(id, jobRequest); |
| 0 | 424 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 425 | | switch (message.Response.Status) |
| | 426 | | { |
| | 427 | | case 200: |
| | 428 | | { |
| | 429 | | JobResponse value = default; |
| 0 | 430 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 431 | | value = JobResponse.DeserializeJobResponse(document.RootElement); |
| 0 | 432 | | return Response.FromValue(value, message.Response); |
| | 433 | | } |
| | 434 | | default: |
| 0 | 435 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 436 | | } |
| 0 | 437 | | } |
| | 438 | |
|
| | 439 | | /// <summary> Creates a new job to schedule twin updates or direct methods on the IoT Hub at a scheduled time. S |
| | 440 | | /// <param name="id"> The unique identifier of the job. </param> |
| | 441 | | /// <param name="jobRequest"> The job request info. </param> |
| | 442 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 443 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> or <paramref name="jobRequest"/> is null. </e |
| | 444 | | public Response<JobResponse> CreateScheduledJob(string id, JobRequest jobRequest, CancellationToken cancellation |
| | 445 | | { |
| 0 | 446 | | if (id == null) |
| | 447 | | { |
| 0 | 448 | | throw new ArgumentNullException(nameof(id)); |
| | 449 | | } |
| 0 | 450 | | if (jobRequest == null) |
| | 451 | | { |
| 0 | 452 | | throw new ArgumentNullException(nameof(jobRequest)); |
| | 453 | | } |
| | 454 | |
|
| 0 | 455 | | using var message = CreateCreateScheduledJobRequest(id, jobRequest); |
| 0 | 456 | | _pipeline.Send(message, cancellationToken); |
| 0 | 457 | | switch (message.Response.Status) |
| | 458 | | { |
| | 459 | | case 200: |
| | 460 | | { |
| | 461 | | JobResponse value = default; |
| 0 | 462 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 463 | | value = JobResponse.DeserializeJobResponse(document.RootElement); |
| 0 | 464 | | return Response.FromValue(value, message.Response); |
| | 465 | | } |
| | 466 | | default: |
| 0 | 467 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 468 | | } |
| 0 | 469 | | } |
| | 470 | |
|
| | 471 | | internal HttpMessage CreateCancelScheduledJobRequest(string id) |
| | 472 | | { |
| 0 | 473 | | var message = _pipeline.CreateMessage(); |
| 0 | 474 | | var request = message.Request; |
| 0 | 475 | | request.Method = RequestMethod.Post; |
| 0 | 476 | | var uri = new RawRequestUriBuilder(); |
| 0 | 477 | | uri.Reset(endpoint); |
| 0 | 478 | | uri.AppendPath("/jobs/v2/", false); |
| 0 | 479 | | uri.AppendPath(id, true); |
| 0 | 480 | | uri.AppendPath("/cancel", false); |
| 0 | 481 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 482 | | request.Uri = uri; |
| 0 | 483 | | return message; |
| | 484 | | } |
| | 485 | |
|
| | 486 | | /// <summary> Cancels a scheduled job on the IoT Hub. See https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub |
| | 487 | | /// <param name="id"> The unique identifier of the job. </param> |
| | 488 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 489 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 490 | | public async Task<Response<JobResponse>> CancelScheduledJobAsync(string id, CancellationToken cancellationToken |
| | 491 | | { |
| 0 | 492 | | if (id == null) |
| | 493 | | { |
| 0 | 494 | | throw new ArgumentNullException(nameof(id)); |
| | 495 | | } |
| | 496 | |
|
| 0 | 497 | | using var message = CreateCancelScheduledJobRequest(id); |
| 0 | 498 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 499 | | switch (message.Response.Status) |
| | 500 | | { |
| | 501 | | case 200: |
| | 502 | | { |
| | 503 | | JobResponse value = default; |
| 0 | 504 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 505 | | value = JobResponse.DeserializeJobResponse(document.RootElement); |
| 0 | 506 | | return Response.FromValue(value, message.Response); |
| | 507 | | } |
| | 508 | | default: |
| 0 | 509 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 510 | | } |
| 0 | 511 | | } |
| | 512 | |
|
| | 513 | | /// <summary> Cancels a scheduled job on the IoT Hub. See https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub |
| | 514 | | /// <param name="id"> The unique identifier of the job. </param> |
| | 515 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 516 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 517 | | public Response<JobResponse> CancelScheduledJob(string id, CancellationToken cancellationToken = default) |
| | 518 | | { |
| 0 | 519 | | if (id == null) |
| | 520 | | { |
| 0 | 521 | | throw new ArgumentNullException(nameof(id)); |
| | 522 | | } |
| | 523 | |
|
| 0 | 524 | | using var message = CreateCancelScheduledJobRequest(id); |
| 0 | 525 | | _pipeline.Send(message, cancellationToken); |
| 0 | 526 | | switch (message.Response.Status) |
| | 527 | | { |
| | 528 | | case 200: |
| | 529 | | { |
| | 530 | | JobResponse value = default; |
| 0 | 531 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 532 | | value = JobResponse.DeserializeJobResponse(document.RootElement); |
| 0 | 533 | | return Response.FromValue(value, message.Response); |
| | 534 | | } |
| | 535 | | default: |
| 0 | 536 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 537 | | } |
| 0 | 538 | | } |
| | 539 | |
|
| | 540 | | internal HttpMessage CreateQueryScheduledJobsRequest(string jobType, string jobStatus) |
| | 541 | | { |
| 0 | 542 | | var message = _pipeline.CreateMessage(); |
| 0 | 543 | | var request = message.Request; |
| 0 | 544 | | request.Method = RequestMethod.Get; |
| 0 | 545 | | var uri = new RawRequestUriBuilder(); |
| 0 | 546 | | uri.Reset(endpoint); |
| 0 | 547 | | uri.AppendPath("/jobs/v2/query", false); |
| 0 | 548 | | if (jobType != null) |
| | 549 | | { |
| 0 | 550 | | uri.AppendQuery("jobType", jobType, true); |
| | 551 | | } |
| 0 | 552 | | if (jobStatus != null) |
| | 553 | | { |
| 0 | 554 | | uri.AppendQuery("jobStatus", jobStatus, true); |
| | 555 | | } |
| 0 | 556 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 557 | | request.Uri = uri; |
| 0 | 558 | | return message; |
| | 559 | | } |
| | 560 | |
|
| | 561 | | /// <summary> Gets the information about jobs using an IoT Hub query. See https://docs.microsoft.com/azure/iot-h |
| | 562 | | /// <param name="jobType"> The job type. See https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-job |
| | 563 | | /// <param name="jobStatus"> The job status. See https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide |
| | 564 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 565 | | public async Task<Response<QueryResult>> QueryScheduledJobsAsync(string jobType = null, string jobStatus = null, |
| | 566 | | { |
| 0 | 567 | | using var message = CreateQueryScheduledJobsRequest(jobType, jobStatus); |
| 0 | 568 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 569 | | switch (message.Response.Status) |
| | 570 | | { |
| | 571 | | case 200: |
| | 572 | | { |
| | 573 | | QueryResult value = default; |
| 0 | 574 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 575 | | value = QueryResult.DeserializeQueryResult(document.RootElement); |
| 0 | 576 | | return Response.FromValue(value, message.Response); |
| | 577 | | } |
| | 578 | | default: |
| 0 | 579 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 580 | | } |
| 0 | 581 | | } |
| | 582 | |
|
| | 583 | | /// <summary> Gets the information about jobs using an IoT Hub query. See https://docs.microsoft.com/azure/iot-h |
| | 584 | | /// <param name="jobType"> The job type. See https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-job |
| | 585 | | /// <param name="jobStatus"> The job status. See https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide |
| | 586 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 587 | | public Response<QueryResult> QueryScheduledJobs(string jobType = null, string jobStatus = null, CancellationToke |
| | 588 | | { |
| 0 | 589 | | using var message = CreateQueryScheduledJobsRequest(jobType, jobStatus); |
| 0 | 590 | | _pipeline.Send(message, cancellationToken); |
| 0 | 591 | | switch (message.Response.Status) |
| | 592 | | { |
| | 593 | | case 200: |
| | 594 | | { |
| | 595 | | QueryResult value = default; |
| 0 | 596 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 597 | | value = QueryResult.DeserializeQueryResult(document.RootElement); |
| 0 | 598 | | return Response.FromValue(value, message.Response); |
| | 599 | | } |
| | 600 | | default: |
| 0 | 601 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 602 | | } |
| 0 | 603 | | } |
| | 604 | | } |
| | 605 | | } |