| | 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.Threading; |
| | 10 | | using System.Threading.Tasks; |
| | 11 | | using Azure; |
| | 12 | | using Azure.Core; |
| | 13 | | using Azure.Core.Pipeline; |
| | 14 | |
|
| | 15 | | namespace Azure.Iot.Hub.Service |
| | 16 | | { |
| | 17 | | internal partial class CloudToDeviceMessagesRestClient |
| | 18 | | { |
| | 19 | | private Uri endpoint; |
| | 20 | | private string apiVersion; |
| | 21 | | private ClientDiagnostics _clientDiagnostics; |
| | 22 | | private HttpPipeline _pipeline; |
| | 23 | |
|
| | 24 | | /// <summary> Initializes a new instance of CloudToDeviceMessagesRestClient. </summary> |
| | 25 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 26 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 27 | | /// <param name="endpoint"> server parameter. </param> |
| | 28 | | /// <param name="apiVersion"> Api Version. </param> |
| | 29 | | /// <exception cref="ArgumentNullException"> <paramref name="apiVersion"/> is null. </exception> |
| 0 | 30 | | public CloudToDeviceMessagesRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint |
| | 31 | | { |
| 0 | 32 | | endpoint ??= new Uri("https://fully-qualified-iothubname.azure-devices.net"); |
| 0 | 33 | | if (apiVersion == null) |
| | 34 | | { |
| 0 | 35 | | throw new ArgumentNullException(nameof(apiVersion)); |
| | 36 | | } |
| | 37 | |
|
| 0 | 38 | | this.endpoint = endpoint; |
| 0 | 39 | | this.apiVersion = apiVersion; |
| 0 | 40 | | _clientDiagnostics = clientDiagnostics; |
| 0 | 41 | | _pipeline = pipeline; |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | internal HttpMessage CreateReceiveFeedbackNotificationRequest() |
| | 45 | | { |
| 0 | 46 | | var message = _pipeline.CreateMessage(); |
| 0 | 47 | | var request = message.Request; |
| 0 | 48 | | request.Method = RequestMethod.Get; |
| 0 | 49 | | var uri = new RawRequestUriBuilder(); |
| 0 | 50 | | uri.Reset(endpoint); |
| 0 | 51 | | uri.AppendPath("/messages/serviceBound/feedback", false); |
| 0 | 52 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 53 | | request.Uri = uri; |
| 0 | 54 | | return message; |
| | 55 | | } |
| | 56 | |
|
| | 57 | | /// <summary> Gets the feedback for cloud-to-device messages. See https://docs.microsoft.com/azure/iot-hub/iot-h |
| | 58 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 59 | | public async Task<Response> ReceiveFeedbackNotificationAsync(CancellationToken cancellationToken = default) |
| | 60 | | { |
| 0 | 61 | | using var message = CreateReceiveFeedbackNotificationRequest(); |
| 0 | 62 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 63 | | switch (message.Response.Status) |
| | 64 | | { |
| | 65 | | case 200: |
| | 66 | | case 204: |
| 0 | 67 | | return message.Response; |
| | 68 | | default: |
| 0 | 69 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 70 | | } |
| 0 | 71 | | } |
| | 72 | |
|
| | 73 | | /// <summary> Gets the feedback for cloud-to-device messages. See https://docs.microsoft.com/azure/iot-hub/iot-h |
| | 74 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 75 | | public Response ReceiveFeedbackNotification(CancellationToken cancellationToken = default) |
| | 76 | | { |
| 0 | 77 | | using var message = CreateReceiveFeedbackNotificationRequest(); |
| 0 | 78 | | _pipeline.Send(message, cancellationToken); |
| 0 | 79 | | switch (message.Response.Status) |
| | 80 | | { |
| | 81 | | case 200: |
| | 82 | | case 204: |
| 0 | 83 | | return message.Response; |
| | 84 | | default: |
| 0 | 85 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 86 | | } |
| 0 | 87 | | } |
| | 88 | |
|
| | 89 | | internal HttpMessage CreateCompleteFeedbackNotificationRequest(string lockToken) |
| | 90 | | { |
| 0 | 91 | | var message = _pipeline.CreateMessage(); |
| 0 | 92 | | var request = message.Request; |
| 0 | 93 | | request.Method = RequestMethod.Delete; |
| 0 | 94 | | var uri = new RawRequestUriBuilder(); |
| 0 | 95 | | uri.Reset(endpoint); |
| 0 | 96 | | uri.AppendPath("/messages/serviceBound/feedback/", false); |
| 0 | 97 | | uri.AppendPath(lockToken, true); |
| 0 | 98 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 99 | | request.Uri = uri; |
| 0 | 100 | | return message; |
| | 101 | | } |
| | 102 | |
|
| | 103 | | /// <summary> Completes the cloud-to-device feedback message. A completed message is deleted from the feedback q |
| | 104 | | /// <param name="lockToken"> The lock token obtained when the cloud-to-device message is received. This is used |
| | 105 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 106 | | /// <exception cref="ArgumentNullException"> <paramref name="lockToken"/> is null. </exception> |
| | 107 | | public async Task<Response> CompleteFeedbackNotificationAsync(string lockToken, CancellationToken cancellationTo |
| | 108 | | { |
| 0 | 109 | | if (lockToken == null) |
| | 110 | | { |
| 0 | 111 | | throw new ArgumentNullException(nameof(lockToken)); |
| | 112 | | } |
| | 113 | |
|
| 0 | 114 | | using var message = CreateCompleteFeedbackNotificationRequest(lockToken); |
| 0 | 115 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 116 | | switch (message.Response.Status) |
| | 117 | | { |
| | 118 | | case 204: |
| 0 | 119 | | return message.Response; |
| | 120 | | default: |
| 0 | 121 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 122 | | } |
| 0 | 123 | | } |
| | 124 | |
|
| | 125 | | /// <summary> Completes the cloud-to-device feedback message. A completed message is deleted from the feedback q |
| | 126 | | /// <param name="lockToken"> The lock token obtained when the cloud-to-device message is received. This is used |
| | 127 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 128 | | /// <exception cref="ArgumentNullException"> <paramref name="lockToken"/> is null. </exception> |
| | 129 | | public Response CompleteFeedbackNotification(string lockToken, CancellationToken cancellationToken = default) |
| | 130 | | { |
| 0 | 131 | | if (lockToken == null) |
| | 132 | | { |
| 0 | 133 | | throw new ArgumentNullException(nameof(lockToken)); |
| | 134 | | } |
| | 135 | |
|
| 0 | 136 | | using var message = CreateCompleteFeedbackNotificationRequest(lockToken); |
| 0 | 137 | | _pipeline.Send(message, cancellationToken); |
| 0 | 138 | | switch (message.Response.Status) |
| | 139 | | { |
| | 140 | | case 204: |
| 0 | 141 | | return message.Response; |
| | 142 | | default: |
| 0 | 143 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 144 | | } |
| 0 | 145 | | } |
| | 146 | |
|
| | 147 | | internal HttpMessage CreateAbandonFeedbackNotificationRequest(string lockToken) |
| | 148 | | { |
| 0 | 149 | | var message = _pipeline.CreateMessage(); |
| 0 | 150 | | var request = message.Request; |
| 0 | 151 | | request.Method = RequestMethod.Post; |
| 0 | 152 | | var uri = new RawRequestUriBuilder(); |
| 0 | 153 | | uri.Reset(endpoint); |
| 0 | 154 | | uri.AppendPath("/messages/serviceBound/feedback/", false); |
| 0 | 155 | | uri.AppendPath(lockToken, true); |
| 0 | 156 | | uri.AppendPath("/abandon", false); |
| 0 | 157 | | uri.AppendQuery("api-version", apiVersion, true); |
| 0 | 158 | | request.Uri = uri; |
| 0 | 159 | | return message; |
| | 160 | | } |
| | 161 | |
|
| | 162 | | /// <summary> Abandons a cloud-to-device feedback message. An abandoned message is deleted from the feedback que |
| | 163 | | /// <param name="lockToken"> The lock token obtained when the cloud-to-device message is received. This is used |
| | 164 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 165 | | /// <exception cref="ArgumentNullException"> <paramref name="lockToken"/> is null. </exception> |
| | 166 | | public async Task<Response> AbandonFeedbackNotificationAsync(string lockToken, CancellationToken cancellationTok |
| | 167 | | { |
| 0 | 168 | | if (lockToken == null) |
| | 169 | | { |
| 0 | 170 | | throw new ArgumentNullException(nameof(lockToken)); |
| | 171 | | } |
| | 172 | |
|
| 0 | 173 | | using var message = CreateAbandonFeedbackNotificationRequest(lockToken); |
| 0 | 174 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 175 | | switch (message.Response.Status) |
| | 176 | | { |
| | 177 | | case 204: |
| 0 | 178 | | return message.Response; |
| | 179 | | default: |
| 0 | 180 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 181 | | } |
| 0 | 182 | | } |
| | 183 | |
|
| | 184 | | /// <summary> Abandons a cloud-to-device feedback message. An abandoned message is deleted from the feedback que |
| | 185 | | /// <param name="lockToken"> The lock token obtained when the cloud-to-device message is received. This is used |
| | 186 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 187 | | /// <exception cref="ArgumentNullException"> <paramref name="lockToken"/> is null. </exception> |
| | 188 | | public Response AbandonFeedbackNotification(string lockToken, CancellationToken cancellationToken = default) |
| | 189 | | { |
| 0 | 190 | | if (lockToken == null) |
| | 191 | | { |
| 0 | 192 | | throw new ArgumentNullException(nameof(lockToken)); |
| | 193 | | } |
| | 194 | |
|
| 0 | 195 | | using var message = CreateAbandonFeedbackNotificationRequest(lockToken); |
| 0 | 196 | | _pipeline.Send(message, cancellationToken); |
| 0 | 197 | | switch (message.Response.Status) |
| | 198 | | { |
| | 199 | | case 204: |
| 0 | 200 | | return message.Response; |
| | 201 | | default: |
| 0 | 202 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 203 | | } |
| 0 | 204 | | } |
| | 205 | | } |
| | 206 | | } |