| | | 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.Language.LUIS.Authoring |
| | | 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 | | /// Examples operations. |
| | | 27 | | /// </summary> |
| | | 28 | | public partial class Examples : IServiceOperations<LUISAuthoringClient>, IExamples |
| | | 29 | | { |
| | | 30 | | /// <summary> |
| | | 31 | | /// Initializes a new instance of the Examples 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> |
| | 156 | 39 | | public Examples(LUISAuthoringClient client) |
| | | 40 | | { |
| | 156 | 41 | | if (client == null) |
| | | 42 | | { |
| | 0 | 43 | | throw new System.ArgumentNullException("client"); |
| | | 44 | | } |
| | 156 | 45 | | Client = client; |
| | 156 | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <summary> |
| | | 49 | | /// Gets a reference to the LUISAuthoringClient |
| | | 50 | | /// </summary> |
| | 259 | 51 | | public LUISAuthoringClient Client { get; private set; } |
| | | 52 | | |
| | | 53 | | /// <summary> |
| | | 54 | | /// Adds a labeled example utterance in a version of the application. |
| | | 55 | | /// </summary> |
| | | 56 | | /// <param name='appId'> |
| | | 57 | | /// The application ID. |
| | | 58 | | /// </param> |
| | | 59 | | /// <param name='versionId'> |
| | | 60 | | /// The version ID. |
| | | 61 | | /// </param> |
| | | 62 | | /// <param name='exampleLabelObject'> |
| | | 63 | | /// A labeled example utterance with the expected intent and entities. |
| | | 64 | | /// </param> |
| | | 65 | | /// <param name='enableNestedChildren'> |
| | | 66 | | /// Toggles nested/flat format |
| | | 67 | | /// </param> |
| | | 68 | | /// <param name='customHeaders'> |
| | | 69 | | /// Headers that will be added to request. |
| | | 70 | | /// </param> |
| | | 71 | | /// <param name='cancellationToken'> |
| | | 72 | | /// The cancellation token. |
| | | 73 | | /// </param> |
| | | 74 | | /// <exception cref="ErrorResponseException"> |
| | | 75 | | /// Thrown when the operation returned an invalid status code |
| | | 76 | | /// </exception> |
| | | 77 | | /// <exception cref="SerializationException"> |
| | | 78 | | /// Thrown when unable to deserialize the response |
| | | 79 | | /// </exception> |
| | | 80 | | /// <exception cref="ValidationException"> |
| | | 81 | | /// Thrown when a required parameter is null |
| | | 82 | | /// </exception> |
| | | 83 | | /// <exception cref="System.ArgumentNullException"> |
| | | 84 | | /// Thrown when a required parameter is null |
| | | 85 | | /// </exception> |
| | | 86 | | /// <return> |
| | | 87 | | /// A response object containing the response body and response headers. |
| | | 88 | | /// </return> |
| | | 89 | | public async Task<HttpOperationResponse<LabelExampleResponse>> AddWithHttpMessagesAsync(System.Guid appId, strin |
| | | 90 | | { |
| | 3 | 91 | | if (Client.Endpoint == null) |
| | | 92 | | { |
| | 0 | 93 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | | 94 | | } |
| | 3 | 95 | | if (versionId == null) |
| | | 96 | | { |
| | 0 | 97 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | | 98 | | } |
| | 3 | 99 | | if (exampleLabelObject == null) |
| | | 100 | | { |
| | 0 | 101 | | throw new ValidationException(ValidationRules.CannotBeNull, "exampleLabelObject"); |
| | | 102 | | } |
| | | 103 | | // Tracing |
| | 3 | 104 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 3 | 105 | | string _invocationId = null; |
| | 3 | 106 | | if (_shouldTrace) |
| | | 107 | | { |
| | 0 | 108 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 0 | 109 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 0 | 110 | | tracingParameters.Add("appId", appId); |
| | 0 | 111 | | tracingParameters.Add("versionId", versionId); |
| | 0 | 112 | | tracingParameters.Add("enableNestedChildren", enableNestedChildren); |
| | 0 | 113 | | tracingParameters.Add("exampleLabelObject", exampleLabelObject); |
| | 0 | 114 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 0 | 115 | | ServiceClientTracing.Enter(_invocationId, this, "Add", tracingParameters); |
| | | 116 | | } |
| | | 117 | | // Construct URL |
| | 3 | 118 | | var _baseUrl = Client.BaseUri; |
| | 3 | 119 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/example"; |
| | 3 | 120 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 3 | 121 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 3 | 122 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 3 | 123 | | List<string> _queryParameters = new List<string>(); |
| | 3 | 124 | | if (enableNestedChildren != null) |
| | | 125 | | { |
| | 3 | 126 | | _queryParameters.Add(string.Format("enableNestedChildren={0}", System.Uri.EscapeDataString(Rest.Serializ |
| | | 127 | | } |
| | 3 | 128 | | if (_queryParameters.Count > 0) |
| | | 129 | | { |
| | 3 | 130 | | _url += "?" + string.Join("&", _queryParameters); |
| | | 131 | | } |
| | | 132 | | // Create HTTP transport objects |
| | 3 | 133 | | var _httpRequest = new HttpRequestMessage(); |
| | 3 | 134 | | HttpResponseMessage _httpResponse = null; |
| | 3 | 135 | | _httpRequest.Method = new HttpMethod("POST"); |
| | 3 | 136 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | | 137 | | // Set Headers |
| | | 138 | | |
| | | 139 | | |
| | 3 | 140 | | if (customHeaders != null) |
| | | 141 | | { |
| | 0 | 142 | | foreach(var _header in customHeaders) |
| | | 143 | | { |
| | 0 | 144 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | | 145 | | { |
| | 0 | 146 | | _httpRequest.Headers.Remove(_header.Key); |
| | | 147 | | } |
| | 0 | 148 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | | 149 | | } |
| | | 150 | | } |
| | | 151 | | |
| | | 152 | | // Serialize Request |
| | 3 | 153 | | string _requestContent = null; |
| | 3 | 154 | | if(exampleLabelObject != null) |
| | | 155 | | { |
| | 3 | 156 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(exampleLabelObject, Client.Serializ |
| | 3 | 157 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| | 3 | 158 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | | 159 | | } |
| | | 160 | | // Set Credentials |
| | 3 | 161 | | if (Client.Credentials != null) |
| | | 162 | | { |
| | 3 | 163 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 3 | 164 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | | 165 | | } |
| | | 166 | | // Send Request |
| | 3 | 167 | | if (_shouldTrace) |
| | | 168 | | { |
| | 0 | 169 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | | 170 | | } |
| | 3 | 171 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 3 | 172 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3 | 173 | | if (_shouldTrace) |
| | | 174 | | { |
| | 0 | 175 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | | 176 | | } |
| | 3 | 177 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 3 | 178 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 3 | 179 | | string _responseContent = null; |
| | 3 | 180 | | if ((int)_statusCode != 201) |
| | | 181 | | { |
| | 0 | 182 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | | 183 | | try |
| | | 184 | | { |
| | 0 | 185 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 0 | 186 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| | 0 | 187 | | if (_errorBody != null) |
| | | 188 | | { |
| | 0 | 189 | | ex.Body = _errorBody; |
| | | 190 | | } |
| | 0 | 191 | | } |
| | 0 | 192 | | catch (JsonException) |
| | | 193 | | { |
| | | 194 | | // Ignore the exception |
| | 0 | 195 | | } |
| | 0 | 196 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 0 | 197 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 0 | 198 | | if (_shouldTrace) |
| | | 199 | | { |
| | 0 | 200 | | ServiceClientTracing.Error(_invocationId, ex); |
| | | 201 | | } |
| | 0 | 202 | | _httpRequest.Dispose(); |
| | 0 | 203 | | if (_httpResponse != null) |
| | | 204 | | { |
| | 0 | 205 | | _httpResponse.Dispose(); |
| | | 206 | | } |
| | 0 | 207 | | throw ex; |
| | | 208 | | } |
| | | 209 | | // Create Result |
| | 3 | 210 | | var _result = new HttpOperationResponse<LabelExampleResponse>(); |
| | 3 | 211 | | _result.Request = _httpRequest; |
| | 3 | 212 | | _result.Response = _httpResponse; |
| | | 213 | | // Deserialize Response |
| | 3 | 214 | | if ((int)_statusCode == 201) |
| | | 215 | | { |
| | 3 | 216 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | | 217 | | try |
| | | 218 | | { |
| | 3 | 219 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<LabelExampleResponse>(_responseC |
| | 3 | 220 | | } |
| | 0 | 221 | | catch (JsonException ex) |
| | | 222 | | { |
| | 0 | 223 | | _httpRequest.Dispose(); |
| | 0 | 224 | | if (_httpResponse != null) |
| | | 225 | | { |
| | 0 | 226 | | _httpResponse.Dispose(); |
| | | 227 | | } |
| | 0 | 228 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | | 229 | | } |
| | | 230 | | } |
| | 3 | 231 | | if (_shouldTrace) |
| | | 232 | | { |
| | 0 | 233 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | | 234 | | } |
| | 3 | 235 | | return _result; |
| | 3 | 236 | | } |
| | | 237 | | |
| | | 238 | | /// <summary> |
| | | 239 | | /// Adds a batch of labeled example utterances to a version of the application. |
| | | 240 | | /// </summary> |
| | | 241 | | /// <param name='appId'> |
| | | 242 | | /// The application ID. |
| | | 243 | | /// </param> |
| | | 244 | | /// <param name='versionId'> |
| | | 245 | | /// The version ID. |
| | | 246 | | /// </param> |
| | | 247 | | /// <param name='exampleLabelObjectArray'> |
| | | 248 | | /// Array of example utterances. |
| | | 249 | | /// </param> |
| | | 250 | | /// <param name='enableNestedChildren'> |
| | | 251 | | /// Toggles nested/flat format |
| | | 252 | | /// </param> |
| | | 253 | | /// <param name='customHeaders'> |
| | | 254 | | /// Headers that will be added to request. |
| | | 255 | | /// </param> |
| | | 256 | | /// <param name='cancellationToken'> |
| | | 257 | | /// The cancellation token. |
| | | 258 | | /// </param> |
| | | 259 | | /// <exception cref="ErrorResponseException"> |
| | | 260 | | /// Thrown when the operation returned an invalid status code |
| | | 261 | | /// </exception> |
| | | 262 | | /// <exception cref="SerializationException"> |
| | | 263 | | /// Thrown when unable to deserialize the response |
| | | 264 | | /// </exception> |
| | | 265 | | /// <exception cref="ValidationException"> |
| | | 266 | | /// Thrown when a required parameter is null |
| | | 267 | | /// </exception> |
| | | 268 | | /// <exception cref="System.ArgumentNullException"> |
| | | 269 | | /// Thrown when a required parameter is null |
| | | 270 | | /// </exception> |
| | | 271 | | /// <return> |
| | | 272 | | /// A response object containing the response body and response headers. |
| | | 273 | | /// </return> |
| | | 274 | | public async Task<HttpOperationResponse<IList<BatchLabelExample>>> BatchWithHttpMessagesAsync(System.Guid appId, |
| | | 275 | | { |
| | 2 | 276 | | if (Client.Endpoint == null) |
| | | 277 | | { |
| | 0 | 278 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | | 279 | | } |
| | 2 | 280 | | if (versionId == null) |
| | | 281 | | { |
| | 0 | 282 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | | 283 | | } |
| | 2 | 284 | | if (exampleLabelObjectArray == null) |
| | | 285 | | { |
| | 0 | 286 | | throw new ValidationException(ValidationRules.CannotBeNull, "exampleLabelObjectArray"); |
| | | 287 | | } |
| | | 288 | | // Tracing |
| | 2 | 289 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 2 | 290 | | string _invocationId = null; |
| | 2 | 291 | | if (_shouldTrace) |
| | | 292 | | { |
| | 0 | 293 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 0 | 294 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 0 | 295 | | tracingParameters.Add("appId", appId); |
| | 0 | 296 | | tracingParameters.Add("versionId", versionId); |
| | 0 | 297 | | tracingParameters.Add("enableNestedChildren", enableNestedChildren); |
| | 0 | 298 | | tracingParameters.Add("exampleLabelObjectArray", exampleLabelObjectArray); |
| | 0 | 299 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 0 | 300 | | ServiceClientTracing.Enter(_invocationId, this, "Batch", tracingParameters); |
| | | 301 | | } |
| | | 302 | | // Construct URL |
| | 2 | 303 | | var _baseUrl = Client.BaseUri; |
| | 2 | 304 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/examples"; |
| | 2 | 305 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 2 | 306 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 2 | 307 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 2 | 308 | | List<string> _queryParameters = new List<string>(); |
| | 2 | 309 | | if (enableNestedChildren != null) |
| | | 310 | | { |
| | 2 | 311 | | _queryParameters.Add(string.Format("enableNestedChildren={0}", System.Uri.EscapeDataString(Rest.Serializ |
| | | 312 | | } |
| | 2 | 313 | | if (_queryParameters.Count > 0) |
| | | 314 | | { |
| | 2 | 315 | | _url += "?" + string.Join("&", _queryParameters); |
| | | 316 | | } |
| | | 317 | | // Create HTTP transport objects |
| | 2 | 318 | | var _httpRequest = new HttpRequestMessage(); |
| | 2 | 319 | | HttpResponseMessage _httpResponse = null; |
| | 2 | 320 | | _httpRequest.Method = new HttpMethod("POST"); |
| | 2 | 321 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | | 322 | | // Set Headers |
| | | 323 | | |
| | | 324 | | |
| | 2 | 325 | | if (customHeaders != null) |
| | | 326 | | { |
| | 0 | 327 | | foreach(var _header in customHeaders) |
| | | 328 | | { |
| | 0 | 329 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | | 330 | | { |
| | 0 | 331 | | _httpRequest.Headers.Remove(_header.Key); |
| | | 332 | | } |
| | 0 | 333 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | | 334 | | } |
| | | 335 | | } |
| | | 336 | | |
| | | 337 | | // Serialize Request |
| | 2 | 338 | | string _requestContent = null; |
| | 2 | 339 | | if(exampleLabelObjectArray != null) |
| | | 340 | | { |
| | 2 | 341 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(exampleLabelObjectArray, Client.Ser |
| | 2 | 342 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| | 2 | 343 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | | 344 | | } |
| | | 345 | | // Set Credentials |
| | 2 | 346 | | if (Client.Credentials != null) |
| | | 347 | | { |
| | 2 | 348 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 2 | 349 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | | 350 | | } |
| | | 351 | | // Send Request |
| | 2 | 352 | | if (_shouldTrace) |
| | | 353 | | { |
| | 0 | 354 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | | 355 | | } |
| | 2 | 356 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 2 | 357 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2 | 358 | | if (_shouldTrace) |
| | | 359 | | { |
| | 0 | 360 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | | 361 | | } |
| | 2 | 362 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 2 | 363 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 2 | 364 | | string _responseContent = null; |
| | 2 | 365 | | if ((int)_statusCode != 201 && (int)_statusCode != 207) |
| | | 366 | | { |
| | 0 | 367 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | | 368 | | try |
| | | 369 | | { |
| | 0 | 370 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 0 | 371 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| | 0 | 372 | | if (_errorBody != null) |
| | | 373 | | { |
| | 0 | 374 | | ex.Body = _errorBody; |
| | | 375 | | } |
| | 0 | 376 | | } |
| | 0 | 377 | | catch (JsonException) |
| | | 378 | | { |
| | | 379 | | // Ignore the exception |
| | 0 | 380 | | } |
| | 0 | 381 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 0 | 382 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 0 | 383 | | if (_shouldTrace) |
| | | 384 | | { |
| | 0 | 385 | | ServiceClientTracing.Error(_invocationId, ex); |
| | | 386 | | } |
| | 0 | 387 | | _httpRequest.Dispose(); |
| | 0 | 388 | | if (_httpResponse != null) |
| | | 389 | | { |
| | 0 | 390 | | _httpResponse.Dispose(); |
| | | 391 | | } |
| | 0 | 392 | | throw ex; |
| | | 393 | | } |
| | | 394 | | // Create Result |
| | 2 | 395 | | var _result = new HttpOperationResponse<IList<BatchLabelExample>>(); |
| | 2 | 396 | | _result.Request = _httpRequest; |
| | 2 | 397 | | _result.Response = _httpResponse; |
| | | 398 | | // Deserialize Response |
| | 2 | 399 | | if ((int)_statusCode == 201) |
| | | 400 | | { |
| | 1 | 401 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | | 402 | | try |
| | | 403 | | { |
| | 1 | 404 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<BatchLabelExample>>(_respo |
| | 1 | 405 | | } |
| | 0 | 406 | | catch (JsonException ex) |
| | | 407 | | { |
| | 0 | 408 | | _httpRequest.Dispose(); |
| | 0 | 409 | | if (_httpResponse != null) |
| | | 410 | | { |
| | 0 | 411 | | _httpResponse.Dispose(); |
| | | 412 | | } |
| | 0 | 413 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | | 414 | | } |
| | | 415 | | } |
| | | 416 | | // Deserialize Response |
| | 2 | 417 | | if ((int)_statusCode == 207) |
| | | 418 | | { |
| | 1 | 419 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | | 420 | | try |
| | | 421 | | { |
| | 1 | 422 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<BatchLabelExample>>(_respo |
| | 1 | 423 | | } |
| | 0 | 424 | | catch (JsonException ex) |
| | | 425 | | { |
| | 0 | 426 | | _httpRequest.Dispose(); |
| | 0 | 427 | | if (_httpResponse != null) |
| | | 428 | | { |
| | 0 | 429 | | _httpResponse.Dispose(); |
| | | 430 | | } |
| | 0 | 431 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | | 432 | | } |
| | | 433 | | } |
| | 2 | 434 | | if (_shouldTrace) |
| | | 435 | | { |
| | 0 | 436 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | | 437 | | } |
| | 2 | 438 | | return _result; |
| | 2 | 439 | | } |
| | | 440 | | |
| | | 441 | | /// <summary> |
| | | 442 | | /// Returns example utterances to be reviewed from a version of the |
| | | 443 | | /// application. |
| | | 444 | | /// </summary> |
| | | 445 | | /// <param name='appId'> |
| | | 446 | | /// The application ID. |
| | | 447 | | /// </param> |
| | | 448 | | /// <param name='versionId'> |
| | | 449 | | /// The version ID. |
| | | 450 | | /// </param> |
| | | 451 | | /// <param name='skip'> |
| | | 452 | | /// The number of entries to skip. Default value is 0. |
| | | 453 | | /// </param> |
| | | 454 | | /// <param name='take'> |
| | | 455 | | /// The number of entries to return. Maximum page size is 500. Default is 100. |
| | | 456 | | /// </param> |
| | | 457 | | /// <param name='enableNestedChildren'> |
| | | 458 | | /// Toggles nested/flat format |
| | | 459 | | /// </param> |
| | | 460 | | /// <param name='customHeaders'> |
| | | 461 | | /// Headers that will be added to request. |
| | | 462 | | /// </param> |
| | | 463 | | /// <param name='cancellationToken'> |
| | | 464 | | /// The cancellation token. |
| | | 465 | | /// </param> |
| | | 466 | | /// <exception cref="ErrorResponseException"> |
| | | 467 | | /// Thrown when the operation returned an invalid status code |
| | | 468 | | /// </exception> |
| | | 469 | | /// <exception cref="SerializationException"> |
| | | 470 | | /// Thrown when unable to deserialize the response |
| | | 471 | | /// </exception> |
| | | 472 | | /// <exception cref="ValidationException"> |
| | | 473 | | /// Thrown when a required parameter is null |
| | | 474 | | /// </exception> |
| | | 475 | | /// <exception cref="System.ArgumentNullException"> |
| | | 476 | | /// Thrown when a required parameter is null |
| | | 477 | | /// </exception> |
| | | 478 | | /// <return> |
| | | 479 | | /// A response object containing the response body and response headers. |
| | | 480 | | /// </return> |
| | | 481 | | public async Task<HttpOperationResponse<IList<LabeledUtterance>>> ListWithHttpMessagesAsync(System.Guid appId, s |
| | | 482 | | { |
| | 4 | 483 | | if (Client.Endpoint == null) |
| | | 484 | | { |
| | 0 | 485 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | | 486 | | } |
| | 4 | 487 | | if (versionId == null) |
| | | 488 | | { |
| | 0 | 489 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | | 490 | | } |
| | 4 | 491 | | if (skip < 0) |
| | | 492 | | { |
| | 0 | 493 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "skip", 0); |
| | | 494 | | } |
| | 4 | 495 | | if (take > 500) |
| | | 496 | | { |
| | 0 | 497 | | throw new ValidationException(ValidationRules.InclusiveMaximum, "take", 500); |
| | | 498 | | } |
| | 4 | 499 | | if (take < 0) |
| | | 500 | | { |
| | 0 | 501 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "take", 0); |
| | | 502 | | } |
| | | 503 | | // Tracing |
| | 4 | 504 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 4 | 505 | | string _invocationId = null; |
| | 4 | 506 | | if (_shouldTrace) |
| | | 507 | | { |
| | 0 | 508 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 0 | 509 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 0 | 510 | | tracingParameters.Add("appId", appId); |
| | 0 | 511 | | tracingParameters.Add("versionId", versionId); |
| | 0 | 512 | | tracingParameters.Add("skip", skip); |
| | 0 | 513 | | tracingParameters.Add("take", take); |
| | 0 | 514 | | tracingParameters.Add("enableNestedChildren", enableNestedChildren); |
| | 0 | 515 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 0 | 516 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | | 517 | | } |
| | | 518 | | // Construct URL |
| | 4 | 519 | | var _baseUrl = Client.BaseUri; |
| | 4 | 520 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/examples"; |
| | 4 | 521 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 4 | 522 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 4 | 523 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 4 | 524 | | List<string> _queryParameters = new List<string>(); |
| | 4 | 525 | | if (skip != null) |
| | | 526 | | { |
| | 4 | 527 | | _queryParameters.Add(string.Format("skip={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | | 528 | | } |
| | 4 | 529 | | if (take != null) |
| | | 530 | | { |
| | 4 | 531 | | _queryParameters.Add(string.Format("take={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCo |
| | | 532 | | } |
| | 4 | 533 | | if (enableNestedChildren != null) |
| | | 534 | | { |
| | 4 | 535 | | _queryParameters.Add(string.Format("enableNestedChildren={0}", System.Uri.EscapeDataString(Rest.Serializ |
| | | 536 | | } |
| | 4 | 537 | | if (_queryParameters.Count > 0) |
| | | 538 | | { |
| | 4 | 539 | | _url += "?" + string.Join("&", _queryParameters); |
| | | 540 | | } |
| | | 541 | | // Create HTTP transport objects |
| | 4 | 542 | | var _httpRequest = new HttpRequestMessage(); |
| | 4 | 543 | | HttpResponseMessage _httpResponse = null; |
| | 4 | 544 | | _httpRequest.Method = new HttpMethod("GET"); |
| | 4 | 545 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | | 546 | | // Set Headers |
| | | 547 | | |
| | | 548 | | |
| | 4 | 549 | | if (customHeaders != null) |
| | | 550 | | { |
| | 0 | 551 | | foreach(var _header in customHeaders) |
| | | 552 | | { |
| | 0 | 553 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | | 554 | | { |
| | 0 | 555 | | _httpRequest.Headers.Remove(_header.Key); |
| | | 556 | | } |
| | 0 | 557 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | | 558 | | } |
| | | 559 | | } |
| | | 560 | | |
| | | 561 | | // Serialize Request |
| | 4 | 562 | | string _requestContent = null; |
| | | 563 | | // Set Credentials |
| | 4 | 564 | | if (Client.Credentials != null) |
| | | 565 | | { |
| | 4 | 566 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 4 | 567 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | | 568 | | } |
| | | 569 | | // Send Request |
| | 4 | 570 | | if (_shouldTrace) |
| | | 571 | | { |
| | 0 | 572 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | | 573 | | } |
| | 4 | 574 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 4 | 575 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 4 | 576 | | if (_shouldTrace) |
| | | 577 | | { |
| | 0 | 578 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | | 579 | | } |
| | 4 | 580 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 4 | 581 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 4 | 582 | | string _responseContent = null; |
| | 4 | 583 | | if ((int)_statusCode != 200) |
| | | 584 | | { |
| | 0 | 585 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | | 586 | | try |
| | | 587 | | { |
| | 0 | 588 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 0 | 589 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| | 0 | 590 | | if (_errorBody != null) |
| | | 591 | | { |
| | 0 | 592 | | ex.Body = _errorBody; |
| | | 593 | | } |
| | 0 | 594 | | } |
| | 0 | 595 | | catch (JsonException) |
| | | 596 | | { |
| | | 597 | | // Ignore the exception |
| | 0 | 598 | | } |
| | 0 | 599 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 0 | 600 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 0 | 601 | | if (_shouldTrace) |
| | | 602 | | { |
| | 0 | 603 | | ServiceClientTracing.Error(_invocationId, ex); |
| | | 604 | | } |
| | 0 | 605 | | _httpRequest.Dispose(); |
| | 0 | 606 | | if (_httpResponse != null) |
| | | 607 | | { |
| | 0 | 608 | | _httpResponse.Dispose(); |
| | | 609 | | } |
| | 0 | 610 | | throw ex; |
| | | 611 | | } |
| | | 612 | | // Create Result |
| | 4 | 613 | | var _result = new HttpOperationResponse<IList<LabeledUtterance>>(); |
| | 4 | 614 | | _result.Request = _httpRequest; |
| | 4 | 615 | | _result.Response = _httpResponse; |
| | | 616 | | // Deserialize Response |
| | 4 | 617 | | if ((int)_statusCode == 200) |
| | | 618 | | { |
| | 4 | 619 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | | 620 | | try |
| | | 621 | | { |
| | 4 | 622 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<LabeledUtterance>>(_respon |
| | 4 | 623 | | } |
| | 0 | 624 | | catch (JsonException ex) |
| | | 625 | | { |
| | 0 | 626 | | _httpRequest.Dispose(); |
| | 0 | 627 | | if (_httpResponse != null) |
| | | 628 | | { |
| | 0 | 629 | | _httpResponse.Dispose(); |
| | | 630 | | } |
| | 0 | 631 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | | 632 | | } |
| | | 633 | | } |
| | 4 | 634 | | if (_shouldTrace) |
| | | 635 | | { |
| | 0 | 636 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | | 637 | | } |
| | 4 | 638 | | return _result; |
| | 4 | 639 | | } |
| | | 640 | | |
| | | 641 | | /// <summary> |
| | | 642 | | /// Deletes the labeled example utterances with the specified ID from a version |
| | | 643 | | /// of the application. |
| | | 644 | | /// </summary> |
| | | 645 | | /// <param name='appId'> |
| | | 646 | | /// The application ID. |
| | | 647 | | /// </param> |
| | | 648 | | /// <param name='versionId'> |
| | | 649 | | /// The version ID. |
| | | 650 | | /// </param> |
| | | 651 | | /// <param name='exampleId'> |
| | | 652 | | /// The example ID. |
| | | 653 | | /// </param> |
| | | 654 | | /// <param name='customHeaders'> |
| | | 655 | | /// Headers that will be added to request. |
| | | 656 | | /// </param> |
| | | 657 | | /// <param name='cancellationToken'> |
| | | 658 | | /// The cancellation token. |
| | | 659 | | /// </param> |
| | | 660 | | /// <exception cref="ErrorResponseException"> |
| | | 661 | | /// Thrown when the operation returned an invalid status code |
| | | 662 | | /// </exception> |
| | | 663 | | /// <exception cref="SerializationException"> |
| | | 664 | | /// Thrown when unable to deserialize the response |
| | | 665 | | /// </exception> |
| | | 666 | | /// <exception cref="ValidationException"> |
| | | 667 | | /// Thrown when a required parameter is null |
| | | 668 | | /// </exception> |
| | | 669 | | /// <exception cref="System.ArgumentNullException"> |
| | | 670 | | /// Thrown when a required parameter is null |
| | | 671 | | /// </exception> |
| | | 672 | | /// <return> |
| | | 673 | | /// A response object containing the response body and response headers. |
| | | 674 | | /// </return> |
| | | 675 | | public async Task<HttpOperationResponse<OperationStatus>> DeleteWithHttpMessagesAsync(System.Guid appId, string |
| | | 676 | | { |
| | 1 | 677 | | if (Client.Endpoint == null) |
| | | 678 | | { |
| | 0 | 679 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | | 680 | | } |
| | 1 | 681 | | if (versionId == null) |
| | | 682 | | { |
| | 0 | 683 | | throw new ValidationException(ValidationRules.CannotBeNull, "versionId"); |
| | | 684 | | } |
| | | 685 | | // Tracing |
| | 1 | 686 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 1 | 687 | | string _invocationId = null; |
| | 1 | 688 | | if (_shouldTrace) |
| | | 689 | | { |
| | 0 | 690 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 0 | 691 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 0 | 692 | | tracingParameters.Add("appId", appId); |
| | 0 | 693 | | tracingParameters.Add("versionId", versionId); |
| | 0 | 694 | | tracingParameters.Add("exampleId", exampleId); |
| | 0 | 695 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 0 | 696 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | | 697 | | } |
| | | 698 | | // Construct URL |
| | 1 | 699 | | var _baseUrl = Client.BaseUri; |
| | 1 | 700 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "apps/{appId}/versions/{versionId}/examples/{exa |
| | 1 | 701 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| | 1 | 702 | | _url = _url.Replace("{appId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeObjec |
| | 1 | 703 | | _url = _url.Replace("{versionId}", System.Uri.EscapeDataString(versionId)); |
| | 1 | 704 | | _url = _url.Replace("{exampleId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeO |
| | | 705 | | // Create HTTP transport objects |
| | 1 | 706 | | var _httpRequest = new HttpRequestMessage(); |
| | 1 | 707 | | HttpResponseMessage _httpResponse = null; |
| | 1 | 708 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| | 1 | 709 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | | 710 | | // Set Headers |
| | | 711 | | |
| | | 712 | | |
| | 1 | 713 | | if (customHeaders != null) |
| | | 714 | | { |
| | 0 | 715 | | foreach(var _header in customHeaders) |
| | | 716 | | { |
| | 0 | 717 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | | 718 | | { |
| | 0 | 719 | | _httpRequest.Headers.Remove(_header.Key); |
| | | 720 | | } |
| | 0 | 721 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | | 722 | | } |
| | | 723 | | } |
| | | 724 | | |
| | | 725 | | // Serialize Request |
| | 1 | 726 | | string _requestContent = null; |
| | | 727 | | // Set Credentials |
| | 1 | 728 | | if (Client.Credentials != null) |
| | | 729 | | { |
| | 1 | 730 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 1 | 731 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | | 732 | | } |
| | | 733 | | // Send Request |
| | 1 | 734 | | if (_shouldTrace) |
| | | 735 | | { |
| | 0 | 736 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | | 737 | | } |
| | 1 | 738 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 1 | 739 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1 | 740 | | if (_shouldTrace) |
| | | 741 | | { |
| | 0 | 742 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | | 743 | | } |
| | 1 | 744 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 1 | 745 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 1 | 746 | | string _responseContent = null; |
| | 1 | 747 | | if ((int)_statusCode != 200) |
| | | 748 | | { |
| | 0 | 749 | | var ex = new ErrorResponseException(string.Format("Operation returned an invalid status code '{0}'", _st |
| | | 750 | | try |
| | | 751 | | { |
| | 0 | 752 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 0 | 753 | | ErrorResponse _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<ErrorResponse>(_res |
| | 0 | 754 | | if (_errorBody != null) |
| | | 755 | | { |
| | 0 | 756 | | ex.Body = _errorBody; |
| | | 757 | | } |
| | 0 | 758 | | } |
| | 0 | 759 | | catch (JsonException) |
| | | 760 | | { |
| | | 761 | | // Ignore the exception |
| | 0 | 762 | | } |
| | 0 | 763 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 0 | 764 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 0 | 765 | | if (_shouldTrace) |
| | | 766 | | { |
| | 0 | 767 | | ServiceClientTracing.Error(_invocationId, ex); |
| | | 768 | | } |
| | 0 | 769 | | _httpRequest.Dispose(); |
| | 0 | 770 | | if (_httpResponse != null) |
| | | 771 | | { |
| | 0 | 772 | | _httpResponse.Dispose(); |
| | | 773 | | } |
| | 0 | 774 | | throw ex; |
| | | 775 | | } |
| | | 776 | | // Create Result |
| | 1 | 777 | | var _result = new HttpOperationResponse<OperationStatus>(); |
| | 1 | 778 | | _result.Request = _httpRequest; |
| | 1 | 779 | | _result.Response = _httpResponse; |
| | | 780 | | // Deserialize Response |
| | 1 | 781 | | if ((int)_statusCode == 200) |
| | | 782 | | { |
| | 1 | 783 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | | 784 | | try |
| | | 785 | | { |
| | 1 | 786 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<OperationStatus>(_responseConten |
| | 1 | 787 | | } |
| | 0 | 788 | | catch (JsonException ex) |
| | | 789 | | { |
| | 0 | 790 | | _httpRequest.Dispose(); |
| | 0 | 791 | | if (_httpResponse != null) |
| | | 792 | | { |
| | 0 | 793 | | _httpResponse.Dispose(); |
| | | 794 | | } |
| | 0 | 795 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | | 796 | | } |
| | | 797 | | } |
| | 1 | 798 | | if (_shouldTrace) |
| | | 799 | | { |
| | 0 | 800 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | | 801 | | } |
| | 1 | 802 | | return _result; |
| | 1 | 803 | | } |
| | | 804 | | |
| | | 805 | | } |
| | | 806 | | } |