| | 1 | | // <auto-generated> |
| | 2 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 3 | | // Licensed under the MIT License. See License.txt in the project root for |
| | 4 | | // license information. |
| | 5 | | // |
| | 6 | | // Code generated by Microsoft (R) AutoRest Code Generator. |
| | 7 | | // Changes may cause incorrect behavior and will be lost if the code is |
| | 8 | | // regenerated. |
| | 9 | | // </auto-generated> |
| | 10 | |
|
| | 11 | | namespace Microsoft.Azure.CognitiveServices.Knowledge.QnAMaker |
| | 12 | | { |
| | 13 | | using Microsoft.Rest; |
| | 14 | | using Models; |
| | 15 | | using Newtonsoft.Json; |
| | 16 | | using System.Collections; |
| | 17 | | using System.Collections.Generic; |
| | 18 | | using System.IO; |
| | 19 | | using System.Linq; |
| | 20 | | using System.Net; |
| | 21 | | using System.Net.Http; |
| | 22 | | using System.Threading; |
| | 23 | | using System.Threading.Tasks; |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// Operations operations. |
| | 27 | | /// </summary> |
| | 28 | | public partial class Operations : IServiceOperations<QnAMakerClient>, IOperations |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the Operations class. |
| | 32 | | /// </summary> |
| | 33 | | /// <param name='client'> |
| | 34 | | /// Reference to the service client. |
| | 35 | | /// </param> |
| | 36 | | /// <exception cref="System.ArgumentNullException"> |
| | 37 | | /// Thrown when a required parameter is null |
| | 38 | | /// </exception> |
| 0 | 39 | | public Operations(QnAMakerClient client) |
| | 40 | | { |
| 0 | 41 | | if (client == null) |
| | 42 | | { |
| 0 | 43 | | throw new System.ArgumentNullException("client"); |
| | 44 | | } |
| 0 | 45 | | Client = client; |
| 0 | 46 | | } |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Gets a reference to the QnAMakerClient |
| | 50 | | /// </summary> |
| 0 | 51 | | public QnAMakerClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Gets details of a specific long running operation. |
| | 55 | | /// </summary> |
| | 56 | | /// <param name='operationId'> |
| | 57 | | /// Operation id. |
| | 58 | | /// </param> |
| | 59 | | /// <param name='customHeaders'> |
| | 60 | | /// Headers that will be added to request. |
| | 61 | | /// </param> |
| | 62 | | /// <param name='cancellationToken'> |
| | 63 | | /// The cancellation token. |
| | 64 | | /// </param> |
| | 65 | | /// <exception cref="ErrorResponseException"> |
| | 66 | | /// Thrown when the operation returned an invalid status code |
| | 67 | | /// </exception> |
| | 68 | | /// <exception cref="SerializationException"> |
| | 69 | | /// Thrown when unable to deserialize the response |
| | 70 | | /// </exception> |
| | 71 | | /// <exception cref="ValidationException"> |
| | 72 | | /// Thrown when a required parameter is null |
| | 73 | | /// </exception> |
| | 74 | | /// <exception cref="System.ArgumentNullException"> |
| | 75 | | /// Thrown when a required parameter is null |
| | 76 | | /// </exception> |
| | 77 | | /// <return> |
| | 78 | | /// A response object containing the response body and response headers. |
| | 79 | | /// </return> |
| | 80 | | public async Task<HttpOperationResponse<Operation,OperationsGetDetailsHeaders>> GetDetailsWithHttpMessagesAsync( |
| | 81 | | { |
| 0 | 82 | | if (Client.Endpoint == null) |
| | 83 | | { |
| 0 | 84 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 85 | | } |
| 0 | 86 | | if (operationId == null) |
| | 87 | | { |
| 0 | 88 | | throw new ValidationException(ValidationRules.CannotBeNull, "operationId"); |
| | 89 | | } |
| | 90 | | // Tracing |
| 0 | 91 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 92 | | string _invocationId = null; |
| 0 | 93 | | if (_shouldTrace) |
| | 94 | | { |
| 0 | 95 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 96 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 97 | | tracingParameters.Add("operationId", operationId); |
| 0 | 98 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 99 | | ServiceClientTracing.Enter(_invocationId, this, "GetDetails", tracingParameters); |
| | 100 | | } |
| | 101 | | // Construct URL |
| 0 | 102 | | var _baseUrl = Client.BaseUri; |
| 0 | 103 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "operations/{operationId}"; |
| 0 | 104 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 105 | | _url = _url.Replace("{operationId}", System.Uri.EscapeDataString(operationId)); |
| | 106 | | // Create HTTP transport objects |
| 0 | 107 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 108 | | HttpResponseMessage _httpResponse = null; |
| 0 | 109 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 110 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 111 | | // Set Headers |
| | 112 | |
|
| | 113 | |
|
| 0 | 114 | | if (customHeaders != null) |
| | 115 | | { |
| 0 | 116 | | foreach(var _header in customHeaders) |
| | 117 | | { |
| 0 | 118 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 119 | | { |
| 0 | 120 | | _httpRequest.Headers.Remove(_header.Key); |
| | 121 | | } |
| 0 | 122 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 123 | | } |
| | 124 | | } |
| | 125 | |
|
| | 126 | | // Serialize Request |
| 0 | 127 | | string _requestContent = null; |
| | 128 | | // Set Credentials |
| 0 | 129 | | if (Client.Credentials != null) |
| | 130 | | { |
| 0 | 131 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 132 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 133 | | } |
| | 134 | | // Send Request |
| 0 | 135 | | if (_shouldTrace) |
| | 136 | | { |
| 0 | 137 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 138 | | } |
| 0 | 139 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 140 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 141 | | if (_shouldTrace) |
| | 142 | | { |
| 0 | 143 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 144 | | } |
| 0 | 145 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 146 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 147 | | string _responseContent = null; |
| 0 | 148 | | if ((int)_statusCode != 200) |
| | 149 | | { |
| 0 | 150 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | 151 | | try |
| | 152 | | { |
| 0 | 153 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 154 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| 0 | 155 | | if (_errorBody != null) |
| | 156 | | { |
| 0 | 157 | | ex.Body = _errorBody; |
| | 158 | | } |
| 0 | 159 | | } |
| 0 | 160 | | catch (JsonException) |
| | 161 | | { |
| | 162 | | // Ignore the exception |
| 0 | 163 | | } |
| 0 | 164 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 165 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 166 | | if (_shouldTrace) |
| | 167 | | { |
| 0 | 168 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 169 | | } |
| 0 | 170 | | _httpRequest.Dispose(); |
| 0 | 171 | | if (_httpResponse != null) |
| | 172 | | { |
| 0 | 173 | | _httpResponse.Dispose(); |
| | 174 | | } |
| 0 | 175 | | throw ex; |
| | 176 | | } |
| | 177 | | // Create Result |
| 0 | 178 | | var _result = new HttpOperationResponse<Operation,OperationsGetDetailsHeaders>(); |
| 0 | 179 | | _result.Request = _httpRequest; |
| 0 | 180 | | _result.Response = _httpResponse; |
| | 181 | | // Deserialize Response |
| 0 | 182 | | if ((int)_statusCode == 200) |
| | 183 | | { |
| 0 | 184 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 185 | | try |
| | 186 | | { |
| 0 | 187 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Operation>(_responseContent, Cli |
| 0 | 188 | | } |
| 0 | 189 | | catch (JsonException ex) |
| | 190 | | { |
| 0 | 191 | | _httpRequest.Dispose(); |
| 0 | 192 | | if (_httpResponse != null) |
| | 193 | | { |
| 0 | 194 | | _httpResponse.Dispose(); |
| | 195 | | } |
| 0 | 196 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 197 | | } |
| | 198 | | } |
| | 199 | | try |
| | 200 | | { |
| 0 | 201 | | _result.Headers = _httpResponse.GetHeadersAsJson().ToObject<OperationsGetDetailsHeaders>(JsonSerializer. |
| 0 | 202 | | } |
| 0 | 203 | | catch (JsonException ex) |
| | 204 | | { |
| 0 | 205 | | _httpRequest.Dispose(); |
| 0 | 206 | | if (_httpResponse != null) |
| | 207 | | { |
| 0 | 208 | | _httpResponse.Dispose(); |
| | 209 | | } |
| 0 | 210 | | throw new SerializationException("Unable to deserialize the headers.", _httpResponse.GetHeadersAsJson(). |
| | 211 | | } |
| 0 | 212 | | if (_shouldTrace) |
| | 213 | | { |
| 0 | 214 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 215 | | } |
| 0 | 216 | | return _result; |
| 0 | 217 | | } |
| | 218 | |
|
| | 219 | | } |
| | 220 | | } |