| | 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.Core; |
| | 13 | | using Azure.Core.Pipeline; |
| | 14 | |
|
| | 15 | | namespace Azure.DigitalTwins.Core |
| | 16 | | { |
| | 17 | | internal partial class QueryRestClient |
| | 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 QueryRestClient. </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> |
| 60 | 30 | | public QueryRestClient(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Uri endpoint = null, string a |
| | 31 | | { |
| 60 | 32 | | endpoint ??= new Uri("https://digitaltwins-name.digitaltwins.azure.net"); |
| 60 | 33 | | if (apiVersion == null) |
| | 34 | | { |
| 0 | 35 | | throw new ArgumentNullException(nameof(apiVersion)); |
| | 36 | | } |
| | 37 | |
|
| 60 | 38 | | this.endpoint = endpoint; |
| 60 | 39 | | this.apiVersion = apiVersion; |
| 60 | 40 | | _clientDiagnostics = clientDiagnostics; |
| 60 | 41 | | _pipeline = pipeline; |
| 60 | 42 | | } |
| | 43 | |
|
| | 44 | | internal HttpMessage CreateQueryTwinsRequest(QuerySpecification querySpecification) |
| | 45 | | { |
| 4 | 46 | | var message = _pipeline.CreateMessage(); |
| 4 | 47 | | var request = message.Request; |
| 4 | 48 | | request.Method = RequestMethod.Post; |
| 4 | 49 | | var uri = new RawRequestUriBuilder(); |
| 4 | 50 | | uri.Reset(endpoint); |
| 4 | 51 | | uri.AppendPath("/query", false); |
| 4 | 52 | | uri.AppendQuery("api-version", apiVersion, true); |
| 4 | 53 | | request.Uri = uri; |
| 4 | 54 | | request.Headers.Add("Content-Type", "application/json"); |
| 4 | 55 | | var content = new Utf8JsonRequestContent(); |
| 4 | 56 | | content.JsonWriter.WriteObjectValue(querySpecification); |
| 4 | 57 | | request.Content = content; |
| 4 | 58 | | return message; |
| | 59 | | } |
| | 60 | |
|
| | 61 | | /// <summary> |
| | 62 | | /// Executes a query that allows traversing relationships and filtering by property values. |
| | 63 | | /// Status codes: |
| | 64 | | /// 200 (OK): Success. |
| | 65 | | /// 400 (Bad Request): The request is invalid. |
| | 66 | | /// </summary> |
| | 67 | | /// <param name="querySpecification"> The query specification to execute. </param> |
| | 68 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 69 | | /// <exception cref="ArgumentNullException"> <paramref name="querySpecification"/> is null. </exception> |
| | 70 | | public async Task<ResponseWithHeaders<QueryResult, QueryQueryTwinsHeaders>> QueryTwinsAsync(QuerySpecification q |
| | 71 | | { |
| 2 | 72 | | if (querySpecification == null) |
| | 73 | | { |
| 0 | 74 | | throw new ArgumentNullException(nameof(querySpecification)); |
| | 75 | | } |
| | 76 | |
|
| 2 | 77 | | using var message = CreateQueryTwinsRequest(querySpecification); |
| 2 | 78 | | await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); |
| 2 | 79 | | var headers = new QueryQueryTwinsHeaders(message.Response); |
| 2 | 80 | | switch (message.Response.Status) |
| | 81 | | { |
| | 82 | | case 200: |
| | 83 | | { |
| | 84 | | QueryResult value = default; |
| 2 | 85 | | using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, canc |
| 2 | 86 | | value = QueryResult.DeserializeQueryResult(document.RootElement); |
| 2 | 87 | | return ResponseWithHeaders.FromValue(value, headers, message.Response); |
| | 88 | | } |
| | 89 | | default: |
| 0 | 90 | | throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(fa |
| | 91 | | } |
| 2 | 92 | | } |
| | 93 | |
|
| | 94 | | /// <summary> |
| | 95 | | /// Executes a query that allows traversing relationships and filtering by property values. |
| | 96 | | /// Status codes: |
| | 97 | | /// 200 (OK): Success. |
| | 98 | | /// 400 (Bad Request): The request is invalid. |
| | 99 | | /// </summary> |
| | 100 | | /// <param name="querySpecification"> The query specification to execute. </param> |
| | 101 | | /// <param name="cancellationToken"> The cancellation token to use. </param> |
| | 102 | | /// <exception cref="ArgumentNullException"> <paramref name="querySpecification"/> is null. </exception> |
| | 103 | | public ResponseWithHeaders<QueryResult, QueryQueryTwinsHeaders> QueryTwins(QuerySpecification querySpecification |
| | 104 | | { |
| 2 | 105 | | if (querySpecification == null) |
| | 106 | | { |
| 0 | 107 | | throw new ArgumentNullException(nameof(querySpecification)); |
| | 108 | | } |
| | 109 | |
|
| 2 | 110 | | using var message = CreateQueryTwinsRequest(querySpecification); |
| 2 | 111 | | _pipeline.Send(message, cancellationToken); |
| 2 | 112 | | var headers = new QueryQueryTwinsHeaders(message.Response); |
| 2 | 113 | | switch (message.Response.Status) |
| | 114 | | { |
| | 115 | | case 200: |
| | 116 | | { |
| | 117 | | QueryResult value = default; |
| 2 | 118 | | using var document = JsonDocument.Parse(message.Response.ContentStream); |
| 2 | 119 | | value = QueryResult.DeserializeQueryResult(document.RootElement); |
| 2 | 120 | | return ResponseWithHeaders.FromValue(value, headers, message.Response); |
| | 121 | | } |
| | 122 | | default: |
| 0 | 123 | | throw _clientDiagnostics.CreateRequestFailedException(message.Response); |
| | 124 | | } |
| 2 | 125 | | } |
| | 126 | | } |
| | 127 | | } |