| | 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.Text.Json; |
| | 10 | | using System.Threading; |
| | 11 | | using System.Threading.Tasks; |
| | 12 | | using Azure; |
| | 13 | | using Azure.Core; |
| | 14 | | using Azure.Core.Pipeline; |
| | 15 | | using Azure.Iot.Hub.Service.Models; |
| | 16 | |
|
| | 17 | | namespace Azure.Iot.Hub.Service |
| | 18 | | { |
| | 19 | | internal partial class MessagesRestClient |
| | 20 | | { |
| | 21 | | private Uri endpoint; |
| | 22 | | private string apiVersion; |
| | 23 | | private ClientDiagnostics _clientDiagnostics; |
| | 24 | | private HttpPipeline _pipeline; |
| | 25 | |
|
| | 26 | | /// <summary> Initializes a new instance of MessagesRestClient. </summary> |
| | 27 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 28 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 29 | | /// <param name="endpoint"> server parameter. </param> |
| | 30 | | /// <param name="apiVersion"> Api Version. </param> |
| | 31 | | /// <exception cref="ArgumentNullException"> <paramref name="apiVersion"/> is null. </exception> |
| 0 | 32 | | public MessagesRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null, strin |
| | 33 | | { |
| 0 | 34 | | endpoint ??= new Uri("https://fully-qualified-iothubname.azure-devices.net"); |
| 0 | 35 | | if (apiVersion == null) |
| | 36 | | { |
| 0 | 37 | | throw new ArgumentNullException(nameof(apiVersion)); |
| | 38 | | } |
| | 39 | |
|
| 0 | 40 | | this.endpoint = endpoint; |
| 0 | 41 | | this.apiVersion = apiVersion; |
| 0 | 42 | | _clientDiagnostics = clientDiagnostics; |
| 0 | 43 | | _pipeline = pipeline; |
| 0 | 44 | | } |
| | 45 | |
|
| | 46 | | internal HttpMessage CreatePurgeCloudToDeviceMessageQueueRequest(string id) |
| | 47 | | { |
| 0 | 48 | | var message = _pipeline.CreateMessage(); |
| 0 | 49 | | var request = message.Request; |
| 0 | 50 | | request.Method = RequestMethod.Delete; |
| 0 | 51 | | var uri = new RawRequestUriBuilder(); |
| 0 | 52 | | uri.Reset(endpoint); |
| 0 | 53 | | uri.AppendPath("/devices/", false); |
| 0 | 54 | | uri.AppendPath(id, true); |
| 0 | 55 | | uri.AppendPath("/commands", false); |
| 0 | 56 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 57 | | request.Uri = uri; |
| 0 | 58 | | return message; |
| | 59 | | } |
| | 60 | |
|
| | 61 | | /// <summary> Deletes all the pending commands for a device in the IoT Hub. </summary> |
| | 62 | | /// <param name="id"> The unique identifier of the device. </param> |
| | 63 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 64 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 65 | | public async Task<Response<PurgeMessageQueueResult>> PurgeCloudToDeviceMessageQueueAsync(string id, Cancellation |
| | 66 | | { |
| 0 | 67 | | if (id == null) |
| | 68 | | { |
| 0 | 69 | | throw new ArgumentNullException(nameof(id)); |
| | 70 | | } |
| | 71 | |
|
| 0 | 72 | | using var message = CreatePurgeCloudToDeviceMessageQueueRequest(id); |
| 0 | 73 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 74 | | switch (message.Response.Status) |
| | 75 | | { |
| | 76 | | case 200: |
| | 77 | | { |
| | 78 | | PurgeMessageQueueResult value = default; |
| 0 | 79 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 80 | | value = PurgeMessageQueueResult.DeserializePurgeMessageQueueResult(document.RootElement); |
| 0 | 81 | | return Response.FromValue(value, message.Response); |
| | 82 | | } |
| | 83 | | default: |
| 0 | 84 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 85 | | } |
| 0 | 86 | | } |
| | 87 | |
|
| | 88 | | /// <summary> Deletes all the pending commands for a device in the IoT Hub. </summary> |
| | 89 | | /// <param name="id"> The unique identifier of the device. </param> |
| | 90 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 91 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 92 | | public Response<PurgeMessageQueueResult> PurgeCloudToDeviceMessageQueue(string id, CancellationToken cancellatio |
| | 93 | | { |
| 0 | 94 | | if (id == null) |
| | 95 | | { |
| 0 | 96 | | throw new ArgumentNullException(nameof(id)); |
| | 97 | | } |
| | 98 | |
|
| 0 | 99 | | using var message = CreatePurgeCloudToDeviceMessageQueueRequest(id); |
| 0 | 100 | | _pipeline.Send(message, cancellationToken); |
| 0 | 101 | | switch (message.Response.Status) |
| | 102 | | { |
| | 103 | | case 200: |
| | 104 | | { |
| | 105 | | PurgeMessageQueueResult value = default; |
| 0 | 106 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 107 | | value = PurgeMessageQueueResult.DeserializePurgeMessageQueueResult(document.RootElement); |
| 0 | 108 | | return Response.FromValue(value, message.Response); |
| | 109 | | } |
| | 110 | | default: |
| 0 | 111 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 112 | | } |
| 0 | 113 | | } |
| | 114 | | } |
| | 115 | | } |