| | 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 | |
|
| | 16 | | namespace Azure.DigitalTwins.Core |
| | 17 | | { |
| | 18 | | internal partial class EventRoutesRestClient |
| | 19 | | { |
| | 20 | | private Uri endpoint; |
| | 21 | | private string apiVersion; |
| | 22 | | private ClientDiagnostics _clientDiagnostics; |
| | 23 | | private HttpPipeline _pipeline; |
| | 24 | |
|
| | 25 | | /// <summary> Initializes a new instance of EventRoutesRestClient. </summary> |
| | 26 | | /// <param name="clientDiagnostics"> The handler for diagnostic messaging in the client. </param> |
| | 27 | | /// <param name="pipeline"> The HTTP pipeline for sending and receiving REST requests and responses. </param> |
| | 28 | | /// <param name="endpoint"> server parameter. </param> |
| | 29 | | /// <param name="apiVersion"> Api Version. </param> |
| | 30 | | /// <exception cref="ArgumentNullException"> <paramref name="apiVersion"/> is null. </exception> |
| 60 | 31 | | public EventRoutesRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null, st |
| | 32 | | { |
| 60 | 33 | | endpoint ??= new Uri("https://digitaltwins-name.digitaltwins.azure.net"); |
| 60 | 34 | | if (apiVersion == null) |
| | 35 | | { |
| 0 | 36 | | throw new ArgumentNullException(nameof(apiVersion)); |
| | 37 | | } |
| | 38 | |
|
| 60 | 39 | | this.endpoint = endpoint; |
| 60 | 40 | | this.apiVersion = apiVersion; |
| 60 | 41 | | _clientDiagnostics = clientDiagnostics; |
| 60 | 42 | | _pipeline = pipeline; |
| 60 | 43 | | } |
| | 44 | |
|
| | 45 | | internal HttpMessage CreateListRequest(EventRoutesListOptions eventRoutesListOptions) |
| | 46 | | { |
| 4 | 47 | | var message = _pipeline.CreateMessage(); |
| 4 | 48 | | var request = message.Request; |
| 4 | 49 | | request.Method = RequestMethod.Get; |
| 4 | 50 | | var uri = new RawRequestUriBuilder(); |
| 4 | 51 | | uri.Reset(endpoint); |
| 4 | 52 | | uri.AppendPath("/eventroutes", false); |
| 4 | 53 | | uri.AppendQuery("api-version", apiVersion, true); |
| 4 | 54 | | request.Uri = uri; |
| 4 | 55 | | if (eventRoutesListOptions?.MaxItemCount != null) |
| | 56 | | { |
| 0 | 57 | | request.Headers.Add("x-ms-max-item-count", eventRoutesListOptions.MaxItemCount.Value); |
| | 58 | | } |
| 4 | 59 | | return message; |
| | 60 | | } |
| | 61 | |
|
| | 62 | | /// <summary> |
| | 63 | | /// Retrieves all event routes. |
| | 64 | | /// Status codes: |
| | 65 | | /// 200 (OK): Success. |
| | 66 | | /// 400 (Bad Request): The request is invalid. |
| | 67 | | /// </summary> |
| | 68 | | /// <param name="eventRoutesListOptions"> Parameter group. </param> |
| | 69 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 70 | | public async Task<Response<EventRouteCollection>> ListAsync(EventRoutesListOptions eventRoutesListOptions = null |
| | 71 | | { |
| 2 | 72 | | using var message = CreateListRequest(eventRoutesListOptions); |
| 2 | 73 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 2 | 74 | | switch (message.Response.Status) |
| | 75 | | { |
| | 76 | | case 200: |
| | 77 | | { |
| | 78 | | EventRouteCollection value = default; |
| 2 | 79 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 2 | 80 | | value = EventRouteCollection.DeserializeEventRouteCollection(document.RootElement); |
| 2 | 81 | | return Response.FromValue(value, message.Response); |
| | 82 | | } |
| | 83 | | default: |
| 0 | 84 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 85 | | } |
| 2 | 86 | | } |
| | 87 | |
|
| | 88 | | /// <summary> |
| | 89 | | /// Retrieves all event routes. |
| | 90 | | /// Status codes: |
| | 91 | | /// 200 (OK): Success. |
| | 92 | | /// 400 (Bad Request): The request is invalid. |
| | 93 | | /// </summary> |
| | 94 | | /// <param name="eventRoutesListOptions"> Parameter group. </param> |
| | 95 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 96 | | public Response<EventRouteCollection> List(EventRoutesListOptions eventRoutesListOptions = null, CancellationTok |
| | 97 | | { |
| 2 | 98 | | using var message = CreateListRequest(eventRoutesListOptions); |
| 2 | 99 | | _pipeline.Send(message, cancellationToken); |
| 2 | 100 | | switch (message.Response.Status) |
| | 101 | | { |
| | 102 | | case 200: |
| | 103 | | { |
| | 104 | | EventRouteCollection value = default; |
| 2 | 105 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 2 | 106 | | value = EventRouteCollection.DeserializeEventRouteCollection(document.RootElement); |
| 2 | 107 | | return Response.FromValue(value, message.Response); |
| | 108 | | } |
| | 109 | | default: |
| 0 | 110 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 111 | | } |
| 2 | 112 | | } |
| | 113 | |
|
| | 114 | | internal HttpMessage CreateGetByIdRequest(string id) |
| | 115 | | { |
| 12 | 116 | | var message = _pipeline.CreateMessage(); |
| 12 | 117 | | var request = message.Request; |
| 12 | 118 | | request.Method = RequestMethod.Get; |
| 12 | 119 | | var uri = new RawRequestUriBuilder(); |
| 12 | 120 | | uri.Reset(endpoint); |
| 12 | 121 | | uri.AppendPath("/eventroutes/", false); |
| 12 | 122 | | uri.AppendPath(id, true); |
| 12 | 123 | | uri.AppendQuery("api-version", apiVersion, true); |
| 12 | 124 | | request.Uri = uri; |
| 12 | 125 | | return message; |
| | 126 | | } |
| | 127 | |
|
| | 128 | | /// <summary> |
| | 129 | | /// Retrieves an event route. |
| | 130 | | /// Status codes: |
| | 131 | | /// 200 (OK): Success. |
| | 132 | | /// 404 (Not Found): There is no event route with the provided id. |
| | 133 | | /// </summary> |
| | 134 | | /// <param name="id"> The id for an event route. The id is unique within event routes and case sensitive. </para |
| | 135 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 136 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 137 | | public async Task<Response<EventRoute>> GetByIdAsync(string id, CancellationToken cancellationToken = default) |
| | 138 | | { |
| 6 | 139 | | if (id == null) |
| | 140 | | { |
| 0 | 141 | | throw new ArgumentNullException(nameof(id)); |
| | 142 | | } |
| | 143 | |
|
| 6 | 144 | | using var message = CreateGetByIdRequest(id); |
| 6 | 145 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 6 | 146 | | switch (message.Response.Status) |
| | 147 | | { |
| | 148 | | case 200: |
| | 149 | | { |
| | 150 | | EventRoute value = default; |
| 2 | 151 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 2 | 152 | | value = EventRoute.DeserializeEventRoute(document.RootElement); |
| 2 | 153 | | return Response.FromValue(value, message.Response); |
| | 154 | | } |
| | 155 | | default: |
| 4 | 156 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 157 | | } |
| 2 | 158 | | } |
| | 159 | |
|
| | 160 | | /// <summary> |
| | 161 | | /// Retrieves an event route. |
| | 162 | | /// Status codes: |
| | 163 | | /// 200 (OK): Success. |
| | 164 | | /// 404 (Not Found): There is no event route with the provided id. |
| | 165 | | /// </summary> |
| | 166 | | /// <param name="id"> The id for an event route. The id is unique within event routes and case sensitive. </para |
| | 167 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 168 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 169 | | public Response<EventRoute> GetById(string id, CancellationToken cancellationToken = default) |
| | 170 | | { |
| 6 | 171 | | if (id == null) |
| | 172 | | { |
| 0 | 173 | | throw new ArgumentNullException(nameof(id)); |
| | 174 | | } |
| | 175 | |
|
| 6 | 176 | | using var message = CreateGetByIdRequest(id); |
| 6 | 177 | | _pipeline.Send(message, cancellationToken); |
| 6 | 178 | | switch (message.Response.Status) |
| | 179 | | { |
| | 180 | | case 200: |
| | 181 | | { |
| | 182 | | EventRoute value = default; |
| 2 | 183 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 2 | 184 | | value = EventRoute.DeserializeEventRoute(document.RootElement); |
| 2 | 185 | | return Response.FromValue(value, message.Response); |
| | 186 | | } |
| | 187 | | default: |
| 4 | 188 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 189 | | } |
| 2 | 190 | | } |
| | 191 | |
|
| | 192 | | internal HttpMessage CreateAddRequest(string id, EventRoute eventRoute) |
| | 193 | | { |
| 12 | 194 | | var message = _pipeline.CreateMessage(); |
| 12 | 195 | | var request = message.Request; |
| 12 | 196 | | request.Method = RequestMethod.Put; |
| 12 | 197 | | var uri = new RawRequestUriBuilder(); |
| 12 | 198 | | uri.Reset(endpoint); |
| 12 | 199 | | uri.AppendPath("/eventroutes/", false); |
| 12 | 200 | | uri.AppendPath(id, true); |
| 12 | 201 | | uri.AppendQuery("api-version", apiVersion, true); |
| 12 | 202 | | request.Uri = uri; |
| 12 | 203 | | request.Headers.Add("Content-Type", "application/json"); |
| 12 | 204 | | if (eventRoute != null) |
| | 205 | | { |
| 12 | 206 | | var content = new Utf8JsonRequestContent(); |
| 12 | 207 | | content.JsonWriter.WriteObjectValue(eventRoute); |
| 12 | 208 | | request.Content = content; |
| | 209 | | } |
| 12 | 210 | | return message; |
| | 211 | | } |
| | 212 | |
|
| | 213 | | /// <summary> |
| | 214 | | /// Adds or replaces an event route. |
| | 215 | | /// Status codes: |
| | 216 | | /// 200 (OK): Success. |
| | 217 | | /// 400 (Bad Request): The request is invalid. |
| | 218 | | /// </summary> |
| | 219 | | /// <param name="id"> The id for an event route. The id is unique within event routes and case sensitive. </para |
| | 220 | | /// <param name="eventRoute"> The event route data. </param> |
| | 221 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 222 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 223 | | public async Task<Response> AddAsync(string id, EventRoute eventRoute = null, CancellationToken cancellationToke |
| | 224 | | { |
| 6 | 225 | | if (id == null) |
| | 226 | | { |
| 0 | 227 | | throw new ArgumentNullException(nameof(id)); |
| | 228 | | } |
| | 229 | |
|
| 6 | 230 | | using var message = CreateAddRequest(id, eventRoute); |
| 6 | 231 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 6 | 232 | | switch (message.Response.Status) |
| | 233 | | { |
| | 234 | | case 204: |
| 4 | 235 | | return message.Response; |
| | 236 | | default: |
| 2 | 237 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 238 | | } |
| 4 | 239 | | } |
| | 240 | |
|
| | 241 | | /// <summary> |
| | 242 | | /// Adds or replaces an event route. |
| | 243 | | /// Status codes: |
| | 244 | | /// 200 (OK): Success. |
| | 245 | | /// 400 (Bad Request): The request is invalid. |
| | 246 | | /// </summary> |
| | 247 | | /// <param name="id"> The id for an event route. The id is unique within event routes and case sensitive. </para |
| | 248 | | /// <param name="eventRoute"> The event route data. </param> |
| | 249 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 250 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 251 | | public Response Add(string id, EventRoute eventRoute = null, CancellationToken cancellationToken = default) |
| | 252 | | { |
| 6 | 253 | | if (id == null) |
| | 254 | | { |
| 0 | 255 | | throw new ArgumentNullException(nameof(id)); |
| | 256 | | } |
| | 257 | |
|
| 6 | 258 | | using var message = CreateAddRequest(id, eventRoute); |
| 6 | 259 | | _pipeline.Send(message, cancellationToken); |
| 6 | 260 | | switch (message.Response.Status) |
| | 261 | | { |
| | 262 | | case 204: |
| 4 | 263 | | return message.Response; |
| | 264 | | default: |
| 2 | 265 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 266 | | } |
| 4 | 267 | | } |
| | 268 | |
|
| | 269 | | internal HttpMessage CreateDeleteRequest(string id) |
| | 270 | | { |
| 8 | 271 | | var message = _pipeline.CreateMessage(); |
| 8 | 272 | | var request = message.Request; |
| 8 | 273 | | request.Method = RequestMethod.Delete; |
| 8 | 274 | | var uri = new RawRequestUriBuilder(); |
| 8 | 275 | | uri.Reset(endpoint); |
| 8 | 276 | | uri.AppendPath("/eventroutes/", false); |
| 8 | 277 | | uri.AppendPath(id, true); |
| 8 | 278 | | uri.AppendQuery("api-version", apiVersion, true); |
| 8 | 279 | | request.Uri = uri; |
| 8 | 280 | | return message; |
| | 281 | | } |
| | 282 | |
|
| | 283 | | /// <summary> |
| | 284 | | /// Deletes an event route. |
| | 285 | | /// Status codes: |
| | 286 | | /// 200 (OK): Success. |
| | 287 | | /// 404 (Not Found): There is no event route with the provided id. |
| | 288 | | /// </summary> |
| | 289 | | /// <param name="id"> The id for an event route. The id is unique within event routes and case sensitive. </para |
| | 290 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 291 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 292 | | public async Task<Response> DeleteAsync(string id, CancellationToken cancellationToken = default) |
| | 293 | | { |
| 4 | 294 | | if (id == null) |
| | 295 | | { |
| 0 | 296 | | throw new ArgumentNullException(nameof(id)); |
| | 297 | | } |
| | 298 | |
|
| 4 | 299 | | using var message = CreateDeleteRequest(id); |
| 4 | 300 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 4 | 301 | | switch (message.Response.Status) |
| | 302 | | { |
| | 303 | | case 204: |
| 4 | 304 | | return message.Response; |
| | 305 | | default: |
| 0 | 306 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 307 | | } |
| 4 | 308 | | } |
| | 309 | |
|
| | 310 | | /// <summary> |
| | 311 | | /// Deletes an event route. |
| | 312 | | /// Status codes: |
| | 313 | | /// 200 (OK): Success. |
| | 314 | | /// 404 (Not Found): There is no event route with the provided id. |
| | 315 | | /// </summary> |
| | 316 | | /// <param name="id"> The id for an event route. The id is unique within event routes and case sensitive. </para |
| | 317 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 318 | | /// <exception cref="ArgumentNullException"> <paramref name="id"/> is null. </exception> |
| | 319 | | public Response Delete(string id, CancellationToken cancellationToken = default) |
| | 320 | | { |
| 4 | 321 | | if (id == null) |
| | 322 | | { |
| 0 | 323 | | throw new ArgumentNullException(nameof(id)); |
| | 324 | | } |
| | 325 | |
|
| 4 | 326 | | using var message = CreateDeleteRequest(id); |
| 4 | 327 | | _pipeline.Send(message, cancellationToken); |
| 4 | 328 | | switch (message.Response.Status) |
| | 329 | | { |
| | 330 | | case 204: |
| 4 | 331 | | return message.Response; |
| | 332 | | default: |
| 0 | 333 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 334 | | } |
| 4 | 335 | | } |
| | 336 | |
|
| | 337 | | internal HttpMessage CreateListNextPageRequest(string nextLink, EventRoutesListOptions eventRoutesListOptions) |
| | 338 | | { |
| 0 | 339 | | var message = _pipeline.CreateMessage(); |
| 0 | 340 | | var request = message.Request; |
| 0 | 341 | | request.Method = RequestMethod.Get; |
| 0 | 342 | | var uri = new RawRequestUriBuilder(); |
| 0 | 343 | | uri.Reset(endpoint); |
| 0 | 344 | | uri.AppendRawNextLink(nextLink, false); |
| 0 | 345 | | request.Uri = uri; |
| 0 | 346 | | if (eventRoutesListOptions?.MaxItemCount != null) |
| | 347 | | { |
| 0 | 348 | | request.Headers.Add("x-ms-max-item-count", eventRoutesListOptions.MaxItemCount.Value); |
| | 349 | | } |
| 0 | 350 | | return message; |
| | 351 | | } |
| | 352 | |
|
| | 353 | | /// <summary> |
| | 354 | | /// Retrieves all event routes. |
| | 355 | | /// Status codes: |
| | 356 | | /// 200 (OK): Success. |
| | 357 | | /// 400 (Bad Request): The request is invalid. |
| | 358 | | /// </summary> |
| | 359 | | /// <param name="nextLink"> The URL to the next page of results. </param> |
| | 360 | | /// <param name="eventRoutesListOptions"> Parameter group. </param> |
| | 361 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 362 | | /// <exception cref="ArgumentNullException"> <paramref name="nextLink"/> is null. </exception> |
| | 363 | | public async Task<Response<EventRouteCollection>> ListNextPageAsync(string nextLink, EventRoutesListOptions even |
| | 364 | | { |
| 0 | 365 | | if (nextLink == null) |
| | 366 | | { |
| 0 | 367 | | throw new ArgumentNullException(nameof(nextLink)); |
| | 368 | | } |
| | 369 | |
|
| 0 | 370 | | using var message = CreateListNextPageRequest(nextLink, eventRoutesListOptions); |
| 0 | 371 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 0 | 372 | | switch (message.Response.Status) |
| | 373 | | { |
| | 374 | | case 200: |
| | 375 | | { |
| | 376 | | EventRouteCollection value = default; |
| 0 | 377 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 0 | 378 | | value = EventRouteCollection.DeserializeEventRouteCollection(document.RootElement); |
| 0 | 379 | | return Response.FromValue(value, message.Response); |
| | 380 | | } |
| | 381 | | default: |
| 0 | 382 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 383 | | } |
| 0 | 384 | | } |
| | 385 | |
|
| | 386 | | /// <summary> |
| | 387 | | /// Retrieves all event routes. |
| | 388 | | /// Status codes: |
| | 389 | | /// 200 (OK): Success. |
| | 390 | | /// 400 (Bad Request): The request is invalid. |
| | 391 | | /// </summary> |
| | 392 | | /// <param name="nextLink"> The URL to the next page of results. </param> |
| | 393 | | /// <param name="eventRoutesListOptions"> Parameter group. </param> |
| | 394 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 395 | | /// <exception cref="ArgumentNullException"> <paramref name="nextLink"/> is null. </exception> |
| | 396 | | public Response<EventRouteCollection> ListNextPage(string nextLink, EventRoutesListOptions eventRoutesListOption |
| | 397 | | { |
| 0 | 398 | | if (nextLink == null) |
| | 399 | | { |
| 0 | 400 | | throw new ArgumentNullException(nameof(nextLink)); |
| | 401 | | } |
| | 402 | |
|
| 0 | 403 | | using var message = CreateListNextPageRequest(nextLink, eventRoutesListOptions); |
| 0 | 404 | | _pipeline.Send(message, cancellationToken); |
| 0 | 405 | | switch (message.Response.Status) |
| | 406 | | { |
| | 407 | | case 200: |
| | 408 | | { |
| | 409 | | EventRouteCollection value = default; |
| 0 | 410 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 0 | 411 | | value = EventRouteCollection.DeserializeEventRouteCollection(document.RootElement); |
| 0 | 412 | | return Response.FromValue(value, message.Response); |
| | 413 | | } |
| | 414 | | default: |
| 0 | 415 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 416 | | } |
| 0 | 417 | | } |
| | 418 | | } |
| | 419 | | } |