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