| | 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.Vision.Face |
| | 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 | | /// LargePersonGroupOperations operations. |
| | 27 | | /// </summary> |
| | 28 | | public partial class LargePersonGroupOperations : IServiceOperations<FaceClient>, ILargePersonGroupOperations |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the LargePersonGroupOperations 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> |
| 34 | 39 | | public LargePersonGroupOperations(FaceClient client) |
| | 40 | | { |
| 34 | 41 | | if (client == null) |
| | 42 | | { |
| 0 | 43 | | throw new System.ArgumentNullException("client"); |
| | 44 | | } |
| 34 | 45 | | Client = client; |
| 34 | 46 | | } |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Gets a reference to the FaceClient |
| | 50 | | /// </summary> |
| 246 | 51 | | public FaceClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Create a new large person group with user-specified largePersonGroupId, |
| | 55 | | /// name, an optional userData and recognitionModel. |
| | 56 | | /// <br /> A large person group is the container of the uploaded person |
| | 57 | | /// data, including face recognition feature, and up to 1,000,000 |
| | 58 | | /// people. |
| | 59 | | /// <br /> After creation, use [LargePersonGroup Person - |
| | 60 | | /// Create](/docs/services/563879b61984550e40cbbe8d/operations/599adcba3a7b9412a4d53f40) |
| | 61 | | /// to add person into the group, and call [LargePersonGroup - |
| | 62 | | /// Train](/docs/services/563879b61984550e40cbbe8d/operations/599ae2d16ac60f11b48b5aa4) |
| | 63 | | /// to get this group ready for [Face - |
| | 64 | | /// Identify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395239). |
| | 65 | | /// <br /> No image will be stored. Only the person's extracted face |
| | 66 | | /// features and userData will be stored on server until [LargePersonGroup |
| | 67 | | /// Person - |
| | 68 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/599ade5c6ac60f11b48b5aa2) |
| | 69 | | /// or [LargePersonGroup - |
| | 70 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/599adc216ac60f11b48b5a9f) |
| | 71 | | /// is called. |
| | 72 | | /// <br/>'recognitionModel' should be specified to associate with this |
| | 73 | | /// large person group. The default value for 'recognitionModel' is |
| | 74 | | /// 'recognition_01', if the latest model needed, please explicitly specify the |
| | 75 | | /// model you need in this parameter. New faces that are added to an existing |
| | 76 | | /// large person group will use the recognition model that's already associated |
| | 77 | | /// with the collection. Existing face features in a large person group can't |
| | 78 | | /// be updated to features extracted by another version of recognition model. |
| | 79 | | /// * 'recognition_01': The default recognition model for [LargePersonGroup - |
| | 80 | | /// Create](/docs/services/563879b61984550e40cbbe8d/operations/599acdee6ac60f11b48b5a9d). |
| | 81 | | /// All those large person groups created before 2019 March are bonded with |
| | 82 | | /// this recognition model. |
| | 83 | | /// * 'recognition_02': Recognition model released in 2019 March. |
| | 84 | | /// 'recognition_02' is recommended since its overall accuracy is improved |
| | 85 | | /// compared with 'recognition_01'. |
| | 86 | | /// |
| | 87 | | /// Large person group quota: |
| | 88 | | /// * Free-tier subscription quota: 1,000 large person groups. |
| | 89 | | /// * S0-tier subscription quota: 1,000,000 large person groups. |
| | 90 | | /// </summary> |
| | 91 | | /// <param name='largePersonGroupId'> |
| | 92 | | /// Id referencing a particular large person group. |
| | 93 | | /// </param> |
| | 94 | | /// <param name='name'> |
| | 95 | | /// User defined name, maximum length is 128. |
| | 96 | | /// </param> |
| | 97 | | /// <param name='userData'> |
| | 98 | | /// User specified data. Length should not exceed 16KB. |
| | 99 | | /// </param> |
| | 100 | | /// <param name='recognitionModel'> |
| | 101 | | /// Possible values include: 'recognition_01', 'recognition_02' |
| | 102 | | /// </param> |
| | 103 | | /// <param name='customHeaders'> |
| | 104 | | /// Headers that will be added to request. |
| | 105 | | /// </param> |
| | 106 | | /// <param name='cancellationToken'> |
| | 107 | | /// The cancellation token. |
| | 108 | | /// </param> |
| | 109 | | /// <exception cref="APIErrorException"> |
| | 110 | | /// Thrown when the operation returned an invalid status code |
| | 111 | | /// </exception> |
| | 112 | | /// <exception cref="ValidationException"> |
| | 113 | | /// Thrown when a required parameter is null |
| | 114 | | /// </exception> |
| | 115 | | /// <exception cref="System.ArgumentNullException"> |
| | 116 | | /// Thrown when a required parameter is null |
| | 117 | | /// </exception> |
| | 118 | | /// <return> |
| | 119 | | /// A response object containing the response body and response headers. |
| | 120 | | /// </return> |
| | 121 | | public async Task<HttpOperationResponse> CreateWithHttpMessagesAsync(string largePersonGroupId, string name = de |
| | 122 | | { |
| 8 | 123 | | if (Client.Endpoint == null) |
| | 124 | | { |
| 0 | 125 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 126 | | } |
| 8 | 127 | | if (largePersonGroupId == null) |
| | 128 | | { |
| 0 | 129 | | throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId"); |
| | 130 | | } |
| 8 | 131 | | if (largePersonGroupId != null) |
| | 132 | | { |
| 8 | 133 | | if (largePersonGroupId.Length > 64) |
| | 134 | | { |
| 0 | 135 | | throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64); |
| | 136 | | } |
| 8 | 137 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$")) |
| | 138 | | { |
| 0 | 139 | | throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$"); |
| | 140 | | } |
| | 141 | | } |
| 8 | 142 | | if (name != null) |
| | 143 | | { |
| 8 | 144 | | if (name.Length > 128) |
| | 145 | | { |
| 0 | 146 | | throw new ValidationException(ValidationRules.MaxLength, "name", 128); |
| | 147 | | } |
| | 148 | | } |
| 8 | 149 | | if (userData != null) |
| | 150 | | { |
| 2 | 151 | | if (userData.Length > 16384) |
| | 152 | | { |
| 0 | 153 | | throw new ValidationException(ValidationRules.MaxLength, "userData", 16384); |
| | 154 | | } |
| | 155 | | } |
| 8 | 156 | | MetaDataContract body = new MetaDataContract(); |
| 8 | 157 | | if (name != null || userData != null || recognitionModel != null) |
| | 158 | | { |
| 8 | 159 | | body.Name = name; |
| 8 | 160 | | body.UserData = userData; |
| 8 | 161 | | body.RecognitionModel = recognitionModel; |
| | 162 | | } |
| | 163 | | // Tracing |
| 8 | 164 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 8 | 165 | | string _invocationId = null; |
| 8 | 166 | | if (_shouldTrace) |
| | 167 | | { |
| 0 | 168 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 169 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 170 | | tracingParameters.Add("largePersonGroupId", largePersonGroupId); |
| 0 | 171 | | tracingParameters.Add("body", body); |
| 0 | 172 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 173 | | ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters); |
| | 174 | | } |
| | 175 | | // Construct URL |
| 8 | 176 | | var _baseUrl = Client.BaseUri; |
| 8 | 177 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}"; |
| 8 | 178 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 8 | 179 | | _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId)); |
| | 180 | | // Create HTTP transport objects |
| 8 | 181 | | var _httpRequest = new HttpRequestMessage(); |
| 8 | 182 | | HttpResponseMessage _httpResponse = null; |
| 8 | 183 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 8 | 184 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 185 | | // Set Headers |
| | 186 | |
|
| | 187 | |
|
| 8 | 188 | | if (customHeaders != null) |
| | 189 | | { |
| 0 | 190 | | foreach(var _header in customHeaders) |
| | 191 | | { |
| 0 | 192 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 193 | | { |
| 0 | 194 | | _httpRequest.Headers.Remove(_header.Key); |
| | 195 | | } |
| 0 | 196 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 197 | | } |
| | 198 | | } |
| | 199 | |
|
| | 200 | | // Serialize Request |
| 8 | 201 | | string _requestContent = null; |
| 8 | 202 | | if(body != null) |
| | 203 | | { |
| 8 | 204 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings) |
| 8 | 205 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 8 | 206 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 207 | | } |
| | 208 | | // Set Credentials |
| 8 | 209 | | if (Client.Credentials != null) |
| | 210 | | { |
| 8 | 211 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 212 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 213 | | } |
| | 214 | | // Send Request |
| 8 | 215 | | if (_shouldTrace) |
| | 216 | | { |
| 0 | 217 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 218 | | } |
| 8 | 219 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 220 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 8 | 221 | | if (_shouldTrace) |
| | 222 | | { |
| 0 | 223 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 224 | | } |
| 8 | 225 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 8 | 226 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 227 | | string _responseContent = null; |
| 8 | 228 | | if ((int)_statusCode != 200) |
| | 229 | | { |
| 0 | 230 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 231 | | try |
| | 232 | | { |
| 0 | 233 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 234 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 235 | | if (_errorBody != null) |
| | 236 | | { |
| 0 | 237 | | ex.Body = _errorBody; |
| | 238 | | } |
| 0 | 239 | | } |
| 0 | 240 | | catch (JsonException) |
| | 241 | | { |
| | 242 | | // Ignore the exception |
| 0 | 243 | | } |
| 0 | 244 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 245 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 246 | | if (_shouldTrace) |
| | 247 | | { |
| 0 | 248 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 249 | | } |
| 0 | 250 | | _httpRequest.Dispose(); |
| 0 | 251 | | if (_httpResponse != null) |
| | 252 | | { |
| 0 | 253 | | _httpResponse.Dispose(); |
| | 254 | | } |
| 0 | 255 | | throw ex; |
| | 256 | | } |
| | 257 | | // Create Result |
| 8 | 258 | | var _result = new HttpOperationResponse(); |
| 8 | 259 | | _result.Request = _httpRequest; |
| 8 | 260 | | _result.Response = _httpResponse; |
| 8 | 261 | | if (_shouldTrace) |
| | 262 | | { |
| 0 | 263 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 264 | | } |
| 8 | 265 | | return _result; |
| 8 | 266 | | } |
| | 267 | |
|
| | 268 | | /// <summary> |
| | 269 | | /// Delete an existing large person group. Persisted face features of all |
| | 270 | | /// people in the large person group will also be deleted. |
| | 271 | | /// </summary> |
| | 272 | | /// <param name='largePersonGroupId'> |
| | 273 | | /// Id referencing a particular large person group. |
| | 274 | | /// </param> |
| | 275 | | /// <param name='customHeaders'> |
| | 276 | | /// Headers that will be added to request. |
| | 277 | | /// </param> |
| | 278 | | /// <param name='cancellationToken'> |
| | 279 | | /// The cancellation token. |
| | 280 | | /// </param> |
| | 281 | | /// <exception cref="APIErrorException"> |
| | 282 | | /// Thrown when the operation returned an invalid status code |
| | 283 | | /// </exception> |
| | 284 | | /// <exception cref="ValidationException"> |
| | 285 | | /// Thrown when a required parameter is null |
| | 286 | | /// </exception> |
| | 287 | | /// <exception cref="System.ArgumentNullException"> |
| | 288 | | /// Thrown when a required parameter is null |
| | 289 | | /// </exception> |
| | 290 | | /// <return> |
| | 291 | | /// A response object containing the response body and response headers. |
| | 292 | | /// </return> |
| | 293 | | public async Task<HttpOperationResponse> DeleteWithHttpMessagesAsync(string largePersonGroupId, Dictionary<strin |
| | 294 | | { |
| 10 | 295 | | if (Client.Endpoint == null) |
| | 296 | | { |
| 0 | 297 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 298 | | } |
| 10 | 299 | | if (largePersonGroupId == null) |
| | 300 | | { |
| 0 | 301 | | throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId"); |
| | 302 | | } |
| 10 | 303 | | if (largePersonGroupId != null) |
| | 304 | | { |
| 10 | 305 | | if (largePersonGroupId.Length > 64) |
| | 306 | | { |
| 0 | 307 | | throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64); |
| | 308 | | } |
| 10 | 309 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$")) |
| | 310 | | { |
| 0 | 311 | | throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$"); |
| | 312 | | } |
| | 313 | | } |
| | 314 | | // Tracing |
| 10 | 315 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 10 | 316 | | string _invocationId = null; |
| 10 | 317 | | if (_shouldTrace) |
| | 318 | | { |
| 0 | 319 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 320 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 321 | | tracingParameters.Add("largePersonGroupId", largePersonGroupId); |
| 0 | 322 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 323 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 324 | | } |
| | 325 | | // Construct URL |
| 10 | 326 | | var _baseUrl = Client.BaseUri; |
| 10 | 327 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}"; |
| 10 | 328 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 10 | 329 | | _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId)); |
| | 330 | | // Create HTTP transport objects |
| 10 | 331 | | var _httpRequest = new HttpRequestMessage(); |
| 10 | 332 | | HttpResponseMessage _httpResponse = null; |
| 10 | 333 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 10 | 334 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 335 | | // Set Headers |
| | 336 | |
|
| | 337 | |
|
| 10 | 338 | | if (customHeaders != null) |
| | 339 | | { |
| 0 | 340 | | foreach(var _header in customHeaders) |
| | 341 | | { |
| 0 | 342 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 343 | | { |
| 0 | 344 | | _httpRequest.Headers.Remove(_header.Key); |
| | 345 | | } |
| 0 | 346 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 347 | | } |
| | 348 | | } |
| | 349 | |
|
| | 350 | | // Serialize Request |
| 10 | 351 | | string _requestContent = null; |
| | 352 | | // Set Credentials |
| 10 | 353 | | if (Client.Credentials != null) |
| | 354 | | { |
| 10 | 355 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 356 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 357 | | } |
| | 358 | | // Send Request |
| 10 | 359 | | if (_shouldTrace) |
| | 360 | | { |
| 0 | 361 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 362 | | } |
| 10 | 363 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 364 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 10 | 365 | | if (_shouldTrace) |
| | 366 | | { |
| 0 | 367 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 368 | | } |
| 10 | 369 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 10 | 370 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 371 | | string _responseContent = null; |
| 10 | 372 | | if ((int)_statusCode != 200) |
| | 373 | | { |
| 0 | 374 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 375 | | try |
| | 376 | | { |
| 0 | 377 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 378 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 379 | | if (_errorBody != null) |
| | 380 | | { |
| 0 | 381 | | ex.Body = _errorBody; |
| | 382 | | } |
| 0 | 383 | | } |
| 0 | 384 | | catch (JsonException) |
| | 385 | | { |
| | 386 | | // Ignore the exception |
| 0 | 387 | | } |
| 0 | 388 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 389 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 390 | | if (_shouldTrace) |
| | 391 | | { |
| 0 | 392 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 393 | | } |
| 0 | 394 | | _httpRequest.Dispose(); |
| 0 | 395 | | if (_httpResponse != null) |
| | 396 | | { |
| 0 | 397 | | _httpResponse.Dispose(); |
| | 398 | | } |
| 0 | 399 | | throw ex; |
| | 400 | | } |
| | 401 | | // Create Result |
| 10 | 402 | | var _result = new HttpOperationResponse(); |
| 10 | 403 | | _result.Request = _httpRequest; |
| 10 | 404 | | _result.Response = _httpResponse; |
| 10 | 405 | | if (_shouldTrace) |
| | 406 | | { |
| 0 | 407 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 408 | | } |
| 10 | 409 | | return _result; |
| 10 | 410 | | } |
| | 411 | |
|
| | 412 | | /// <summary> |
| | 413 | | /// Retrieve the information of a large person group, including its name, |
| | 414 | | /// userData and recognitionModel. This API returns large person group |
| | 415 | | /// information only, use [LargePersonGroup Person - |
| | 416 | | /// List](/docs/services/563879b61984550e40cbbe8d/operations/599adda06ac60f11b48b5aa1) |
| | 417 | | /// instead to retrieve person information under the large person group. |
| | 418 | | /// |
| | 419 | | /// </summary> |
| | 420 | | /// <param name='largePersonGroupId'> |
| | 421 | | /// Id referencing a particular large person group. |
| | 422 | | /// </param> |
| | 423 | | /// <param name='returnRecognitionModel'> |
| | 424 | | /// A value indicating whether the operation should return 'recognitionModel' |
| | 425 | | /// in response. |
| | 426 | | /// </param> |
| | 427 | | /// <param name='customHeaders'> |
| | 428 | | /// Headers that will be added to request. |
| | 429 | | /// </param> |
| | 430 | | /// <param name='cancellationToken'> |
| | 431 | | /// The cancellation token. |
| | 432 | | /// </param> |
| | 433 | | /// <exception cref="APIErrorException"> |
| | 434 | | /// Thrown when the operation returned an invalid status code |
| | 435 | | /// </exception> |
| | 436 | | /// <exception cref="SerializationException"> |
| | 437 | | /// Thrown when unable to deserialize the response |
| | 438 | | /// </exception> |
| | 439 | | /// <exception cref="ValidationException"> |
| | 440 | | /// Thrown when a required parameter is null |
| | 441 | | /// </exception> |
| | 442 | | /// <exception cref="System.ArgumentNullException"> |
| | 443 | | /// Thrown when a required parameter is null |
| | 444 | | /// </exception> |
| | 445 | | /// <return> |
| | 446 | | /// A response object containing the response body and response headers. |
| | 447 | | /// </return> |
| | 448 | | public async Task<HttpOperationResponse<LargePersonGroup>> GetWithHttpMessagesAsync(string largePersonGroupId, b |
| | 449 | | { |
| 2 | 450 | | if (Client.Endpoint == null) |
| | 451 | | { |
| 0 | 452 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 453 | | } |
| 2 | 454 | | if (largePersonGroupId == null) |
| | 455 | | { |
| 0 | 456 | | throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId"); |
| | 457 | | } |
| 2 | 458 | | if (largePersonGroupId != null) |
| | 459 | | { |
| 2 | 460 | | if (largePersonGroupId.Length > 64) |
| | 461 | | { |
| 0 | 462 | | throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64); |
| | 463 | | } |
| 2 | 464 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$")) |
| | 465 | | { |
| 0 | 466 | | throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$"); |
| | 467 | | } |
| | 468 | | } |
| | 469 | | // Tracing |
| 2 | 470 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 471 | | string _invocationId = null; |
| 2 | 472 | | if (_shouldTrace) |
| | 473 | | { |
| 0 | 474 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 475 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 476 | | tracingParameters.Add("largePersonGroupId", largePersonGroupId); |
| 0 | 477 | | tracingParameters.Add("returnRecognitionModel", returnRecognitionModel); |
| 0 | 478 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 479 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 480 | | } |
| | 481 | | // Construct URL |
| 2 | 482 | | var _baseUrl = Client.BaseUri; |
| 2 | 483 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}"; |
| 2 | 484 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 2 | 485 | | _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId)); |
| 2 | 486 | | List<string> _queryParameters = new List<string>(); |
| 2 | 487 | | if (returnRecognitionModel != null) |
| | 488 | | { |
| 2 | 489 | | _queryParameters.Add(string.Format("returnRecognitionModel={0}", System.Uri.EscapeDataString(Rest.Serial |
| | 490 | | } |
| 2 | 491 | | if (_queryParameters.Count > 0) |
| | 492 | | { |
| 2 | 493 | | _url += "?" + string.Join("&", _queryParameters); |
| | 494 | | } |
| | 495 | | // Create HTTP transport objects |
| 2 | 496 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 497 | | HttpResponseMessage _httpResponse = null; |
| 2 | 498 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 499 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 500 | | // Set Headers |
| | 501 | |
|
| | 502 | |
|
| 2 | 503 | | if (customHeaders != null) |
| | 504 | | { |
| 0 | 505 | | foreach(var _header in customHeaders) |
| | 506 | | { |
| 0 | 507 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 508 | | { |
| 0 | 509 | | _httpRequest.Headers.Remove(_header.Key); |
| | 510 | | } |
| 0 | 511 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 512 | | } |
| | 513 | | } |
| | 514 | |
|
| | 515 | | // Serialize Request |
| 2 | 516 | | string _requestContent = null; |
| | 517 | | // Set Credentials |
| 2 | 518 | | if (Client.Credentials != null) |
| | 519 | | { |
| 2 | 520 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 521 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 522 | | } |
| | 523 | | // Send Request |
| 2 | 524 | | if (_shouldTrace) |
| | 525 | | { |
| 0 | 526 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 527 | | } |
| 2 | 528 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 529 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 530 | | if (_shouldTrace) |
| | 531 | | { |
| 0 | 532 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 533 | | } |
| 2 | 534 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 535 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 536 | | string _responseContent = null; |
| 2 | 537 | | if ((int)_statusCode != 200) |
| | 538 | | { |
| 0 | 539 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 540 | | try |
| | 541 | | { |
| 0 | 542 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 543 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 544 | | if (_errorBody != null) |
| | 545 | | { |
| 0 | 546 | | ex.Body = _errorBody; |
| | 547 | | } |
| 0 | 548 | | } |
| 0 | 549 | | catch (JsonException) |
| | 550 | | { |
| | 551 | | // Ignore the exception |
| 0 | 552 | | } |
| 0 | 553 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 554 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 555 | | if (_shouldTrace) |
| | 556 | | { |
| 0 | 557 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 558 | | } |
| 0 | 559 | | _httpRequest.Dispose(); |
| 0 | 560 | | if (_httpResponse != null) |
| | 561 | | { |
| 0 | 562 | | _httpResponse.Dispose(); |
| | 563 | | } |
| 0 | 564 | | throw ex; |
| | 565 | | } |
| | 566 | | // Create Result |
| 2 | 567 | | var _result = new HttpOperationResponse<LargePersonGroup>(); |
| 2 | 568 | | _result.Request = _httpRequest; |
| 2 | 569 | | _result.Response = _httpResponse; |
| | 570 | | // Deserialize Response |
| 2 | 571 | | if ((int)_statusCode == 200) |
| | 572 | | { |
| 2 | 573 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 574 | | try |
| | 575 | | { |
| 2 | 576 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<LargePersonGroup>(_responseConte |
| 2 | 577 | | } |
| 0 | 578 | | catch (JsonException ex) |
| | 579 | | { |
| 0 | 580 | | _httpRequest.Dispose(); |
| 0 | 581 | | if (_httpResponse != null) |
| | 582 | | { |
| 0 | 583 | | _httpResponse.Dispose(); |
| | 584 | | } |
| 0 | 585 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 586 | | } |
| | 587 | | } |
| 2 | 588 | | if (_shouldTrace) |
| | 589 | | { |
| 0 | 590 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 591 | | } |
| 2 | 592 | | return _result; |
| 2 | 593 | | } |
| | 594 | |
|
| | 595 | | /// <summary> |
| | 596 | | /// Update an existing large person group's display name and userData. The |
| | 597 | | /// properties which does not appear in request body will not be updated. |
| | 598 | | /// </summary> |
| | 599 | | /// <param name='largePersonGroupId'> |
| | 600 | | /// Id referencing a particular large person group. |
| | 601 | | /// </param> |
| | 602 | | /// <param name='name'> |
| | 603 | | /// User defined name, maximum length is 128. |
| | 604 | | /// </param> |
| | 605 | | /// <param name='userData'> |
| | 606 | | /// User specified data. Length should not exceed 16KB. |
| | 607 | | /// </param> |
| | 608 | | /// <param name='customHeaders'> |
| | 609 | | /// Headers that will be added to request. |
| | 610 | | /// </param> |
| | 611 | | /// <param name='cancellationToken'> |
| | 612 | | /// The cancellation token. |
| | 613 | | /// </param> |
| | 614 | | /// <exception cref="APIErrorException"> |
| | 615 | | /// Thrown when the operation returned an invalid status code |
| | 616 | | /// </exception> |
| | 617 | | /// <exception cref="ValidationException"> |
| | 618 | | /// Thrown when a required parameter is null |
| | 619 | | /// </exception> |
| | 620 | | /// <exception cref="System.ArgumentNullException"> |
| | 621 | | /// Thrown when a required parameter is null |
| | 622 | | /// </exception> |
| | 623 | | /// <return> |
| | 624 | | /// A response object containing the response body and response headers. |
| | 625 | | /// </return> |
| | 626 | | public async Task<HttpOperationResponse> UpdateWithHttpMessagesAsync(string largePersonGroupId, string name = de |
| | 627 | | { |
| 0 | 628 | | if (Client.Endpoint == null) |
| | 629 | | { |
| 0 | 630 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 631 | | } |
| 0 | 632 | | if (largePersonGroupId == null) |
| | 633 | | { |
| 0 | 634 | | throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId"); |
| | 635 | | } |
| 0 | 636 | | if (largePersonGroupId != null) |
| | 637 | | { |
| 0 | 638 | | if (largePersonGroupId.Length > 64) |
| | 639 | | { |
| 0 | 640 | | throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64); |
| | 641 | | } |
| 0 | 642 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$")) |
| | 643 | | { |
| 0 | 644 | | throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$"); |
| | 645 | | } |
| | 646 | | } |
| 0 | 647 | | if (name != null) |
| | 648 | | { |
| 0 | 649 | | if (name.Length > 128) |
| | 650 | | { |
| 0 | 651 | | throw new ValidationException(ValidationRules.MaxLength, "name", 128); |
| | 652 | | } |
| | 653 | | } |
| 0 | 654 | | if (userData != null) |
| | 655 | | { |
| 0 | 656 | | if (userData.Length > 16384) |
| | 657 | | { |
| 0 | 658 | | throw new ValidationException(ValidationRules.MaxLength, "userData", 16384); |
| | 659 | | } |
| | 660 | | } |
| 0 | 661 | | NameAndUserDataContract body = new NameAndUserDataContract(); |
| 0 | 662 | | if (name != null || userData != null) |
| | 663 | | { |
| 0 | 664 | | body.Name = name; |
| 0 | 665 | | body.UserData = userData; |
| | 666 | | } |
| | 667 | | // Tracing |
| 0 | 668 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 669 | | string _invocationId = null; |
| 0 | 670 | | if (_shouldTrace) |
| | 671 | | { |
| 0 | 672 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 673 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 674 | | tracingParameters.Add("largePersonGroupId", largePersonGroupId); |
| 0 | 675 | | tracingParameters.Add("body", body); |
| 0 | 676 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 677 | | ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters); |
| | 678 | | } |
| | 679 | | // Construct URL |
| 0 | 680 | | var _baseUrl = Client.BaseUri; |
| 0 | 681 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}"; |
| 0 | 682 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 683 | | _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId)); |
| | 684 | | // Create HTTP transport objects |
| 0 | 685 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 686 | | HttpResponseMessage _httpResponse = null; |
| 0 | 687 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 0 | 688 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 689 | | // Set Headers |
| | 690 | |
|
| | 691 | |
|
| 0 | 692 | | if (customHeaders != null) |
| | 693 | | { |
| 0 | 694 | | foreach(var _header in customHeaders) |
| | 695 | | { |
| 0 | 696 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 697 | | { |
| 0 | 698 | | _httpRequest.Headers.Remove(_header.Key); |
| | 699 | | } |
| 0 | 700 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 701 | | } |
| | 702 | | } |
| | 703 | |
|
| | 704 | | // Serialize Request |
| 0 | 705 | | string _requestContent = null; |
| 0 | 706 | | if(body != null) |
| | 707 | | { |
| 0 | 708 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings) |
| 0 | 709 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 710 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 711 | | } |
| | 712 | | // Set Credentials |
| 0 | 713 | | if (Client.Credentials != null) |
| | 714 | | { |
| 0 | 715 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 716 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 717 | | } |
| | 718 | | // Send Request |
| 0 | 719 | | if (_shouldTrace) |
| | 720 | | { |
| 0 | 721 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 722 | | } |
| 0 | 723 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 724 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 725 | | if (_shouldTrace) |
| | 726 | | { |
| 0 | 727 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 728 | | } |
| 0 | 729 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 730 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 731 | | string _responseContent = null; |
| 0 | 732 | | if ((int)_statusCode != 200) |
| | 733 | | { |
| 0 | 734 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 735 | | try |
| | 736 | | { |
| 0 | 737 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 738 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 739 | | if (_errorBody != null) |
| | 740 | | { |
| 0 | 741 | | ex.Body = _errorBody; |
| | 742 | | } |
| 0 | 743 | | } |
| 0 | 744 | | catch (JsonException) |
| | 745 | | { |
| | 746 | | // Ignore the exception |
| 0 | 747 | | } |
| 0 | 748 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 749 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 750 | | if (_shouldTrace) |
| | 751 | | { |
| 0 | 752 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 753 | | } |
| 0 | 754 | | _httpRequest.Dispose(); |
| 0 | 755 | | if (_httpResponse != null) |
| | 756 | | { |
| 0 | 757 | | _httpResponse.Dispose(); |
| | 758 | | } |
| 0 | 759 | | throw ex; |
| | 760 | | } |
| | 761 | | // Create Result |
| 0 | 762 | | var _result = new HttpOperationResponse(); |
| 0 | 763 | | _result.Request = _httpRequest; |
| 0 | 764 | | _result.Response = _httpResponse; |
| 0 | 765 | | if (_shouldTrace) |
| | 766 | | { |
| 0 | 767 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 768 | | } |
| 0 | 769 | | return _result; |
| 0 | 770 | | } |
| | 771 | |
|
| | 772 | | /// <summary> |
| | 773 | | /// Retrieve the training status of a large person group (completed or |
| | 774 | | /// ongoing). |
| | 775 | | /// </summary> |
| | 776 | | /// <param name='largePersonGroupId'> |
| | 777 | | /// Id referencing a particular large person group. |
| | 778 | | /// </param> |
| | 779 | | /// <param name='customHeaders'> |
| | 780 | | /// Headers that will be added to request. |
| | 781 | | /// </param> |
| | 782 | | /// <param name='cancellationToken'> |
| | 783 | | /// The cancellation token. |
| | 784 | | /// </param> |
| | 785 | | /// <exception cref="APIErrorException"> |
| | 786 | | /// Thrown when the operation returned an invalid status code |
| | 787 | | /// </exception> |
| | 788 | | /// <exception cref="SerializationException"> |
| | 789 | | /// Thrown when unable to deserialize the response |
| | 790 | | /// </exception> |
| | 791 | | /// <exception cref="ValidationException"> |
| | 792 | | /// Thrown when a required parameter is null |
| | 793 | | /// </exception> |
| | 794 | | /// <exception cref="System.ArgumentNullException"> |
| | 795 | | /// Thrown when a required parameter is null |
| | 796 | | /// </exception> |
| | 797 | | /// <return> |
| | 798 | | /// A response object containing the response body and response headers. |
| | 799 | | /// </return> |
| | 800 | | public async Task<HttpOperationResponse<TrainingStatus>> GetTrainingStatusWithHttpMessagesAsync(string largePers |
| | 801 | | { |
| 8 | 802 | | if (Client.Endpoint == null) |
| | 803 | | { |
| 0 | 804 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 805 | | } |
| 8 | 806 | | if (largePersonGroupId == null) |
| | 807 | | { |
| 0 | 808 | | throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId"); |
| | 809 | | } |
| 8 | 810 | | if (largePersonGroupId != null) |
| | 811 | | { |
| 8 | 812 | | if (largePersonGroupId.Length > 64) |
| | 813 | | { |
| 0 | 814 | | throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64); |
| | 815 | | } |
| 8 | 816 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$")) |
| | 817 | | { |
| 0 | 818 | | throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$"); |
| | 819 | | } |
| | 820 | | } |
| | 821 | | // Tracing |
| 8 | 822 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 8 | 823 | | string _invocationId = null; |
| 8 | 824 | | if (_shouldTrace) |
| | 825 | | { |
| 0 | 826 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 827 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 828 | | tracingParameters.Add("largePersonGroupId", largePersonGroupId); |
| 0 | 829 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 830 | | ServiceClientTracing.Enter(_invocationId, this, "GetTrainingStatus", tracingParameters); |
| | 831 | | } |
| | 832 | | // Construct URL |
| 8 | 833 | | var _baseUrl = Client.BaseUri; |
| 8 | 834 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}/training |
| 8 | 835 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 8 | 836 | | _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId)); |
| | 837 | | // Create HTTP transport objects |
| 8 | 838 | | var _httpRequest = new HttpRequestMessage(); |
| 8 | 839 | | HttpResponseMessage _httpResponse = null; |
| 8 | 840 | | _httpRequest.Method = new HttpMethod("GET"); |
| 8 | 841 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 842 | | // Set Headers |
| | 843 | |
|
| | 844 | |
|
| 8 | 845 | | if (customHeaders != null) |
| | 846 | | { |
| 0 | 847 | | foreach(var _header in customHeaders) |
| | 848 | | { |
| 0 | 849 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 850 | | { |
| 0 | 851 | | _httpRequest.Headers.Remove(_header.Key); |
| | 852 | | } |
| 0 | 853 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 854 | | } |
| | 855 | | } |
| | 856 | |
|
| | 857 | | // Serialize Request |
| 8 | 858 | | string _requestContent = null; |
| | 859 | | // Set Credentials |
| 8 | 860 | | if (Client.Credentials != null) |
| | 861 | | { |
| 8 | 862 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 863 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 864 | | } |
| | 865 | | // Send Request |
| 8 | 866 | | if (_shouldTrace) |
| | 867 | | { |
| 0 | 868 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 869 | | } |
| 8 | 870 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 871 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 8 | 872 | | if (_shouldTrace) |
| | 873 | | { |
| 0 | 874 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 875 | | } |
| 8 | 876 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 8 | 877 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 878 | | string _responseContent = null; |
| 8 | 879 | | if ((int)_statusCode != 200) |
| | 880 | | { |
| 0 | 881 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 882 | | try |
| | 883 | | { |
| 0 | 884 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 885 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 886 | | if (_errorBody != null) |
| | 887 | | { |
| 0 | 888 | | ex.Body = _errorBody; |
| | 889 | | } |
| 0 | 890 | | } |
| 0 | 891 | | catch (JsonException) |
| | 892 | | { |
| | 893 | | // Ignore the exception |
| 0 | 894 | | } |
| 0 | 895 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 896 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 897 | | if (_shouldTrace) |
| | 898 | | { |
| 0 | 899 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 900 | | } |
| 0 | 901 | | _httpRequest.Dispose(); |
| 0 | 902 | | if (_httpResponse != null) |
| | 903 | | { |
| 0 | 904 | | _httpResponse.Dispose(); |
| | 905 | | } |
| 0 | 906 | | throw ex; |
| | 907 | | } |
| | 908 | | // Create Result |
| 8 | 909 | | var _result = new HttpOperationResponse<TrainingStatus>(); |
| 8 | 910 | | _result.Request = _httpRequest; |
| 8 | 911 | | _result.Response = _httpResponse; |
| | 912 | | // Deserialize Response |
| 8 | 913 | | if ((int)_statusCode == 200) |
| | 914 | | { |
| 8 | 915 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 916 | | try |
| | 917 | | { |
| 8 | 918 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<TrainingStatus>(_responseContent |
| 8 | 919 | | } |
| 0 | 920 | | catch (JsonException ex) |
| | 921 | | { |
| 0 | 922 | | _httpRequest.Dispose(); |
| 0 | 923 | | if (_httpResponse != null) |
| | 924 | | { |
| 0 | 925 | | _httpResponse.Dispose(); |
| | 926 | | } |
| 0 | 927 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 928 | | } |
| | 929 | | } |
| 8 | 930 | | if (_shouldTrace) |
| | 931 | | { |
| 0 | 932 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 933 | | } |
| 8 | 934 | | return _result; |
| 8 | 935 | | } |
| | 936 | |
|
| | 937 | | /// <summary> |
| | 938 | | /// List all existing large person groups’ largePersonGroupId, name, userData |
| | 939 | | /// and recognitionModel.<br /> |
| | 940 | | /// * Large person groups are stored in alphabetical order of |
| | 941 | | /// largePersonGroupId. |
| | 942 | | /// * "start" parameter (string, optional) is a user-provided |
| | 943 | | /// largePersonGroupId value that returned entries have larger ids by string |
| | 944 | | /// comparison. "start" set to empty to indicate return from the first item. |
| | 945 | | /// * "top" parameter (int, optional) specifies the number of entries to |
| | 946 | | /// return. A maximal of 1000 entries can be returned in one call. To fetch |
| | 947 | | /// more, you can specify "start" with the last returned entry’s Id of the |
| | 948 | | /// current call. |
| | 949 | | /// <br /> |
| | 950 | | /// For example, total 5 large person groups: "group1", ..., "group5". |
| | 951 | | /// <br /> "start=&top=" will return all 5 groups. |
| | 952 | | /// <br /> "start=&top=2" will return "group1", "group2". |
| | 953 | | /// <br /> "start=group2&top=3" will return "group3", "group4", |
| | 954 | | /// "group5". |
| | 955 | | /// |
| | 956 | | /// </summary> |
| | 957 | | /// <param name='start'> |
| | 958 | | /// List large person groups from the least largePersonGroupId greater than the |
| | 959 | | /// "start". |
| | 960 | | /// </param> |
| | 961 | | /// <param name='top'> |
| | 962 | | /// The number of large person groups to list. |
| | 963 | | /// </param> |
| | 964 | | /// <param name='returnRecognitionModel'> |
| | 965 | | /// A value indicating whether the operation should return 'recognitionModel' |
| | 966 | | /// in response. |
| | 967 | | /// </param> |
| | 968 | | /// <param name='customHeaders'> |
| | 969 | | /// Headers that will be added to request. |
| | 970 | | /// </param> |
| | 971 | | /// <param name='cancellationToken'> |
| | 972 | | /// The cancellation token. |
| | 973 | | /// </param> |
| | 974 | | /// <exception cref="APIErrorException"> |
| | 975 | | /// Thrown when the operation returned an invalid status code |
| | 976 | | /// </exception> |
| | 977 | | /// <exception cref="SerializationException"> |
| | 978 | | /// Thrown when unable to deserialize the response |
| | 979 | | /// </exception> |
| | 980 | | /// <exception cref="ValidationException"> |
| | 981 | | /// Thrown when a required parameter is null |
| | 982 | | /// </exception> |
| | 983 | | /// <exception cref="System.ArgumentNullException"> |
| | 984 | | /// Thrown when a required parameter is null |
| | 985 | | /// </exception> |
| | 986 | | /// <return> |
| | 987 | | /// A response object containing the response body and response headers. |
| | 988 | | /// </return> |
| | 989 | | public async Task<HttpOperationResponse<IList<LargePersonGroup>>> ListWithHttpMessagesAsync(string start = defau |
| | 990 | | { |
| 0 | 991 | | if (Client.Endpoint == null) |
| | 992 | | { |
| 0 | 993 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 994 | | } |
| 0 | 995 | | if (start != null) |
| | 996 | | { |
| 0 | 997 | | if (start.Length > 64) |
| | 998 | | { |
| 0 | 999 | | throw new ValidationException(ValidationRules.MaxLength, "start", 64); |
| | 1000 | | } |
| | 1001 | | } |
| 0 | 1002 | | if (top > 1000) |
| | 1003 | | { |
| 0 | 1004 | | throw new ValidationException(ValidationRules.InclusiveMaximum, "top", 1000); |
| | 1005 | | } |
| 0 | 1006 | | if (top < 1) |
| | 1007 | | { |
| 0 | 1008 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "top", 1); |
| | 1009 | | } |
| | 1010 | | // Tracing |
| 0 | 1011 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1012 | | string _invocationId = null; |
| 0 | 1013 | | if (_shouldTrace) |
| | 1014 | | { |
| 0 | 1015 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1016 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1017 | | tracingParameters.Add("start", start); |
| 0 | 1018 | | tracingParameters.Add("top", top); |
| 0 | 1019 | | tracingParameters.Add("returnRecognitionModel", returnRecognitionModel); |
| 0 | 1020 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1021 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | 1022 | | } |
| | 1023 | | // Construct URL |
| 0 | 1024 | | var _baseUrl = Client.BaseUri; |
| 0 | 1025 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups"; |
| 0 | 1026 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1027 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1028 | | if (start != null) |
| | 1029 | | { |
| 0 | 1030 | | _queryParameters.Add(string.Format("start={0}", System.Uri.EscapeDataString(start))); |
| | 1031 | | } |
| 0 | 1032 | | if (top != null) |
| | 1033 | | { |
| 0 | 1034 | | _queryParameters.Add(string.Format("top={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCon |
| | 1035 | | } |
| 0 | 1036 | | if (returnRecognitionModel != null) |
| | 1037 | | { |
| 0 | 1038 | | _queryParameters.Add(string.Format("returnRecognitionModel={0}", System.Uri.EscapeDataString(Rest.Serial |
| | 1039 | | } |
| 0 | 1040 | | if (_queryParameters.Count > 0) |
| | 1041 | | { |
| 0 | 1042 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1043 | | } |
| | 1044 | | // Create HTTP transport objects |
| 0 | 1045 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1046 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1047 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 1048 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1049 | | // Set Headers |
| | 1050 | |
|
| | 1051 | |
|
| 0 | 1052 | | if (customHeaders != null) |
| | 1053 | | { |
| 0 | 1054 | | foreach(var _header in customHeaders) |
| | 1055 | | { |
| 0 | 1056 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1057 | | { |
| 0 | 1058 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1059 | | } |
| 0 | 1060 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1061 | | } |
| | 1062 | | } |
| | 1063 | |
|
| | 1064 | | // Serialize Request |
| 0 | 1065 | | string _requestContent = null; |
| | 1066 | | // Set Credentials |
| 0 | 1067 | | if (Client.Credentials != null) |
| | 1068 | | { |
| 0 | 1069 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1070 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1071 | | } |
| | 1072 | | // Send Request |
| 0 | 1073 | | if (_shouldTrace) |
| | 1074 | | { |
| 0 | 1075 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1076 | | } |
| 0 | 1077 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1078 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1079 | | if (_shouldTrace) |
| | 1080 | | { |
| 0 | 1081 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1082 | | } |
| 0 | 1083 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1084 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1085 | | string _responseContent = null; |
| 0 | 1086 | | if ((int)_statusCode != 200) |
| | 1087 | | { |
| 0 | 1088 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1089 | | try |
| | 1090 | | { |
| 0 | 1091 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1092 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1093 | | if (_errorBody != null) |
| | 1094 | | { |
| 0 | 1095 | | ex.Body = _errorBody; |
| | 1096 | | } |
| 0 | 1097 | | } |
| 0 | 1098 | | catch (JsonException) |
| | 1099 | | { |
| | 1100 | | // Ignore the exception |
| 0 | 1101 | | } |
| 0 | 1102 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1103 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1104 | | if (_shouldTrace) |
| | 1105 | | { |
| 0 | 1106 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1107 | | } |
| 0 | 1108 | | _httpRequest.Dispose(); |
| 0 | 1109 | | if (_httpResponse != null) |
| | 1110 | | { |
| 0 | 1111 | | _httpResponse.Dispose(); |
| | 1112 | | } |
| 0 | 1113 | | throw ex; |
| | 1114 | | } |
| | 1115 | | // Create Result |
| 0 | 1116 | | var _result = new HttpOperationResponse<IList<LargePersonGroup>>(); |
| 0 | 1117 | | _result.Request = _httpRequest; |
| 0 | 1118 | | _result.Response = _httpResponse; |
| | 1119 | | // Deserialize Response |
| 0 | 1120 | | if ((int)_statusCode == 200) |
| | 1121 | | { |
| 0 | 1122 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1123 | | try |
| | 1124 | | { |
| 0 | 1125 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<LargePersonGroup>>(_respon |
| 0 | 1126 | | } |
| 0 | 1127 | | catch (JsonException ex) |
| | 1128 | | { |
| 0 | 1129 | | _httpRequest.Dispose(); |
| 0 | 1130 | | if (_httpResponse != null) |
| | 1131 | | { |
| 0 | 1132 | | _httpResponse.Dispose(); |
| | 1133 | | } |
| 0 | 1134 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1135 | | } |
| | 1136 | | } |
| 0 | 1137 | | if (_shouldTrace) |
| | 1138 | | { |
| 0 | 1139 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1140 | | } |
| 0 | 1141 | | return _result; |
| 0 | 1142 | | } |
| | 1143 | |
|
| | 1144 | | /// <summary> |
| | 1145 | | /// Queue a large person group training task, the training task may not be |
| | 1146 | | /// started immediately. |
| | 1147 | | /// </summary> |
| | 1148 | | /// <param name='largePersonGroupId'> |
| | 1149 | | /// Id referencing a particular large person group. |
| | 1150 | | /// </param> |
| | 1151 | | /// <param name='customHeaders'> |
| | 1152 | | /// Headers that will be added to request. |
| | 1153 | | /// </param> |
| | 1154 | | /// <param name='cancellationToken'> |
| | 1155 | | /// The cancellation token. |
| | 1156 | | /// </param> |
| | 1157 | | /// <exception cref="APIErrorException"> |
| | 1158 | | /// Thrown when the operation returned an invalid status code |
| | 1159 | | /// </exception> |
| | 1160 | | /// <exception cref="ValidationException"> |
| | 1161 | | /// Thrown when a required parameter is null |
| | 1162 | | /// </exception> |
| | 1163 | | /// <exception cref="System.ArgumentNullException"> |
| | 1164 | | /// Thrown when a required parameter is null |
| | 1165 | | /// </exception> |
| | 1166 | | /// <return> |
| | 1167 | | /// A response object containing the response body and response headers. |
| | 1168 | | /// </return> |
| | 1169 | | public async Task<HttpOperationResponse> TrainWithHttpMessagesAsync(string largePersonGroupId, Dictionary<string |
| | 1170 | | { |
| 4 | 1171 | | if (Client.Endpoint == null) |
| | 1172 | | { |
| 0 | 1173 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1174 | | } |
| 4 | 1175 | | if (largePersonGroupId == null) |
| | 1176 | | { |
| 0 | 1177 | | throw new ValidationException(ValidationRules.CannotBeNull, "largePersonGroupId"); |
| | 1178 | | } |
| 4 | 1179 | | if (largePersonGroupId != null) |
| | 1180 | | { |
| 4 | 1181 | | if (largePersonGroupId.Length > 64) |
| | 1182 | | { |
| 0 | 1183 | | throw new ValidationException(ValidationRules.MaxLength, "largePersonGroupId", 64); |
| | 1184 | | } |
| 4 | 1185 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largePersonGroupId, "^[a-z0-9-_]+$")) |
| | 1186 | | { |
| 0 | 1187 | | throw new ValidationException(ValidationRules.Pattern, "largePersonGroupId", "^[a-z0-9-_]+$"); |
| | 1188 | | } |
| | 1189 | | } |
| | 1190 | | // Tracing |
| 4 | 1191 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 1192 | | string _invocationId = null; |
| 4 | 1193 | | if (_shouldTrace) |
| | 1194 | | { |
| 0 | 1195 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1196 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1197 | | tracingParameters.Add("largePersonGroupId", largePersonGroupId); |
| 0 | 1198 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1199 | | ServiceClientTracing.Enter(_invocationId, this, "Train", tracingParameters); |
| | 1200 | | } |
| | 1201 | | // Construct URL |
| 4 | 1202 | | var _baseUrl = Client.BaseUri; |
| 4 | 1203 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largepersongroups/{largePersonGroupId}/train"; |
| 4 | 1204 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 4 | 1205 | | _url = _url.Replace("{largePersonGroupId}", System.Uri.EscapeDataString(largePersonGroupId)); |
| | 1206 | | // Create HTTP transport objects |
| 4 | 1207 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 1208 | | HttpResponseMessage _httpResponse = null; |
| 4 | 1209 | | _httpRequest.Method = new HttpMethod("POST"); |
| 4 | 1210 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1211 | | // Set Headers |
| | 1212 | |
|
| | 1213 | |
|
| 4 | 1214 | | if (customHeaders != null) |
| | 1215 | | { |
| 0 | 1216 | | foreach(var _header in customHeaders) |
| | 1217 | | { |
| 0 | 1218 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1219 | | { |
| 0 | 1220 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1221 | | } |
| 0 | 1222 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1223 | | } |
| | 1224 | | } |
| | 1225 | |
|
| | 1226 | | // Serialize Request |
| 4 | 1227 | | string _requestContent = null; |
| | 1228 | | // Set Credentials |
| 4 | 1229 | | if (Client.Credentials != null) |
| | 1230 | | { |
| 4 | 1231 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1232 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1233 | | } |
| | 1234 | | // Send Request |
| 4 | 1235 | | if (_shouldTrace) |
| | 1236 | | { |
| 0 | 1237 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1238 | | } |
| 4 | 1239 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1240 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 1241 | | if (_shouldTrace) |
| | 1242 | | { |
| 0 | 1243 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1244 | | } |
| 4 | 1245 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 1246 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1247 | | string _responseContent = null; |
| 4 | 1248 | | if ((int)_statusCode != 202) |
| | 1249 | | { |
| 0 | 1250 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1251 | | try |
| | 1252 | | { |
| 0 | 1253 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1254 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1255 | | if (_errorBody != null) |
| | 1256 | | { |
| 0 | 1257 | | ex.Body = _errorBody; |
| | 1258 | | } |
| 0 | 1259 | | } |
| 0 | 1260 | | catch (JsonException) |
| | 1261 | | { |
| | 1262 | | // Ignore the exception |
| 0 | 1263 | | } |
| 0 | 1264 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1265 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1266 | | if (_shouldTrace) |
| | 1267 | | { |
| 0 | 1268 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1269 | | } |
| 0 | 1270 | | _httpRequest.Dispose(); |
| 0 | 1271 | | if (_httpResponse != null) |
| | 1272 | | { |
| 0 | 1273 | | _httpResponse.Dispose(); |
| | 1274 | | } |
| 0 | 1275 | | throw ex; |
| | 1276 | | } |
| | 1277 | | // Create Result |
| 4 | 1278 | | var _result = new HttpOperationResponse(); |
| 4 | 1279 | | _result.Request = _httpRequest; |
| 4 | 1280 | | _result.Response = _httpResponse; |
| 4 | 1281 | | if (_shouldTrace) |
| | 1282 | | { |
| 0 | 1283 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1284 | | } |
| 4 | 1285 | | return _result; |
| 4 | 1286 | | } |
| | 1287 | |
|
| | 1288 | | } |
| | 1289 | | } |