| | 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 | | /// LargeFaceListOperations operations. |
| | 27 | | /// </summary> |
| | 28 | | public partial class LargeFaceListOperations : IServiceOperations<FaceClient>, ILargeFaceListOperations |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the LargeFaceListOperations 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 LargeFaceListOperations(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> |
| 306 | 51 | | public FaceClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Create an empty large face list with user-specified largeFaceListId, name, |
| | 55 | | /// an optional userData and recognitionModel. |
| | 56 | | /// <br /> Large face list is a list of faces, up to 1,000,000 faces, and |
| | 57 | | /// used by [Face - Find |
| | 58 | | /// Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237). |
| | 59 | | /// <br /> After creation, user should use [LargeFaceList Face - |
| | 60 | | /// Add](/docs/services/563879b61984550e40cbbe8d/operations/5a158c10d2de3616c086f2d3) |
| | 61 | | /// to import the faces and [LargeFaceList - |
| | 62 | | /// Train](/docs/services/563879b61984550e40cbbe8d/operations/5a158422d2de3616c086f2d1) |
| | 63 | | /// to make it ready for [Face - Find |
| | 64 | | /// Similar](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395237). |
| | 65 | | /// No image will be stored. Only the extracted face features are stored on |
| | 66 | | /// server until [LargeFaceList - |
| | 67 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/5a1580d5d2de3616c086f2cd) |
| | 68 | | /// is called. |
| | 69 | | /// <br /> Find Similar is used for scenario like finding celebrity-like |
| | 70 | | /// faces, similar face filtering, or as a light way face identification. But |
| | 71 | | /// if the actual use is to identify person, please use |
| | 72 | | /// [PersonGroup](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395244) |
| | 73 | | /// / |
| | 74 | | /// [LargePersonGroup](/docs/services/563879b61984550e40cbbe8d/operations/599acdee6ac60f11b48b5a9d) |
| | 75 | | /// and [Face - |
| | 76 | | /// Identify](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395239). |
| | 77 | | /// <br/>'recognitionModel' should be specified to associate with this |
| | 78 | | /// large face list. The default value for 'recognitionModel' is |
| | 79 | | /// 'recognition_01', if the latest model needed, please explicitly specify the |
| | 80 | | /// model you need in this parameter. New faces that are added to an existing |
| | 81 | | /// large face list will use the recognition model that's already associated |
| | 82 | | /// with the collection. Existing face features in a large face list can't be |
| | 83 | | /// updated to features extracted by another version of recognition model. |
| | 84 | | /// * 'recognition_01': The default recognition model for [LargeFaceList- |
| | 85 | | /// Create](/docs/services/563879b61984550e40cbbe8d/operations/5a157b68d2de3616c086f2cc). |
| | 86 | | /// All those large face lists created before 2019 March are bonded with this |
| | 87 | | /// recognition model. |
| | 88 | | /// * 'recognition_02': Recognition model released in 2019 March. |
| | 89 | | /// 'recognition_02' is recommended since its overall accuracy is improved |
| | 90 | | /// compared with 'recognition_01'. |
| | 91 | | /// |
| | 92 | | /// Large face list quota: |
| | 93 | | /// * Free-tier subscription quota: 64 large face lists. |
| | 94 | | /// * S0-tier subscription quota: 1,000,000 large face lists. |
| | 95 | | /// </summary> |
| | 96 | | /// <param name='largeFaceListId'> |
| | 97 | | /// Id referencing a particular large face list. |
| | 98 | | /// </param> |
| | 99 | | /// <param name='name'> |
| | 100 | | /// User defined name, maximum length is 128. |
| | 101 | | /// </param> |
| | 102 | | /// <param name='userData'> |
| | 103 | | /// User specified data. Length should not exceed 16KB. |
| | 104 | | /// </param> |
| | 105 | | /// <param name='recognitionModel'> |
| | 106 | | /// Possible values include: 'recognition_01', 'recognition_02' |
| | 107 | | /// </param> |
| | 108 | | /// <param name='customHeaders'> |
| | 109 | | /// Headers that will be added to request. |
| | 110 | | /// </param> |
| | 111 | | /// <param name='cancellationToken'> |
| | 112 | | /// The cancellation token. |
| | 113 | | /// </param> |
| | 114 | | /// <exception cref="APIErrorException"> |
| | 115 | | /// Thrown when the operation returned an invalid status code |
| | 116 | | /// </exception> |
| | 117 | | /// <exception cref="ValidationException"> |
| | 118 | | /// Thrown when a required parameter is null |
| | 119 | | /// </exception> |
| | 120 | | /// <exception cref="System.ArgumentNullException"> |
| | 121 | | /// Thrown when a required parameter is null |
| | 122 | | /// </exception> |
| | 123 | | /// <return> |
| | 124 | | /// A response object containing the response body and response headers. |
| | 125 | | /// </return> |
| | 126 | | public async Task<HttpOperationResponse> CreateWithHttpMessagesAsync(string largeFaceListId, string name = defau |
| | 127 | | { |
| 4 | 128 | | if (Client.Endpoint == null) |
| | 129 | | { |
| 0 | 130 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 131 | | } |
| 4 | 132 | | if (largeFaceListId == null) |
| | 133 | | { |
| 0 | 134 | | throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId"); |
| | 135 | | } |
| 4 | 136 | | if (largeFaceListId != null) |
| | 137 | | { |
| 4 | 138 | | if (largeFaceListId.Length > 64) |
| | 139 | | { |
| 0 | 140 | | throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64); |
| | 141 | | } |
| 4 | 142 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$")) |
| | 143 | | { |
| 0 | 144 | | throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$"); |
| | 145 | | } |
| | 146 | | } |
| 4 | 147 | | if (name != null) |
| | 148 | | { |
| 4 | 149 | | if (name.Length > 128) |
| | 150 | | { |
| 0 | 151 | | throw new ValidationException(ValidationRules.MaxLength, "name", 128); |
| | 152 | | } |
| | 153 | | } |
| 4 | 154 | | if (userData != null) |
| | 155 | | { |
| 2 | 156 | | if (userData.Length > 16384) |
| | 157 | | { |
| 0 | 158 | | throw new ValidationException(ValidationRules.MaxLength, "userData", 16384); |
| | 159 | | } |
| | 160 | | } |
| 4 | 161 | | MetaDataContract body = new MetaDataContract(); |
| 4 | 162 | | if (name != null || userData != null || recognitionModel != null) |
| | 163 | | { |
| 4 | 164 | | body.Name = name; |
| 4 | 165 | | body.UserData = userData; |
| 4 | 166 | | body.RecognitionModel = recognitionModel; |
| | 167 | | } |
| | 168 | | // Tracing |
| 4 | 169 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 170 | | string _invocationId = null; |
| 4 | 171 | | if (_shouldTrace) |
| | 172 | | { |
| 0 | 173 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 174 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 175 | | tracingParameters.Add("largeFaceListId", largeFaceListId); |
| 0 | 176 | | tracingParameters.Add("body", body); |
| 0 | 177 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 178 | | ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters); |
| | 179 | | } |
| | 180 | | // Construct URL |
| 4 | 181 | | var _baseUrl = Client.BaseUri; |
| 4 | 182 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}"; |
| 4 | 183 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 4 | 184 | | _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId)); |
| | 185 | | // Create HTTP transport objects |
| 4 | 186 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 187 | | HttpResponseMessage _httpResponse = null; |
| 4 | 188 | | _httpRequest.Method = new HttpMethod("PUT"); |
| 4 | 189 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 190 | | // Set Headers |
| | 191 | |
|
| | 192 | |
|
| 4 | 193 | | if (customHeaders != null) |
| | 194 | | { |
| 0 | 195 | | foreach(var _header in customHeaders) |
| | 196 | | { |
| 0 | 197 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 198 | | { |
| 0 | 199 | | _httpRequest.Headers.Remove(_header.Key); |
| | 200 | | } |
| 0 | 201 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 202 | | } |
| | 203 | | } |
| | 204 | |
|
| | 205 | | // Serialize Request |
| 4 | 206 | | string _requestContent = null; |
| 4 | 207 | | if(body != null) |
| | 208 | | { |
| 4 | 209 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings) |
| 4 | 210 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 4 | 211 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 212 | | } |
| | 213 | | // Set Credentials |
| 4 | 214 | | if (Client.Credentials != null) |
| | 215 | | { |
| 4 | 216 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 217 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 218 | | } |
| | 219 | | // Send Request |
| 4 | 220 | | if (_shouldTrace) |
| | 221 | | { |
| 0 | 222 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 223 | | } |
| 4 | 224 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 225 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 226 | | if (_shouldTrace) |
| | 227 | | { |
| 0 | 228 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 229 | | } |
| 4 | 230 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 231 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 232 | | string _responseContent = null; |
| 4 | 233 | | if ((int)_statusCode != 200) |
| | 234 | | { |
| 0 | 235 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 236 | | try |
| | 237 | | { |
| 0 | 238 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 239 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 240 | | if (_errorBody != null) |
| | 241 | | { |
| 0 | 242 | | ex.Body = _errorBody; |
| | 243 | | } |
| 0 | 244 | | } |
| 0 | 245 | | catch (JsonException) |
| | 246 | | { |
| | 247 | | // Ignore the exception |
| 0 | 248 | | } |
| 0 | 249 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 250 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 251 | | if (_shouldTrace) |
| | 252 | | { |
| 0 | 253 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 254 | | } |
| 0 | 255 | | _httpRequest.Dispose(); |
| 0 | 256 | | if (_httpResponse != null) |
| | 257 | | { |
| 0 | 258 | | _httpResponse.Dispose(); |
| | 259 | | } |
| 0 | 260 | | throw ex; |
| | 261 | | } |
| | 262 | | // Create Result |
| 4 | 263 | | var _result = new HttpOperationResponse(); |
| 4 | 264 | | _result.Request = _httpRequest; |
| 4 | 265 | | _result.Response = _httpResponse; |
| 4 | 266 | | if (_shouldTrace) |
| | 267 | | { |
| 0 | 268 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 269 | | } |
| 4 | 270 | | return _result; |
| 4 | 271 | | } |
| | 272 | |
|
| | 273 | | /// <summary> |
| | 274 | | /// Retrieve a large face list’s largeFaceListId, name, userData and |
| | 275 | | /// recognitionModel. |
| | 276 | | /// </summary> |
| | 277 | | /// <param name='largeFaceListId'> |
| | 278 | | /// Id referencing a particular large face list. |
| | 279 | | /// </param> |
| | 280 | | /// <param name='returnRecognitionModel'> |
| | 281 | | /// A value indicating whether the operation should return 'recognitionModel' |
| | 282 | | /// in response. |
| | 283 | | /// </param> |
| | 284 | | /// <param name='customHeaders'> |
| | 285 | | /// Headers that will be added to request. |
| | 286 | | /// </param> |
| | 287 | | /// <param name='cancellationToken'> |
| | 288 | | /// The cancellation token. |
| | 289 | | /// </param> |
| | 290 | | /// <exception cref="APIErrorException"> |
| | 291 | | /// Thrown when the operation returned an invalid status code |
| | 292 | | /// </exception> |
| | 293 | | /// <exception cref="SerializationException"> |
| | 294 | | /// Thrown when unable to deserialize the response |
| | 295 | | /// </exception> |
| | 296 | | /// <exception cref="ValidationException"> |
| | 297 | | /// Thrown when a required parameter is null |
| | 298 | | /// </exception> |
| | 299 | | /// <exception cref="System.ArgumentNullException"> |
| | 300 | | /// Thrown when a required parameter is null |
| | 301 | | /// </exception> |
| | 302 | | /// <return> |
| | 303 | | /// A response object containing the response body and response headers. |
| | 304 | | /// </return> |
| | 305 | | public async Task<HttpOperationResponse<LargeFaceList>> GetWithHttpMessagesAsync(string largeFaceListId, bool? r |
| | 306 | | { |
| 2 | 307 | | if (Client.Endpoint == null) |
| | 308 | | { |
| 0 | 309 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 310 | | } |
| 2 | 311 | | if (largeFaceListId == null) |
| | 312 | | { |
| 0 | 313 | | throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId"); |
| | 314 | | } |
| 2 | 315 | | if (largeFaceListId != null) |
| | 316 | | { |
| 2 | 317 | | if (largeFaceListId.Length > 64) |
| | 318 | | { |
| 0 | 319 | | throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64); |
| | 320 | | } |
| 2 | 321 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$")) |
| | 322 | | { |
| 0 | 323 | | throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$"); |
| | 324 | | } |
| | 325 | | } |
| | 326 | | // Tracing |
| 2 | 327 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 328 | | string _invocationId = null; |
| 2 | 329 | | if (_shouldTrace) |
| | 330 | | { |
| 0 | 331 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 332 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 333 | | tracingParameters.Add("largeFaceListId", largeFaceListId); |
| 0 | 334 | | tracingParameters.Add("returnRecognitionModel", returnRecognitionModel); |
| 0 | 335 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 336 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 337 | | } |
| | 338 | | // Construct URL |
| 2 | 339 | | var _baseUrl = Client.BaseUri; |
| 2 | 340 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}"; |
| 2 | 341 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 2 | 342 | | _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId)); |
| 2 | 343 | | List<string> _queryParameters = new List<string>(); |
| 2 | 344 | | if (returnRecognitionModel != null) |
| | 345 | | { |
| 2 | 346 | | _queryParameters.Add(string.Format("returnRecognitionModel={0}", System.Uri.EscapeDataString(Rest.Serial |
| | 347 | | } |
| 2 | 348 | | if (_queryParameters.Count > 0) |
| | 349 | | { |
| 2 | 350 | | _url += "?" + string.Join("&", _queryParameters); |
| | 351 | | } |
| | 352 | | // Create HTTP transport objects |
| 2 | 353 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 354 | | HttpResponseMessage _httpResponse = null; |
| 2 | 355 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 356 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 357 | | // Set Headers |
| | 358 | |
|
| | 359 | |
|
| 2 | 360 | | if (customHeaders != null) |
| | 361 | | { |
| 0 | 362 | | foreach(var _header in customHeaders) |
| | 363 | | { |
| 0 | 364 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 365 | | { |
| 0 | 366 | | _httpRequest.Headers.Remove(_header.Key); |
| | 367 | | } |
| 0 | 368 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 369 | | } |
| | 370 | | } |
| | 371 | |
|
| | 372 | | // Serialize Request |
| 2 | 373 | | string _requestContent = null; |
| | 374 | | // Set Credentials |
| 2 | 375 | | if (Client.Credentials != null) |
| | 376 | | { |
| 2 | 377 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 378 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 379 | | } |
| | 380 | | // Send Request |
| 2 | 381 | | if (_shouldTrace) |
| | 382 | | { |
| 0 | 383 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 384 | | } |
| 2 | 385 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 386 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 387 | | if (_shouldTrace) |
| | 388 | | { |
| 0 | 389 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 390 | | } |
| 2 | 391 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 392 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 393 | | string _responseContent = null; |
| 2 | 394 | | if ((int)_statusCode != 200) |
| | 395 | | { |
| 0 | 396 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 397 | | try |
| | 398 | | { |
| 0 | 399 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 400 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 401 | | if (_errorBody != null) |
| | 402 | | { |
| 0 | 403 | | ex.Body = _errorBody; |
| | 404 | | } |
| 0 | 405 | | } |
| 0 | 406 | | catch (JsonException) |
| | 407 | | { |
| | 408 | | // Ignore the exception |
| 0 | 409 | | } |
| 0 | 410 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 411 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 412 | | if (_shouldTrace) |
| | 413 | | { |
| 0 | 414 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 415 | | } |
| 0 | 416 | | _httpRequest.Dispose(); |
| 0 | 417 | | if (_httpResponse != null) |
| | 418 | | { |
| 0 | 419 | | _httpResponse.Dispose(); |
| | 420 | | } |
| 0 | 421 | | throw ex; |
| | 422 | | } |
| | 423 | | // Create Result |
| 2 | 424 | | var _result = new HttpOperationResponse<LargeFaceList>(); |
| 2 | 425 | | _result.Request = _httpRequest; |
| 2 | 426 | | _result.Response = _httpResponse; |
| | 427 | | // Deserialize Response |
| 2 | 428 | | if ((int)_statusCode == 200) |
| | 429 | | { |
| 2 | 430 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 431 | | try |
| | 432 | | { |
| 2 | 433 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<LargeFaceList>(_responseContent, |
| 2 | 434 | | } |
| 0 | 435 | | catch (JsonException ex) |
| | 436 | | { |
| 0 | 437 | | _httpRequest.Dispose(); |
| 0 | 438 | | if (_httpResponse != null) |
| | 439 | | { |
| 0 | 440 | | _httpResponse.Dispose(); |
| | 441 | | } |
| 0 | 442 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 443 | | } |
| | 444 | | } |
| 2 | 445 | | if (_shouldTrace) |
| | 446 | | { |
| 0 | 447 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 448 | | } |
| 2 | 449 | | return _result; |
| 2 | 450 | | } |
| | 451 | |
|
| | 452 | | /// <summary> |
| | 453 | | /// Update information of a large face list. |
| | 454 | | /// </summary> |
| | 455 | | /// <param name='largeFaceListId'> |
| | 456 | | /// Id referencing a particular large face list. |
| | 457 | | /// </param> |
| | 458 | | /// <param name='name'> |
| | 459 | | /// User defined name, maximum length is 128. |
| | 460 | | /// </param> |
| | 461 | | /// <param name='userData'> |
| | 462 | | /// User specified data. Length should not exceed 16KB. |
| | 463 | | /// </param> |
| | 464 | | /// <param name='customHeaders'> |
| | 465 | | /// Headers that will be added to request. |
| | 466 | | /// </param> |
| | 467 | | /// <param name='cancellationToken'> |
| | 468 | | /// The cancellation token. |
| | 469 | | /// </param> |
| | 470 | | /// <exception cref="APIErrorException"> |
| | 471 | | /// Thrown when the operation returned an invalid status code |
| | 472 | | /// </exception> |
| | 473 | | /// <exception cref="ValidationException"> |
| | 474 | | /// Thrown when a required parameter is null |
| | 475 | | /// </exception> |
| | 476 | | /// <exception cref="System.ArgumentNullException"> |
| | 477 | | /// Thrown when a required parameter is null |
| | 478 | | /// </exception> |
| | 479 | | /// <return> |
| | 480 | | /// A response object containing the response body and response headers. |
| | 481 | | /// </return> |
| | 482 | | public async Task<HttpOperationResponse> UpdateWithHttpMessagesAsync(string largeFaceListId, string name = defau |
| | 483 | | { |
| 0 | 484 | | if (Client.Endpoint == null) |
| | 485 | | { |
| 0 | 486 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 487 | | } |
| 0 | 488 | | if (largeFaceListId == null) |
| | 489 | | { |
| 0 | 490 | | throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId"); |
| | 491 | | } |
| 0 | 492 | | if (largeFaceListId != null) |
| | 493 | | { |
| 0 | 494 | | if (largeFaceListId.Length > 64) |
| | 495 | | { |
| 0 | 496 | | throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64); |
| | 497 | | } |
| 0 | 498 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$")) |
| | 499 | | { |
| 0 | 500 | | throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$"); |
| | 501 | | } |
| | 502 | | } |
| 0 | 503 | | if (name != null) |
| | 504 | | { |
| 0 | 505 | | if (name.Length > 128) |
| | 506 | | { |
| 0 | 507 | | throw new ValidationException(ValidationRules.MaxLength, "name", 128); |
| | 508 | | } |
| | 509 | | } |
| 0 | 510 | | if (userData != null) |
| | 511 | | { |
| 0 | 512 | | if (userData.Length > 16384) |
| | 513 | | { |
| 0 | 514 | | throw new ValidationException(ValidationRules.MaxLength, "userData", 16384); |
| | 515 | | } |
| | 516 | | } |
| 0 | 517 | | NameAndUserDataContract body = new NameAndUserDataContract(); |
| 0 | 518 | | if (name != null || userData != null) |
| | 519 | | { |
| 0 | 520 | | body.Name = name; |
| 0 | 521 | | body.UserData = userData; |
| | 522 | | } |
| | 523 | | // Tracing |
| 0 | 524 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 525 | | string _invocationId = null; |
| 0 | 526 | | if (_shouldTrace) |
| | 527 | | { |
| 0 | 528 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 529 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 530 | | tracingParameters.Add("largeFaceListId", largeFaceListId); |
| 0 | 531 | | tracingParameters.Add("body", body); |
| 0 | 532 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 533 | | ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters); |
| | 534 | | } |
| | 535 | | // Construct URL |
| 0 | 536 | | var _baseUrl = Client.BaseUri; |
| 0 | 537 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}"; |
| 0 | 538 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 539 | | _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId)); |
| | 540 | | // Create HTTP transport objects |
| 0 | 541 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 542 | | HttpResponseMessage _httpResponse = null; |
| 0 | 543 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 0 | 544 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 545 | | // Set Headers |
| | 546 | |
|
| | 547 | |
|
| 0 | 548 | | if (customHeaders != null) |
| | 549 | | { |
| 0 | 550 | | foreach(var _header in customHeaders) |
| | 551 | | { |
| 0 | 552 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 553 | | { |
| 0 | 554 | | _httpRequest.Headers.Remove(_header.Key); |
| | 555 | | } |
| 0 | 556 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 557 | | } |
| | 558 | | } |
| | 559 | |
|
| | 560 | | // Serialize Request |
| 0 | 561 | | string _requestContent = null; |
| 0 | 562 | | if(body != null) |
| | 563 | | { |
| 0 | 564 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings) |
| 0 | 565 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 566 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 567 | | } |
| | 568 | | // Set Credentials |
| 0 | 569 | | if (Client.Credentials != null) |
| | 570 | | { |
| 0 | 571 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 572 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 573 | | } |
| | 574 | | // Send Request |
| 0 | 575 | | if (_shouldTrace) |
| | 576 | | { |
| 0 | 577 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 578 | | } |
| 0 | 579 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 580 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 581 | | if (_shouldTrace) |
| | 582 | | { |
| 0 | 583 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 584 | | } |
| 0 | 585 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 586 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 587 | | string _responseContent = null; |
| 0 | 588 | | if ((int)_statusCode != 200) |
| | 589 | | { |
| 0 | 590 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 591 | | try |
| | 592 | | { |
| 0 | 593 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 594 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 595 | | if (_errorBody != null) |
| | 596 | | { |
| 0 | 597 | | ex.Body = _errorBody; |
| | 598 | | } |
| 0 | 599 | | } |
| 0 | 600 | | catch (JsonException) |
| | 601 | | { |
| | 602 | | // Ignore the exception |
| 0 | 603 | | } |
| 0 | 604 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 605 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 606 | | if (_shouldTrace) |
| | 607 | | { |
| 0 | 608 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 609 | | } |
| 0 | 610 | | _httpRequest.Dispose(); |
| 0 | 611 | | if (_httpResponse != null) |
| | 612 | | { |
| 0 | 613 | | _httpResponse.Dispose(); |
| | 614 | | } |
| 0 | 615 | | throw ex; |
| | 616 | | } |
| | 617 | | // Create Result |
| 0 | 618 | | var _result = new HttpOperationResponse(); |
| 0 | 619 | | _result.Request = _httpRequest; |
| 0 | 620 | | _result.Response = _httpResponse; |
| 0 | 621 | | if (_shouldTrace) |
| | 622 | | { |
| 0 | 623 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 624 | | } |
| 0 | 625 | | return _result; |
| 0 | 626 | | } |
| | 627 | |
|
| | 628 | | /// <summary> |
| | 629 | | /// Delete a specified large face list. |
| | 630 | | /// </summary> |
| | 631 | | /// <param name='largeFaceListId'> |
| | 632 | | /// Id referencing a particular large face list. |
| | 633 | | /// </param> |
| | 634 | | /// <param name='customHeaders'> |
| | 635 | | /// Headers that will be added to request. |
| | 636 | | /// </param> |
| | 637 | | /// <param name='cancellationToken'> |
| | 638 | | /// The cancellation token. |
| | 639 | | /// </param> |
| | 640 | | /// <exception cref="APIErrorException"> |
| | 641 | | /// Thrown when the operation returned an invalid status code |
| | 642 | | /// </exception> |
| | 643 | | /// <exception cref="ValidationException"> |
| | 644 | | /// Thrown when a required parameter is null |
| | 645 | | /// </exception> |
| | 646 | | /// <exception cref="System.ArgumentNullException"> |
| | 647 | | /// Thrown when a required parameter is null |
| | 648 | | /// </exception> |
| | 649 | | /// <return> |
| | 650 | | /// A response object containing the response body and response headers. |
| | 651 | | /// </return> |
| | 652 | | public async Task<HttpOperationResponse> DeleteWithHttpMessagesAsync(string largeFaceListId, Dictionary<string, |
| | 653 | | { |
| 6 | 654 | | if (Client.Endpoint == null) |
| | 655 | | { |
| 0 | 656 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 657 | | } |
| 6 | 658 | | if (largeFaceListId == null) |
| | 659 | | { |
| 0 | 660 | | throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId"); |
| | 661 | | } |
| 6 | 662 | | if (largeFaceListId != null) |
| | 663 | | { |
| 6 | 664 | | if (largeFaceListId.Length > 64) |
| | 665 | | { |
| 0 | 666 | | throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64); |
| | 667 | | } |
| 6 | 668 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$")) |
| | 669 | | { |
| 0 | 670 | | throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$"); |
| | 671 | | } |
| | 672 | | } |
| | 673 | | // Tracing |
| 6 | 674 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 6 | 675 | | string _invocationId = null; |
| 6 | 676 | | if (_shouldTrace) |
| | 677 | | { |
| 0 | 678 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 679 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 680 | | tracingParameters.Add("largeFaceListId", largeFaceListId); |
| 0 | 681 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 682 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 683 | | } |
| | 684 | | // Construct URL |
| 6 | 685 | | var _baseUrl = Client.BaseUri; |
| 6 | 686 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}"; |
| 6 | 687 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 6 | 688 | | _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId)); |
| | 689 | | // Create HTTP transport objects |
| 6 | 690 | | var _httpRequest = new HttpRequestMessage(); |
| 6 | 691 | | HttpResponseMessage _httpResponse = null; |
| 6 | 692 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 6 | 693 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 694 | | // Set Headers |
| | 695 | |
|
| | 696 | |
|
| 6 | 697 | | if (customHeaders != null) |
| | 698 | | { |
| 0 | 699 | | foreach(var _header in customHeaders) |
| | 700 | | { |
| 0 | 701 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 702 | | { |
| 0 | 703 | | _httpRequest.Headers.Remove(_header.Key); |
| | 704 | | } |
| 0 | 705 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 706 | | } |
| | 707 | | } |
| | 708 | |
|
| | 709 | | // Serialize Request |
| 6 | 710 | | string _requestContent = null; |
| | 711 | | // Set Credentials |
| 6 | 712 | | if (Client.Credentials != null) |
| | 713 | | { |
| 6 | 714 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 715 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 716 | | } |
| | 717 | | // Send Request |
| 6 | 718 | | if (_shouldTrace) |
| | 719 | | { |
| 0 | 720 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 721 | | } |
| 6 | 722 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 723 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 6 | 724 | | if (_shouldTrace) |
| | 725 | | { |
| 0 | 726 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 727 | | } |
| 6 | 728 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 6 | 729 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 730 | | string _responseContent = null; |
| 6 | 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 |
| 6 | 761 | | var _result = new HttpOperationResponse(); |
| 6 | 762 | | _result.Request = _httpRequest; |
| 6 | 763 | | _result.Response = _httpResponse; |
| 6 | 764 | | if (_shouldTrace) |
| | 765 | | { |
| 0 | 766 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 767 | | } |
| 6 | 768 | | return _result; |
| 6 | 769 | | } |
| | 770 | |
|
| | 771 | | /// <summary> |
| | 772 | | /// Retrieve the training status of a large face list (completed or ongoing). |
| | 773 | | /// </summary> |
| | 774 | | /// <param name='largeFaceListId'> |
| | 775 | | /// Id referencing a particular large face list. |
| | 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 largeFace |
| | 799 | | { |
| 8 | 800 | | if (Client.Endpoint == null) |
| | 801 | | { |
| 0 | 802 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 803 | | } |
| 8 | 804 | | if (largeFaceListId == null) |
| | 805 | | { |
| 0 | 806 | | throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId"); |
| | 807 | | } |
| 8 | 808 | | if (largeFaceListId != null) |
| | 809 | | { |
| 8 | 810 | | if (largeFaceListId.Length > 64) |
| | 811 | | { |
| 0 | 812 | | throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64); |
| | 813 | | } |
| 8 | 814 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$")) |
| | 815 | | { |
| 0 | 816 | | throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$"); |
| | 817 | | } |
| | 818 | | } |
| | 819 | | // Tracing |
| 8 | 820 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 8 | 821 | | string _invocationId = null; |
| 8 | 822 | | if (_shouldTrace) |
| | 823 | | { |
| 0 | 824 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 825 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 826 | | tracingParameters.Add("largeFaceListId", largeFaceListId); |
| 0 | 827 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 828 | | ServiceClientTracing.Enter(_invocationId, this, "GetTrainingStatus", tracingParameters); |
| | 829 | | } |
| | 830 | | // Construct URL |
| 8 | 831 | | var _baseUrl = Client.BaseUri; |
| 8 | 832 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/training"; |
| 8 | 833 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 8 | 834 | | _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId)); |
| | 835 | | // Create HTTP transport objects |
| 8 | 836 | | var _httpRequest = new HttpRequestMessage(); |
| 8 | 837 | | HttpResponseMessage _httpResponse = null; |
| 8 | 838 | | _httpRequest.Method = new HttpMethod("GET"); |
| 8 | 839 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 840 | | // Set Headers |
| | 841 | |
|
| | 842 | |
|
| 8 | 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 |
| 8 | 856 | | string _requestContent = null; |
| | 857 | | // Set Credentials |
| 8 | 858 | | if (Client.Credentials != null) |
| | 859 | | { |
| 8 | 860 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 861 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 862 | | } |
| | 863 | | // Send Request |
| 8 | 864 | | if (_shouldTrace) |
| | 865 | | { |
| 0 | 866 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 867 | | } |
| 8 | 868 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 869 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 8 | 870 | | if (_shouldTrace) |
| | 871 | | { |
| 0 | 872 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 873 | | } |
| 8 | 874 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 8 | 875 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 876 | | string _responseContent = null; |
| 8 | 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 |
| 8 | 907 | | var _result = new HttpOperationResponse<TrainingStatus>(); |
| 8 | 908 | | _result.Request = _httpRequest; |
| 8 | 909 | | _result.Response = _httpResponse; |
| | 910 | | // Deserialize Response |
| 8 | 911 | | if ((int)_statusCode == 200) |
| | 912 | | { |
| 8 | 913 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 914 | | try |
| | 915 | | { |
| 8 | 916 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<TrainingStatus>(_responseContent |
| 8 | 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 | | } |
| 8 | 928 | | if (_shouldTrace) |
| | 929 | | { |
| 0 | 930 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 931 | | } |
| 8 | 932 | | return _result; |
| 8 | 933 | | } |
| | 934 | |
|
| | 935 | | /// <summary> |
| | 936 | | /// List large face lists’ information of largeFaceListId, name, userData and |
| | 937 | | /// recognitionModel. <br /> |
| | 938 | | /// To get face information inside largeFaceList use [LargeFaceList Face - |
| | 939 | | /// Get](/docs/services/563879b61984550e40cbbe8d/operations/5a158cf2d2de3616c086f2d5)<br |
| | 940 | | /// /> |
| | 941 | | /// * Large face lists are stored in alphabetical order of largeFaceListId. |
| | 942 | | /// * "start" parameter (string, optional) is a user-provided largeFaceListId |
| | 943 | | /// value that returned entries have larger ids by string comparison. "start" |
| | 944 | | /// 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 lists: "list1", ..., "list5". |
| | 951 | | /// <br /> "start=&top=" will return all 5 lists. |
| | 952 | | /// <br /> "start=&top=2" will return "list1", "list2". |
| | 953 | | /// <br /> "start=list2&top=3" will return "list3", "list4", "list5". |
| | 954 | | /// |
| | 955 | | /// </summary> |
| | 956 | | /// <param name='returnRecognitionModel'> |
| | 957 | | /// A value indicating whether the operation should return 'recognitionModel' |
| | 958 | | /// in response. |
| | 959 | | /// </param> |
| | 960 | | /// <param name='customHeaders'> |
| | 961 | | /// Headers that will be added to request. |
| | 962 | | /// </param> |
| | 963 | | /// <param name='cancellationToken'> |
| | 964 | | /// The cancellation token. |
| | 965 | | /// </param> |
| | 966 | | /// <exception cref="APIErrorException"> |
| | 967 | | /// Thrown when the operation returned an invalid status code |
| | 968 | | /// </exception> |
| | 969 | | /// <exception cref="SerializationException"> |
| | 970 | | /// Thrown when unable to deserialize the response |
| | 971 | | /// </exception> |
| | 972 | | /// <exception cref="ValidationException"> |
| | 973 | | /// Thrown when a required parameter is null |
| | 974 | | /// </exception> |
| | 975 | | /// <exception cref="System.ArgumentNullException"> |
| | 976 | | /// Thrown when a required parameter is null |
| | 977 | | /// </exception> |
| | 978 | | /// <return> |
| | 979 | | /// A response object containing the response body and response headers. |
| | 980 | | /// </return> |
| | 981 | | public async Task<HttpOperationResponse<IList<LargeFaceList>>> ListWithHttpMessagesAsync(bool? returnRecognition |
| | 982 | | { |
| 0 | 983 | | if (Client.Endpoint == null) |
| | 984 | | { |
| 0 | 985 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 986 | | } |
| | 987 | | // Tracing |
| 0 | 988 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 989 | | string _invocationId = null; |
| 0 | 990 | | if (_shouldTrace) |
| | 991 | | { |
| 0 | 992 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 993 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 994 | | tracingParameters.Add("returnRecognitionModel", returnRecognitionModel); |
| 0 | 995 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 996 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | 997 | | } |
| | 998 | | // Construct URL |
| 0 | 999 | | var _baseUrl = Client.BaseUri; |
| 0 | 1000 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists"; |
| 0 | 1001 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1002 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1003 | | if (returnRecognitionModel != null) |
| | 1004 | | { |
| 0 | 1005 | | _queryParameters.Add(string.Format("returnRecognitionModel={0}", System.Uri.EscapeDataString(Rest.Serial |
| | 1006 | | } |
| 0 | 1007 | | if (_queryParameters.Count > 0) |
| | 1008 | | { |
| 0 | 1009 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1010 | | } |
| | 1011 | | // Create HTTP transport objects |
| 0 | 1012 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1013 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1014 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 1015 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1016 | | // Set Headers |
| | 1017 | |
|
| | 1018 | |
|
| 0 | 1019 | | if (customHeaders != null) |
| | 1020 | | { |
| 0 | 1021 | | foreach(var _header in customHeaders) |
| | 1022 | | { |
| 0 | 1023 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1024 | | { |
| 0 | 1025 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1026 | | } |
| 0 | 1027 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1028 | | } |
| | 1029 | | } |
| | 1030 | |
|
| | 1031 | | // Serialize Request |
| 0 | 1032 | | string _requestContent = null; |
| | 1033 | | // Set Credentials |
| 0 | 1034 | | if (Client.Credentials != null) |
| | 1035 | | { |
| 0 | 1036 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1037 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1038 | | } |
| | 1039 | | // Send Request |
| 0 | 1040 | | if (_shouldTrace) |
| | 1041 | | { |
| 0 | 1042 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1043 | | } |
| 0 | 1044 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1045 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1046 | | if (_shouldTrace) |
| | 1047 | | { |
| 0 | 1048 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1049 | | } |
| 0 | 1050 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1051 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1052 | | string _responseContent = null; |
| 0 | 1053 | | if ((int)_statusCode != 200) |
| | 1054 | | { |
| 0 | 1055 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1056 | | try |
| | 1057 | | { |
| 0 | 1058 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1059 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1060 | | if (_errorBody != null) |
| | 1061 | | { |
| 0 | 1062 | | ex.Body = _errorBody; |
| | 1063 | | } |
| 0 | 1064 | | } |
| 0 | 1065 | | catch (JsonException) |
| | 1066 | | { |
| | 1067 | | // Ignore the exception |
| 0 | 1068 | | } |
| 0 | 1069 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1070 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1071 | | if (_shouldTrace) |
| | 1072 | | { |
| 0 | 1073 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1074 | | } |
| 0 | 1075 | | _httpRequest.Dispose(); |
| 0 | 1076 | | if (_httpResponse != null) |
| | 1077 | | { |
| 0 | 1078 | | _httpResponse.Dispose(); |
| | 1079 | | } |
| 0 | 1080 | | throw ex; |
| | 1081 | | } |
| | 1082 | | // Create Result |
| 0 | 1083 | | var _result = new HttpOperationResponse<IList<LargeFaceList>>(); |
| 0 | 1084 | | _result.Request = _httpRequest; |
| 0 | 1085 | | _result.Response = _httpResponse; |
| | 1086 | | // Deserialize Response |
| 0 | 1087 | | if ((int)_statusCode == 200) |
| | 1088 | | { |
| 0 | 1089 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1090 | | try |
| | 1091 | | { |
| 0 | 1092 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<LargeFaceList>>(_responseC |
| 0 | 1093 | | } |
| 0 | 1094 | | catch (JsonException ex) |
| | 1095 | | { |
| 0 | 1096 | | _httpRequest.Dispose(); |
| 0 | 1097 | | if (_httpResponse != null) |
| | 1098 | | { |
| 0 | 1099 | | _httpResponse.Dispose(); |
| | 1100 | | } |
| 0 | 1101 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1102 | | } |
| | 1103 | | } |
| 0 | 1104 | | if (_shouldTrace) |
| | 1105 | | { |
| 0 | 1106 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1107 | | } |
| 0 | 1108 | | return _result; |
| 0 | 1109 | | } |
| | 1110 | |
|
| | 1111 | | /// <summary> |
| | 1112 | | /// Queue a large face list training task, the training task may not be started |
| | 1113 | | /// immediately. |
| | 1114 | | /// </summary> |
| | 1115 | | /// <param name='largeFaceListId'> |
| | 1116 | | /// Id referencing a particular large face list. |
| | 1117 | | /// </param> |
| | 1118 | | /// <param name='customHeaders'> |
| | 1119 | | /// Headers that will be added to request. |
| | 1120 | | /// </param> |
| | 1121 | | /// <param name='cancellationToken'> |
| | 1122 | | /// The cancellation token. |
| | 1123 | | /// </param> |
| | 1124 | | /// <exception cref="APIErrorException"> |
| | 1125 | | /// Thrown when the operation returned an invalid status code |
| | 1126 | | /// </exception> |
| | 1127 | | /// <exception cref="ValidationException"> |
| | 1128 | | /// Thrown when a required parameter is null |
| | 1129 | | /// </exception> |
| | 1130 | | /// <exception cref="System.ArgumentNullException"> |
| | 1131 | | /// Thrown when a required parameter is null |
| | 1132 | | /// </exception> |
| | 1133 | | /// <return> |
| | 1134 | | /// A response object containing the response body and response headers. |
| | 1135 | | /// </return> |
| | 1136 | | public async Task<HttpOperationResponse> TrainWithHttpMessagesAsync(string largeFaceListId, Dictionary<string, L |
| | 1137 | | { |
| 4 | 1138 | | if (Client.Endpoint == null) |
| | 1139 | | { |
| 0 | 1140 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1141 | | } |
| 4 | 1142 | | if (largeFaceListId == null) |
| | 1143 | | { |
| 0 | 1144 | | throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId"); |
| | 1145 | | } |
| 4 | 1146 | | if (largeFaceListId != null) |
| | 1147 | | { |
| 4 | 1148 | | if (largeFaceListId.Length > 64) |
| | 1149 | | { |
| 0 | 1150 | | throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64); |
| | 1151 | | } |
| 4 | 1152 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$")) |
| | 1153 | | { |
| 0 | 1154 | | throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$"); |
| | 1155 | | } |
| | 1156 | | } |
| | 1157 | | // Tracing |
| 4 | 1158 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 1159 | | string _invocationId = null; |
| 4 | 1160 | | if (_shouldTrace) |
| | 1161 | | { |
| 0 | 1162 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1163 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1164 | | tracingParameters.Add("largeFaceListId", largeFaceListId); |
| 0 | 1165 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1166 | | ServiceClientTracing.Enter(_invocationId, this, "Train", tracingParameters); |
| | 1167 | | } |
| | 1168 | | // Construct URL |
| 4 | 1169 | | var _baseUrl = Client.BaseUri; |
| 4 | 1170 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/train"; |
| 4 | 1171 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 4 | 1172 | | _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId)); |
| | 1173 | | // Create HTTP transport objects |
| 4 | 1174 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 1175 | | HttpResponseMessage _httpResponse = null; |
| 4 | 1176 | | _httpRequest.Method = new HttpMethod("POST"); |
| 4 | 1177 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1178 | | // Set Headers |
| | 1179 | |
|
| | 1180 | |
|
| 4 | 1181 | | if (customHeaders != null) |
| | 1182 | | { |
| 0 | 1183 | | foreach(var _header in customHeaders) |
| | 1184 | | { |
| 0 | 1185 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1186 | | { |
| 0 | 1187 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1188 | | } |
| 0 | 1189 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1190 | | } |
| | 1191 | | } |
| | 1192 | |
|
| | 1193 | | // Serialize Request |
| 4 | 1194 | | string _requestContent = null; |
| | 1195 | | // Set Credentials |
| 4 | 1196 | | if (Client.Credentials != null) |
| | 1197 | | { |
| 4 | 1198 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1199 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1200 | | } |
| | 1201 | | // Send Request |
| 4 | 1202 | | if (_shouldTrace) |
| | 1203 | | { |
| 0 | 1204 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1205 | | } |
| 4 | 1206 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1207 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 1208 | | if (_shouldTrace) |
| | 1209 | | { |
| 0 | 1210 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1211 | | } |
| 4 | 1212 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 1213 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 1214 | | string _responseContent = null; |
| 4 | 1215 | | if ((int)_statusCode != 202) |
| | 1216 | | { |
| 0 | 1217 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1218 | | try |
| | 1219 | | { |
| 0 | 1220 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1221 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1222 | | if (_errorBody != null) |
| | 1223 | | { |
| 0 | 1224 | | ex.Body = _errorBody; |
| | 1225 | | } |
| 0 | 1226 | | } |
| 0 | 1227 | | catch (JsonException) |
| | 1228 | | { |
| | 1229 | | // Ignore the exception |
| 0 | 1230 | | } |
| 0 | 1231 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1232 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1233 | | if (_shouldTrace) |
| | 1234 | | { |
| 0 | 1235 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1236 | | } |
| 0 | 1237 | | _httpRequest.Dispose(); |
| 0 | 1238 | | if (_httpResponse != null) |
| | 1239 | | { |
| 0 | 1240 | | _httpResponse.Dispose(); |
| | 1241 | | } |
| 0 | 1242 | | throw ex; |
| | 1243 | | } |
| | 1244 | | // Create Result |
| 4 | 1245 | | var _result = new HttpOperationResponse(); |
| 4 | 1246 | | _result.Request = _httpRequest; |
| 4 | 1247 | | _result.Response = _httpResponse; |
| 4 | 1248 | | if (_shouldTrace) |
| | 1249 | | { |
| 0 | 1250 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1251 | | } |
| 4 | 1252 | | return _result; |
| 4 | 1253 | | } |
| | 1254 | |
|
| | 1255 | | /// <summary> |
| | 1256 | | /// Delete a face from a large face list by specified largeFaceListId and |
| | 1257 | | /// persistedFaceId. |
| | 1258 | | /// <br /> Adding/deleting faces to/from a same large face list are |
| | 1259 | | /// processed sequentially and to/from different large face lists are in |
| | 1260 | | /// parallel. |
| | 1261 | | /// </summary> |
| | 1262 | | /// <param name='largeFaceListId'> |
| | 1263 | | /// Id referencing a particular large face list. |
| | 1264 | | /// </param> |
| | 1265 | | /// <param name='persistedFaceId'> |
| | 1266 | | /// Id referencing a particular persistedFaceId of an existing face. |
| | 1267 | | /// </param> |
| | 1268 | | /// <param name='customHeaders'> |
| | 1269 | | /// Headers that will be added to request. |
| | 1270 | | /// </param> |
| | 1271 | | /// <param name='cancellationToken'> |
| | 1272 | | /// The cancellation token. |
| | 1273 | | /// </param> |
| | 1274 | | /// <exception cref="APIErrorException"> |
| | 1275 | | /// Thrown when the operation returned an invalid status code |
| | 1276 | | /// </exception> |
| | 1277 | | /// <exception cref="ValidationException"> |
| | 1278 | | /// Thrown when a required parameter is null |
| | 1279 | | /// </exception> |
| | 1280 | | /// <exception cref="System.ArgumentNullException"> |
| | 1281 | | /// Thrown when a required parameter is null |
| | 1282 | | /// </exception> |
| | 1283 | | /// <return> |
| | 1284 | | /// A response object containing the response body and response headers. |
| | 1285 | | /// </return> |
| | 1286 | | public async Task<HttpOperationResponse> DeleteFaceWithHttpMessagesAsync(string largeFaceListId, System.Guid per |
| | 1287 | | { |
| 0 | 1288 | | if (Client.Endpoint == null) |
| | 1289 | | { |
| 0 | 1290 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1291 | | } |
| 0 | 1292 | | if (largeFaceListId == null) |
| | 1293 | | { |
| 0 | 1294 | | throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId"); |
| | 1295 | | } |
| 0 | 1296 | | if (largeFaceListId != null) |
| | 1297 | | { |
| 0 | 1298 | | if (largeFaceListId.Length > 64) |
| | 1299 | | { |
| 0 | 1300 | | throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64); |
| | 1301 | | } |
| 0 | 1302 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$")) |
| | 1303 | | { |
| 0 | 1304 | | throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$"); |
| | 1305 | | } |
| | 1306 | | } |
| | 1307 | | // Tracing |
| 0 | 1308 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1309 | | string _invocationId = null; |
| 0 | 1310 | | if (_shouldTrace) |
| | 1311 | | { |
| 0 | 1312 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1313 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1314 | | tracingParameters.Add("largeFaceListId", largeFaceListId); |
| 0 | 1315 | | tracingParameters.Add("persistedFaceId", persistedFaceId); |
| 0 | 1316 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1317 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteFace", tracingParameters); |
| | 1318 | | } |
| | 1319 | | // Construct URL |
| 0 | 1320 | | var _baseUrl = Client.BaseUri; |
| 0 | 1321 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/persistedfaces |
| 0 | 1322 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1323 | | _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId)); |
| 0 | 1324 | | _url = _url.Replace("{persistedFaceId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Seri |
| | 1325 | | // Create HTTP transport objects |
| 0 | 1326 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1327 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1328 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 1329 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1330 | | // Set Headers |
| | 1331 | |
|
| | 1332 | |
|
| 0 | 1333 | | if (customHeaders != null) |
| | 1334 | | { |
| 0 | 1335 | | foreach(var _header in customHeaders) |
| | 1336 | | { |
| 0 | 1337 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1338 | | { |
| 0 | 1339 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1340 | | } |
| 0 | 1341 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1342 | | } |
| | 1343 | | } |
| | 1344 | |
|
| | 1345 | | // Serialize Request |
| 0 | 1346 | | string _requestContent = null; |
| | 1347 | | // Set Credentials |
| 0 | 1348 | | if (Client.Credentials != null) |
| | 1349 | | { |
| 0 | 1350 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1351 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1352 | | } |
| | 1353 | | // Send Request |
| 0 | 1354 | | if (_shouldTrace) |
| | 1355 | | { |
| 0 | 1356 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1357 | | } |
| 0 | 1358 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1359 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1360 | | if (_shouldTrace) |
| | 1361 | | { |
| 0 | 1362 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1363 | | } |
| 0 | 1364 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1365 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1366 | | string _responseContent = null; |
| 0 | 1367 | | if ((int)_statusCode != 200) |
| | 1368 | | { |
| 0 | 1369 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1370 | | try |
| | 1371 | | { |
| 0 | 1372 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1373 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1374 | | if (_errorBody != null) |
| | 1375 | | { |
| 0 | 1376 | | ex.Body = _errorBody; |
| | 1377 | | } |
| 0 | 1378 | | } |
| 0 | 1379 | | catch (JsonException) |
| | 1380 | | { |
| | 1381 | | // Ignore the exception |
| 0 | 1382 | | } |
| 0 | 1383 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1384 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1385 | | if (_shouldTrace) |
| | 1386 | | { |
| 0 | 1387 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1388 | | } |
| 0 | 1389 | | _httpRequest.Dispose(); |
| 0 | 1390 | | if (_httpResponse != null) |
| | 1391 | | { |
| 0 | 1392 | | _httpResponse.Dispose(); |
| | 1393 | | } |
| 0 | 1394 | | throw ex; |
| | 1395 | | } |
| | 1396 | | // Create Result |
| 0 | 1397 | | var _result = new HttpOperationResponse(); |
| 0 | 1398 | | _result.Request = _httpRequest; |
| 0 | 1399 | | _result.Response = _httpResponse; |
| 0 | 1400 | | if (_shouldTrace) |
| | 1401 | | { |
| 0 | 1402 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1403 | | } |
| 0 | 1404 | | return _result; |
| 0 | 1405 | | } |
| | 1406 | |
|
| | 1407 | | /// <summary> |
| | 1408 | | /// Retrieve information about a persisted face (specified by persistedFaceId |
| | 1409 | | /// and its belonging largeFaceListId). |
| | 1410 | | /// </summary> |
| | 1411 | | /// <param name='largeFaceListId'> |
| | 1412 | | /// Id referencing a particular large face list. |
| | 1413 | | /// </param> |
| | 1414 | | /// <param name='persistedFaceId'> |
| | 1415 | | /// Id referencing a particular persistedFaceId of an existing face. |
| | 1416 | | /// </param> |
| | 1417 | | /// <param name='customHeaders'> |
| | 1418 | | /// Headers that will be added to request. |
| | 1419 | | /// </param> |
| | 1420 | | /// <param name='cancellationToken'> |
| | 1421 | | /// The cancellation token. |
| | 1422 | | /// </param> |
| | 1423 | | /// <exception cref="APIErrorException"> |
| | 1424 | | /// Thrown when the operation returned an invalid status code |
| | 1425 | | /// </exception> |
| | 1426 | | /// <exception cref="SerializationException"> |
| | 1427 | | /// Thrown when unable to deserialize the response |
| | 1428 | | /// </exception> |
| | 1429 | | /// <exception cref="ValidationException"> |
| | 1430 | | /// Thrown when a required parameter is null |
| | 1431 | | /// </exception> |
| | 1432 | | /// <exception cref="System.ArgumentNullException"> |
| | 1433 | | /// Thrown when a required parameter is null |
| | 1434 | | /// </exception> |
| | 1435 | | /// <return> |
| | 1436 | | /// A response object containing the response body and response headers. |
| | 1437 | | /// </return> |
| | 1438 | | public async Task<HttpOperationResponse<PersistedFace>> GetFaceWithHttpMessagesAsync(string largeFaceListId, Sys |
| | 1439 | | { |
| 0 | 1440 | | if (Client.Endpoint == null) |
| | 1441 | | { |
| 0 | 1442 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1443 | | } |
| 0 | 1444 | | if (largeFaceListId == null) |
| | 1445 | | { |
| 0 | 1446 | | throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId"); |
| | 1447 | | } |
| 0 | 1448 | | if (largeFaceListId != null) |
| | 1449 | | { |
| 0 | 1450 | | if (largeFaceListId.Length > 64) |
| | 1451 | | { |
| 0 | 1452 | | throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64); |
| | 1453 | | } |
| 0 | 1454 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$")) |
| | 1455 | | { |
| 0 | 1456 | | throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$"); |
| | 1457 | | } |
| | 1458 | | } |
| | 1459 | | // Tracing |
| 0 | 1460 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1461 | | string _invocationId = null; |
| 0 | 1462 | | if (_shouldTrace) |
| | 1463 | | { |
| 0 | 1464 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1465 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1466 | | tracingParameters.Add("largeFaceListId", largeFaceListId); |
| 0 | 1467 | | tracingParameters.Add("persistedFaceId", persistedFaceId); |
| 0 | 1468 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1469 | | ServiceClientTracing.Enter(_invocationId, this, "GetFace", tracingParameters); |
| | 1470 | | } |
| | 1471 | | // Construct URL |
| 0 | 1472 | | var _baseUrl = Client.BaseUri; |
| 0 | 1473 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/persistedfaces |
| 0 | 1474 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1475 | | _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId)); |
| 0 | 1476 | | _url = _url.Replace("{persistedFaceId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Seri |
| | 1477 | | // Create HTTP transport objects |
| 0 | 1478 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1479 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1480 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 1481 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1482 | | // Set Headers |
| | 1483 | |
|
| | 1484 | |
|
| 0 | 1485 | | if (customHeaders != null) |
| | 1486 | | { |
| 0 | 1487 | | foreach(var _header in customHeaders) |
| | 1488 | | { |
| 0 | 1489 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1490 | | { |
| 0 | 1491 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1492 | | } |
| 0 | 1493 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1494 | | } |
| | 1495 | | } |
| | 1496 | |
|
| | 1497 | | // Serialize Request |
| 0 | 1498 | | string _requestContent = null; |
| | 1499 | | // Set Credentials |
| 0 | 1500 | | if (Client.Credentials != null) |
| | 1501 | | { |
| 0 | 1502 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1503 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1504 | | } |
| | 1505 | | // Send Request |
| 0 | 1506 | | if (_shouldTrace) |
| | 1507 | | { |
| 0 | 1508 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1509 | | } |
| 0 | 1510 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1511 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1512 | | if (_shouldTrace) |
| | 1513 | | { |
| 0 | 1514 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1515 | | } |
| 0 | 1516 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1517 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1518 | | string _responseContent = null; |
| 0 | 1519 | | if ((int)_statusCode != 200) |
| | 1520 | | { |
| 0 | 1521 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1522 | | try |
| | 1523 | | { |
| 0 | 1524 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1525 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1526 | | if (_errorBody != null) |
| | 1527 | | { |
| 0 | 1528 | | ex.Body = _errorBody; |
| | 1529 | | } |
| 0 | 1530 | | } |
| 0 | 1531 | | catch (JsonException) |
| | 1532 | | { |
| | 1533 | | // Ignore the exception |
| 0 | 1534 | | } |
| 0 | 1535 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1536 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1537 | | if (_shouldTrace) |
| | 1538 | | { |
| 0 | 1539 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1540 | | } |
| 0 | 1541 | | _httpRequest.Dispose(); |
| 0 | 1542 | | if (_httpResponse != null) |
| | 1543 | | { |
| 0 | 1544 | | _httpResponse.Dispose(); |
| | 1545 | | } |
| 0 | 1546 | | throw ex; |
| | 1547 | | } |
| | 1548 | | // Create Result |
| 0 | 1549 | | var _result = new HttpOperationResponse<PersistedFace>(); |
| 0 | 1550 | | _result.Request = _httpRequest; |
| 0 | 1551 | | _result.Response = _httpResponse; |
| | 1552 | | // Deserialize Response |
| 0 | 1553 | | if ((int)_statusCode == 200) |
| | 1554 | | { |
| 0 | 1555 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1556 | | try |
| | 1557 | | { |
| 0 | 1558 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent, |
| 0 | 1559 | | } |
| 0 | 1560 | | catch (JsonException ex) |
| | 1561 | | { |
| 0 | 1562 | | _httpRequest.Dispose(); |
| 0 | 1563 | | if (_httpResponse != null) |
| | 1564 | | { |
| 0 | 1565 | | _httpResponse.Dispose(); |
| | 1566 | | } |
| 0 | 1567 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1568 | | } |
| | 1569 | | } |
| 0 | 1570 | | if (_shouldTrace) |
| | 1571 | | { |
| 0 | 1572 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1573 | | } |
| 0 | 1574 | | return _result; |
| 0 | 1575 | | } |
| | 1576 | |
|
| | 1577 | | /// <summary> |
| | 1578 | | /// Update a persisted face's userData field. |
| | 1579 | | /// </summary> |
| | 1580 | | /// <param name='largeFaceListId'> |
| | 1581 | | /// Id referencing a particular large face list. |
| | 1582 | | /// </param> |
| | 1583 | | /// <param name='persistedFaceId'> |
| | 1584 | | /// Id referencing a particular persistedFaceId of an existing face. |
| | 1585 | | /// </param> |
| | 1586 | | /// <param name='userData'> |
| | 1587 | | /// User-provided data attached to the face. The size limit is 1KB. |
| | 1588 | | /// </param> |
| | 1589 | | /// <param name='customHeaders'> |
| | 1590 | | /// Headers that will be added to request. |
| | 1591 | | /// </param> |
| | 1592 | | /// <param name='cancellationToken'> |
| | 1593 | | /// The cancellation token. |
| | 1594 | | /// </param> |
| | 1595 | | /// <exception cref="APIErrorException"> |
| | 1596 | | /// Thrown when the operation returned an invalid status code |
| | 1597 | | /// </exception> |
| | 1598 | | /// <exception cref="ValidationException"> |
| | 1599 | | /// Thrown when a required parameter is null |
| | 1600 | | /// </exception> |
| | 1601 | | /// <exception cref="System.ArgumentNullException"> |
| | 1602 | | /// Thrown when a required parameter is null |
| | 1603 | | /// </exception> |
| | 1604 | | /// <return> |
| | 1605 | | /// A response object containing the response body and response headers. |
| | 1606 | | /// </return> |
| | 1607 | | public async Task<HttpOperationResponse> UpdateFaceWithHttpMessagesAsync(string largeFaceListId, System.Guid per |
| | 1608 | | { |
| 0 | 1609 | | if (Client.Endpoint == null) |
| | 1610 | | { |
| 0 | 1611 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1612 | | } |
| 0 | 1613 | | if (largeFaceListId == null) |
| | 1614 | | { |
| 0 | 1615 | | throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId"); |
| | 1616 | | } |
| 0 | 1617 | | if (largeFaceListId != null) |
| | 1618 | | { |
| 0 | 1619 | | if (largeFaceListId.Length > 64) |
| | 1620 | | { |
| 0 | 1621 | | throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64); |
| | 1622 | | } |
| 0 | 1623 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$")) |
| | 1624 | | { |
| 0 | 1625 | | throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$"); |
| | 1626 | | } |
| | 1627 | | } |
| 0 | 1628 | | if (userData != null) |
| | 1629 | | { |
| 0 | 1630 | | if (userData.Length > 1024) |
| | 1631 | | { |
| 0 | 1632 | | throw new ValidationException(ValidationRules.MaxLength, "userData", 1024); |
| | 1633 | | } |
| | 1634 | | } |
| 0 | 1635 | | UpdateFaceRequest body = new UpdateFaceRequest(); |
| 0 | 1636 | | if (userData != null) |
| | 1637 | | { |
| 0 | 1638 | | body.UserData = userData; |
| | 1639 | | } |
| | 1640 | | // Tracing |
| 0 | 1641 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1642 | | string _invocationId = null; |
| 0 | 1643 | | if (_shouldTrace) |
| | 1644 | | { |
| 0 | 1645 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1646 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1647 | | tracingParameters.Add("largeFaceListId", largeFaceListId); |
| 0 | 1648 | | tracingParameters.Add("persistedFaceId", persistedFaceId); |
| 0 | 1649 | | tracingParameters.Add("body", body); |
| 0 | 1650 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1651 | | ServiceClientTracing.Enter(_invocationId, this, "UpdateFace", tracingParameters); |
| | 1652 | | } |
| | 1653 | | // Construct URL |
| 0 | 1654 | | var _baseUrl = Client.BaseUri; |
| 0 | 1655 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/persistedfaces |
| 0 | 1656 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1657 | | _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId)); |
| 0 | 1658 | | _url = _url.Replace("{persistedFaceId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Seri |
| | 1659 | | // Create HTTP transport objects |
| 0 | 1660 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1661 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1662 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 0 | 1663 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1664 | | // Set Headers |
| | 1665 | |
|
| | 1666 | |
|
| 0 | 1667 | | if (customHeaders != null) |
| | 1668 | | { |
| 0 | 1669 | | foreach(var _header in customHeaders) |
| | 1670 | | { |
| 0 | 1671 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1672 | | { |
| 0 | 1673 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1674 | | } |
| 0 | 1675 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1676 | | } |
| | 1677 | | } |
| | 1678 | |
|
| | 1679 | | // Serialize Request |
| 0 | 1680 | | string _requestContent = null; |
| 0 | 1681 | | if(body != null) |
| | 1682 | | { |
| 0 | 1683 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings) |
| 0 | 1684 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1685 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1686 | | } |
| | 1687 | | // Set Credentials |
| 0 | 1688 | | if (Client.Credentials != null) |
| | 1689 | | { |
| 0 | 1690 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1691 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1692 | | } |
| | 1693 | | // Send Request |
| 0 | 1694 | | if (_shouldTrace) |
| | 1695 | | { |
| 0 | 1696 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1697 | | } |
| 0 | 1698 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1699 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1700 | | if (_shouldTrace) |
| | 1701 | | { |
| 0 | 1702 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1703 | | } |
| 0 | 1704 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1705 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1706 | | string _responseContent = null; |
| 0 | 1707 | | if ((int)_statusCode != 200) |
| | 1708 | | { |
| 0 | 1709 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1710 | | try |
| | 1711 | | { |
| 0 | 1712 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1713 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1714 | | if (_errorBody != null) |
| | 1715 | | { |
| 0 | 1716 | | ex.Body = _errorBody; |
| | 1717 | | } |
| 0 | 1718 | | } |
| 0 | 1719 | | catch (JsonException) |
| | 1720 | | { |
| | 1721 | | // Ignore the exception |
| 0 | 1722 | | } |
| 0 | 1723 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1724 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1725 | | if (_shouldTrace) |
| | 1726 | | { |
| 0 | 1727 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1728 | | } |
| 0 | 1729 | | _httpRequest.Dispose(); |
| 0 | 1730 | | if (_httpResponse != null) |
| | 1731 | | { |
| 0 | 1732 | | _httpResponse.Dispose(); |
| | 1733 | | } |
| 0 | 1734 | | throw ex; |
| | 1735 | | } |
| | 1736 | | // Create Result |
| 0 | 1737 | | var _result = new HttpOperationResponse(); |
| 0 | 1738 | | _result.Request = _httpRequest; |
| 0 | 1739 | | _result.Response = _httpResponse; |
| 0 | 1740 | | if (_shouldTrace) |
| | 1741 | | { |
| 0 | 1742 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1743 | | } |
| 0 | 1744 | | return _result; |
| 0 | 1745 | | } |
| | 1746 | |
|
| | 1747 | | /// <summary> |
| | 1748 | | /// Add a face to a specified large face list, up to 1,000,000 faces. |
| | 1749 | | /// <br /> To deal with an image contains multiple faces, input face can |
| | 1750 | | /// be specified as an image with a targetFace rectangle. It returns a |
| | 1751 | | /// persistedFaceId representing the added face. No image will be stored. Only |
| | 1752 | | /// the extracted face feature will be stored on server until [LargeFaceList |
| | 1753 | | /// Face - |
| | 1754 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/5a158c8ad2de3616c086f2d4) |
| | 1755 | | /// or [LargeFaceList - |
| | 1756 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/5a1580d5d2de3616c086f2cd) |
| | 1757 | | /// is called. |
| | 1758 | | /// <br /> Note persistedFaceId is different from faceId generated by |
| | 1759 | | /// [Face - |
| | 1760 | | /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236). |
| | 1761 | | /// * Higher face image quality means better recognition precision. Please |
| | 1762 | | /// consider high-quality faces: frontal, clear, and face size is 200x200 |
| | 1763 | | /// pixels (100 pixels between eyes) or bigger. |
| | 1764 | | /// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The |
| | 1765 | | /// allowed image file size is from 1KB to 6MB. |
| | 1766 | | /// * "targetFace" rectangle should contain one face. Zero or multiple faces |
| | 1767 | | /// will be regarded as an error. If the provided "targetFace" rectangle is not |
| | 1768 | | /// returned from [Face - |
| | 1769 | | /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236), |
| | 1770 | | /// there’s no guarantee to detect and add the face successfully. |
| | 1771 | | /// * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose, |
| | 1772 | | /// or large occlusions will cause failures. |
| | 1773 | | /// * Adding/deleting faces to/from a same face list are processed sequentially |
| | 1774 | | /// and to/from different face lists are in parallel. |
| | 1775 | | /// * The minimum detectable face size is 36x36 pixels in an image no larger |
| | 1776 | | /// than 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels |
| | 1777 | | /// will need a proportionally larger minimum face size. |
| | 1778 | | /// * Different 'detectionModel' values can be provided. To use and compare |
| | 1779 | | /// different detection models, please refer to [How to specify a detection |
| | 1780 | | /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detecti |
| | 1781 | | /// | Model | Recommended use-case(s) | |
| | 1782 | | /// | ---------- | -------- | |
| | 1783 | | /// | 'detection_01': | The default detection model for [LargeFaceList - Add |
| | 1784 | | /// Face](/docs/services/563879b61984550e40cbbe8d/operations/5a158c10d2de3616c086f2d3). |
| | 1785 | | /// Recommend for near frontal face detection. For scenarios with exceptionally |
| | 1786 | | /// large angle (head-pose) faces, occluded faces or wrong image orientation, |
| | 1787 | | /// the faces in such cases may not be detected. | |
| | 1788 | | /// | 'detection_02': | Detection model released in 2019 May with improved |
| | 1789 | | /// accuracy especially on small, side and blurry faces. | |
| | 1790 | | /// |
| | 1791 | | /// Quota: |
| | 1792 | | /// * Free-tier subscription quota: 1,000 faces per large face list. |
| | 1793 | | /// * S0-tier subscription quota: 1,000,000 faces per large face list. |
| | 1794 | | /// </summary> |
| | 1795 | | /// <param name='largeFaceListId'> |
| | 1796 | | /// Id referencing a particular large face list. |
| | 1797 | | /// </param> |
| | 1798 | | /// <param name='url'> |
| | 1799 | | /// Publicly reachable URL of an image |
| | 1800 | | /// </param> |
| | 1801 | | /// <param name='userData'> |
| | 1802 | | /// User-specified data about the face for any purpose. The maximum length is |
| | 1803 | | /// 1KB. |
| | 1804 | | /// </param> |
| | 1805 | | /// <param name='targetFace'> |
| | 1806 | | /// A face rectangle to specify the target face to be added to a person in the |
| | 1807 | | /// format of "targetFace=left,top,width,height". E.g. |
| | 1808 | | /// "targetFace=10,10,100,100". If there is more than one face in the image, |
| | 1809 | | /// targetFace is required to specify which face to add. No targetFace means |
| | 1810 | | /// there is only one face detected in the entire image. |
| | 1811 | | /// </param> |
| | 1812 | | /// <param name='detectionModel'> |
| | 1813 | | /// Name of detection model. Detection model is used to detect faces in the |
| | 1814 | | /// submitted image. A detection model name can be provided when performing |
| | 1815 | | /// Face - Detect or (Large)FaceList - Add Face or (Large)PersonGroup - Add |
| | 1816 | | /// Face. The default value is 'detection_01', if another model is needed, |
| | 1817 | | /// please explicitly specify it. Possible values include: 'detection_01', |
| | 1818 | | /// 'detection_02' |
| | 1819 | | /// </param> |
| | 1820 | | /// <param name='customHeaders'> |
| | 1821 | | /// Headers that will be added to request. |
| | 1822 | | /// </param> |
| | 1823 | | /// <param name='cancellationToken'> |
| | 1824 | | /// The cancellation token. |
| | 1825 | | /// </param> |
| | 1826 | | /// <exception cref="APIErrorException"> |
| | 1827 | | /// Thrown when the operation returned an invalid status code |
| | 1828 | | /// </exception> |
| | 1829 | | /// <exception cref="SerializationException"> |
| | 1830 | | /// Thrown when unable to deserialize the response |
| | 1831 | | /// </exception> |
| | 1832 | | /// <exception cref="ValidationException"> |
| | 1833 | | /// Thrown when a required parameter is null |
| | 1834 | | /// </exception> |
| | 1835 | | /// <exception cref="System.ArgumentNullException"> |
| | 1836 | | /// Thrown when a required parameter is null |
| | 1837 | | /// </exception> |
| | 1838 | | /// <return> |
| | 1839 | | /// A response object containing the response body and response headers. |
| | 1840 | | /// </return> |
| | 1841 | | public async Task<HttpOperationResponse<PersistedFace>> AddFaceFromUrlWithHttpMessagesAsync(string largeFaceList |
| | 1842 | | { |
| 0 | 1843 | | if (Client.Endpoint == null) |
| | 1844 | | { |
| 0 | 1845 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1846 | | } |
| 0 | 1847 | | if (largeFaceListId == null) |
| | 1848 | | { |
| 0 | 1849 | | throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId"); |
| | 1850 | | } |
| 0 | 1851 | | if (largeFaceListId != null) |
| | 1852 | | { |
| 0 | 1853 | | if (largeFaceListId.Length > 64) |
| | 1854 | | { |
| 0 | 1855 | | throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64); |
| | 1856 | | } |
| 0 | 1857 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$")) |
| | 1858 | | { |
| 0 | 1859 | | throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$"); |
| | 1860 | | } |
| | 1861 | | } |
| 0 | 1862 | | if (userData != null) |
| | 1863 | | { |
| 0 | 1864 | | if (userData.Length > 1024) |
| | 1865 | | { |
| 0 | 1866 | | throw new ValidationException(ValidationRules.MaxLength, "userData", 1024); |
| | 1867 | | } |
| | 1868 | | } |
| 0 | 1869 | | if (url == null) |
| | 1870 | | { |
| 0 | 1871 | | throw new ValidationException(ValidationRules.CannotBeNull, "url"); |
| | 1872 | | } |
| 0 | 1873 | | ImageUrl imageUrl = new ImageUrl(); |
| 0 | 1874 | | if (url != null) |
| | 1875 | | { |
| 0 | 1876 | | imageUrl.Url = url; |
| | 1877 | | } |
| | 1878 | | // Tracing |
| 0 | 1879 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1880 | | string _invocationId = null; |
| 0 | 1881 | | if (_shouldTrace) |
| | 1882 | | { |
| 0 | 1883 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1884 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1885 | | tracingParameters.Add("largeFaceListId", largeFaceListId); |
| 0 | 1886 | | tracingParameters.Add("userData", userData); |
| 0 | 1887 | | tracingParameters.Add("targetFace", targetFace); |
| 0 | 1888 | | tracingParameters.Add("detectionModel", detectionModel); |
| 0 | 1889 | | tracingParameters.Add("imageUrl", imageUrl); |
| 0 | 1890 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1891 | | ServiceClientTracing.Enter(_invocationId, this, "AddFaceFromUrl", tracingParameters); |
| | 1892 | | } |
| | 1893 | | // Construct URL |
| 0 | 1894 | | var _baseUrl = Client.BaseUri; |
| 0 | 1895 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/persistedfaces |
| 0 | 1896 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1897 | | _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId)); |
| 0 | 1898 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1899 | | if (userData != null) |
| | 1900 | | { |
| 0 | 1901 | | _queryParameters.Add(string.Format("userData={0}", System.Uri.EscapeDataString(userData))); |
| | 1902 | | } |
| 0 | 1903 | | if (targetFace != null) |
| | 1904 | | { |
| 0 | 1905 | | _queryParameters.Add(string.Format("targetFace={0}", System.Uri.EscapeDataString(string.Join(",", target |
| | 1906 | | } |
| 0 | 1907 | | if (detectionModel != null) |
| | 1908 | | { |
| 0 | 1909 | | _queryParameters.Add(string.Format("detectionModel={0}", System.Uri.EscapeDataString(detectionModel))); |
| | 1910 | | } |
| 0 | 1911 | | if (_queryParameters.Count > 0) |
| | 1912 | | { |
| 0 | 1913 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1914 | | } |
| | 1915 | | // Create HTTP transport objects |
| 0 | 1916 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1917 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1918 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1919 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1920 | | // Set Headers |
| | 1921 | |
|
| | 1922 | |
|
| 0 | 1923 | | if (customHeaders != null) |
| | 1924 | | { |
| 0 | 1925 | | foreach(var _header in customHeaders) |
| | 1926 | | { |
| 0 | 1927 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1928 | | { |
| 0 | 1929 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1930 | | } |
| 0 | 1931 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1932 | | } |
| | 1933 | | } |
| | 1934 | |
|
| | 1935 | | // Serialize Request |
| 0 | 1936 | | string _requestContent = null; |
| 0 | 1937 | | if(imageUrl != null) |
| | 1938 | | { |
| 0 | 1939 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti |
| 0 | 1940 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1941 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1942 | | } |
| | 1943 | | // Set Credentials |
| 0 | 1944 | | if (Client.Credentials != null) |
| | 1945 | | { |
| 0 | 1946 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1947 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1948 | | } |
| | 1949 | | // Send Request |
| 0 | 1950 | | if (_shouldTrace) |
| | 1951 | | { |
| 0 | 1952 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1953 | | } |
| 0 | 1954 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1955 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1956 | | if (_shouldTrace) |
| | 1957 | | { |
| 0 | 1958 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1959 | | } |
| 0 | 1960 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1961 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1962 | | string _responseContent = null; |
| 0 | 1963 | | if ((int)_statusCode != 200) |
| | 1964 | | { |
| 0 | 1965 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1966 | | try |
| | 1967 | | { |
| 0 | 1968 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1969 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1970 | | if (_errorBody != null) |
| | 1971 | | { |
| 0 | 1972 | | ex.Body = _errorBody; |
| | 1973 | | } |
| 0 | 1974 | | } |
| 0 | 1975 | | catch (JsonException) |
| | 1976 | | { |
| | 1977 | | // Ignore the exception |
| 0 | 1978 | | } |
| 0 | 1979 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1980 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1981 | | if (_shouldTrace) |
| | 1982 | | { |
| 0 | 1983 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1984 | | } |
| 0 | 1985 | | _httpRequest.Dispose(); |
| 0 | 1986 | | if (_httpResponse != null) |
| | 1987 | | { |
| 0 | 1988 | | _httpResponse.Dispose(); |
| | 1989 | | } |
| 0 | 1990 | | throw ex; |
| | 1991 | | } |
| | 1992 | | // Create Result |
| 0 | 1993 | | var _result = new HttpOperationResponse<PersistedFace>(); |
| 0 | 1994 | | _result.Request = _httpRequest; |
| 0 | 1995 | | _result.Response = _httpResponse; |
| | 1996 | | // Deserialize Response |
| 0 | 1997 | | if ((int)_statusCode == 200) |
| | 1998 | | { |
| 0 | 1999 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2000 | | try |
| | 2001 | | { |
| 0 | 2002 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent, |
| 0 | 2003 | | } |
| 0 | 2004 | | catch (JsonException ex) |
| | 2005 | | { |
| 0 | 2006 | | _httpRequest.Dispose(); |
| 0 | 2007 | | if (_httpResponse != null) |
| | 2008 | | { |
| 0 | 2009 | | _httpResponse.Dispose(); |
| | 2010 | | } |
| 0 | 2011 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2012 | | } |
| | 2013 | | } |
| 0 | 2014 | | if (_shouldTrace) |
| | 2015 | | { |
| 0 | 2016 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2017 | | } |
| 0 | 2018 | | return _result; |
| 0 | 2019 | | } |
| | 2020 | |
|
| | 2021 | | /// <summary> |
| | 2022 | | /// List all faces in a large face list, and retrieve face information |
| | 2023 | | /// (including userData and persistedFaceIds of registered faces of the face). |
| | 2024 | | /// </summary> |
| | 2025 | | /// <param name='largeFaceListId'> |
| | 2026 | | /// Id referencing a particular large face list. |
| | 2027 | | /// </param> |
| | 2028 | | /// <param name='start'> |
| | 2029 | | /// Starting face id to return (used to list a range of faces). |
| | 2030 | | /// </param> |
| | 2031 | | /// <param name='top'> |
| | 2032 | | /// Number of faces to return starting with the face id indicated by the |
| | 2033 | | /// 'start' parameter. |
| | 2034 | | /// </param> |
| | 2035 | | /// <param name='customHeaders'> |
| | 2036 | | /// Headers that will be added to request. |
| | 2037 | | /// </param> |
| | 2038 | | /// <param name='cancellationToken'> |
| | 2039 | | /// The cancellation token. |
| | 2040 | | /// </param> |
| | 2041 | | /// <exception cref="APIErrorException"> |
| | 2042 | | /// Thrown when the operation returned an invalid status code |
| | 2043 | | /// </exception> |
| | 2044 | | /// <exception cref="SerializationException"> |
| | 2045 | | /// Thrown when unable to deserialize the response |
| | 2046 | | /// </exception> |
| | 2047 | | /// <exception cref="ValidationException"> |
| | 2048 | | /// Thrown when a required parameter is null |
| | 2049 | | /// </exception> |
| | 2050 | | /// <exception cref="System.ArgumentNullException"> |
| | 2051 | | /// Thrown when a required parameter is null |
| | 2052 | | /// </exception> |
| | 2053 | | /// <return> |
| | 2054 | | /// A response object containing the response body and response headers. |
| | 2055 | | /// </return> |
| | 2056 | | public async Task<HttpOperationResponse<IList<PersistedFace>>> ListFacesWithHttpMessagesAsync(string largeFaceLi |
| | 2057 | | { |
| 2 | 2058 | | if (Client.Endpoint == null) |
| | 2059 | | { |
| 0 | 2060 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 2061 | | } |
| 2 | 2062 | | if (largeFaceListId == null) |
| | 2063 | | { |
| 0 | 2064 | | throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId"); |
| | 2065 | | } |
| 2 | 2066 | | if (largeFaceListId != null) |
| | 2067 | | { |
| 2 | 2068 | | if (largeFaceListId.Length > 64) |
| | 2069 | | { |
| 0 | 2070 | | throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64); |
| | 2071 | | } |
| 2 | 2072 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$")) |
| | 2073 | | { |
| 0 | 2074 | | throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$"); |
| | 2075 | | } |
| | 2076 | | } |
| 2 | 2077 | | if (top > 1000) |
| | 2078 | | { |
| 0 | 2079 | | throw new ValidationException(ValidationRules.InclusiveMaximum, "top", 1000); |
| | 2080 | | } |
| 2 | 2081 | | if (top < 1) |
| | 2082 | | { |
| 0 | 2083 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "top", 1); |
| | 2084 | | } |
| | 2085 | | // Tracing |
| 2 | 2086 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 2087 | | string _invocationId = null; |
| 2 | 2088 | | if (_shouldTrace) |
| | 2089 | | { |
| 0 | 2090 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2091 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2092 | | tracingParameters.Add("largeFaceListId", largeFaceListId); |
| 0 | 2093 | | tracingParameters.Add("start", start); |
| 0 | 2094 | | tracingParameters.Add("top", top); |
| 0 | 2095 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2096 | | ServiceClientTracing.Enter(_invocationId, this, "ListFaces", tracingParameters); |
| | 2097 | | } |
| | 2098 | | // Construct URL |
| 2 | 2099 | | var _baseUrl = Client.BaseUri; |
| 2 | 2100 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/persistedfaces |
| 2 | 2101 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 2 | 2102 | | _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId)); |
| 2 | 2103 | | List<string> _queryParameters = new List<string>(); |
| 2 | 2104 | | if (start != null) |
| | 2105 | | { |
| 0 | 2106 | | _queryParameters.Add(string.Format("start={0}", System.Uri.EscapeDataString(start))); |
| | 2107 | | } |
| 2 | 2108 | | if (top != null) |
| | 2109 | | { |
| 0 | 2110 | | _queryParameters.Add(string.Format("top={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCon |
| | 2111 | | } |
| 2 | 2112 | | if (_queryParameters.Count > 0) |
| | 2113 | | { |
| 0 | 2114 | | _url += "?" + string.Join("&", _queryParameters); |
| | 2115 | | } |
| | 2116 | | // Create HTTP transport objects |
| 2 | 2117 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 2118 | | HttpResponseMessage _httpResponse = null; |
| 2 | 2119 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 2120 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2121 | | // Set Headers |
| | 2122 | |
|
| | 2123 | |
|
| 2 | 2124 | | if (customHeaders != null) |
| | 2125 | | { |
| 0 | 2126 | | foreach(var _header in customHeaders) |
| | 2127 | | { |
| 0 | 2128 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2129 | | { |
| 0 | 2130 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2131 | | } |
| 0 | 2132 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2133 | | } |
| | 2134 | | } |
| | 2135 | |
|
| | 2136 | | // Serialize Request |
| 2 | 2137 | | string _requestContent = null; |
| | 2138 | | // Set Credentials |
| 2 | 2139 | | if (Client.Credentials != null) |
| | 2140 | | { |
| 2 | 2141 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2142 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2143 | | } |
| | 2144 | | // Send Request |
| 2 | 2145 | | if (_shouldTrace) |
| | 2146 | | { |
| 0 | 2147 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2148 | | } |
| 2 | 2149 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2150 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 2151 | | if (_shouldTrace) |
| | 2152 | | { |
| 0 | 2153 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2154 | | } |
| 2 | 2155 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 2156 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2157 | | string _responseContent = null; |
| 2 | 2158 | | if ((int)_statusCode != 200) |
| | 2159 | | { |
| 0 | 2160 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 2161 | | try |
| | 2162 | | { |
| 0 | 2163 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2164 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 2165 | | if (_errorBody != null) |
| | 2166 | | { |
| 0 | 2167 | | ex.Body = _errorBody; |
| | 2168 | | } |
| 0 | 2169 | | } |
| 0 | 2170 | | catch (JsonException) |
| | 2171 | | { |
| | 2172 | | // Ignore the exception |
| 0 | 2173 | | } |
| 0 | 2174 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2175 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2176 | | if (_shouldTrace) |
| | 2177 | | { |
| 0 | 2178 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2179 | | } |
| 0 | 2180 | | _httpRequest.Dispose(); |
| 0 | 2181 | | if (_httpResponse != null) |
| | 2182 | | { |
| 0 | 2183 | | _httpResponse.Dispose(); |
| | 2184 | | } |
| 0 | 2185 | | throw ex; |
| | 2186 | | } |
| | 2187 | | // Create Result |
| 2 | 2188 | | var _result = new HttpOperationResponse<IList<PersistedFace>>(); |
| 2 | 2189 | | _result.Request = _httpRequest; |
| 2 | 2190 | | _result.Response = _httpResponse; |
| | 2191 | | // Deserialize Response |
| 2 | 2192 | | if ((int)_statusCode == 200) |
| | 2193 | | { |
| 2 | 2194 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2195 | | try |
| | 2196 | | { |
| 2 | 2197 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<PersistedFace>>(_responseC |
| 2 | 2198 | | } |
| 0 | 2199 | | catch (JsonException ex) |
| | 2200 | | { |
| 0 | 2201 | | _httpRequest.Dispose(); |
| 0 | 2202 | | if (_httpResponse != null) |
| | 2203 | | { |
| 0 | 2204 | | _httpResponse.Dispose(); |
| | 2205 | | } |
| 0 | 2206 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2207 | | } |
| | 2208 | | } |
| 2 | 2209 | | if (_shouldTrace) |
| | 2210 | | { |
| 0 | 2211 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2212 | | } |
| 2 | 2213 | | return _result; |
| 2 | 2214 | | } |
| | 2215 | |
|
| | 2216 | | /// <summary> |
| | 2217 | | /// Add a face to a specified large face list, up to 1,000,000 faces. |
| | 2218 | | /// <br /> To deal with an image contains multiple faces, input face can |
| | 2219 | | /// be specified as an image with a targetFace rectangle. It returns a |
| | 2220 | | /// persistedFaceId representing the added face. No image will be stored. Only |
| | 2221 | | /// the extracted face feature will be stored on server until [LargeFaceList |
| | 2222 | | /// Face - |
| | 2223 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/5a158c8ad2de3616c086f2d4) |
| | 2224 | | /// or [LargeFaceList - |
| | 2225 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/5a1580d5d2de3616c086f2cd) |
| | 2226 | | /// is called. |
| | 2227 | | /// <br /> Note persistedFaceId is different from faceId generated by |
| | 2228 | | /// [Face - |
| | 2229 | | /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236). |
| | 2230 | | /// * Higher face image quality means better recognition precision. Please |
| | 2231 | | /// consider high-quality faces: frontal, clear, and face size is 200x200 |
| | 2232 | | /// pixels (100 pixels between eyes) or bigger. |
| | 2233 | | /// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The |
| | 2234 | | /// allowed image file size is from 1KB to 6MB. |
| | 2235 | | /// * "targetFace" rectangle should contain one face. Zero or multiple faces |
| | 2236 | | /// will be regarded as an error. If the provided "targetFace" rectangle is not |
| | 2237 | | /// returned from [Face - |
| | 2238 | | /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236), |
| | 2239 | | /// there’s no guarantee to detect and add the face successfully. |
| | 2240 | | /// * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose, |
| | 2241 | | /// or large occlusions will cause failures. |
| | 2242 | | /// * Adding/deleting faces to/from a same face list are processed sequentially |
| | 2243 | | /// and to/from different face lists are in parallel. |
| | 2244 | | /// * The minimum detectable face size is 36x36 pixels in an image no larger |
| | 2245 | | /// than 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels |
| | 2246 | | /// will need a proportionally larger minimum face size. |
| | 2247 | | /// * Different 'detectionModel' values can be provided. To use and compare |
| | 2248 | | /// different detection models, please refer to [How to specify a detection |
| | 2249 | | /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detecti |
| | 2250 | | /// | Model | Recommended use-case(s) | |
| | 2251 | | /// | ---------- | -------- | |
| | 2252 | | /// | 'detection_01': | The default detection model for [LargeFaceList - Add |
| | 2253 | | /// Face](/docs/services/563879b61984550e40cbbe8d/operations/5a158c10d2de3616c086f2d3). |
| | 2254 | | /// Recommend for near frontal face detection. For scenarios with exceptionally |
| | 2255 | | /// large angle (head-pose) faces, occluded faces or wrong image orientation, |
| | 2256 | | /// the faces in such cases may not be detected. | |
| | 2257 | | /// | 'detection_02': | Detection model released in 2019 May with improved |
| | 2258 | | /// accuracy especially on small, side and blurry faces. | |
| | 2259 | | /// |
| | 2260 | | /// Quota: |
| | 2261 | | /// * Free-tier subscription quota: 1,000 faces per large face list. |
| | 2262 | | /// * S0-tier subscription quota: 1,000,000 faces per large face list. |
| | 2263 | | /// </summary> |
| | 2264 | | /// <param name='largeFaceListId'> |
| | 2265 | | /// Id referencing a particular large face list. |
| | 2266 | | /// </param> |
| | 2267 | | /// <param name='image'> |
| | 2268 | | /// An image stream. |
| | 2269 | | /// </param> |
| | 2270 | | /// <param name='userData'> |
| | 2271 | | /// User-specified data about the face for any purpose. The maximum length is |
| | 2272 | | /// 1KB. |
| | 2273 | | /// </param> |
| | 2274 | | /// <param name='targetFace'> |
| | 2275 | | /// A face rectangle to specify the target face to be added to a person in the |
| | 2276 | | /// format of "targetFace=left,top,width,height". E.g. |
| | 2277 | | /// "targetFace=10,10,100,100". If there is more than one face in the image, |
| | 2278 | | /// targetFace is required to specify which face to add. No targetFace means |
| | 2279 | | /// there is only one face detected in the entire image. |
| | 2280 | | /// </param> |
| | 2281 | | /// <param name='detectionModel'> |
| | 2282 | | /// Name of detection model. Detection model is used to detect faces in the |
| | 2283 | | /// submitted image. A detection model name can be provided when performing |
| | 2284 | | /// Face - Detect or (Large)FaceList - Add Face or (Large)PersonGroup - Add |
| | 2285 | | /// Face. The default value is 'detection_01', if another model is needed, |
| | 2286 | | /// please explicitly specify it. Possible values include: 'detection_01', |
| | 2287 | | /// 'detection_02' |
| | 2288 | | /// </param> |
| | 2289 | | /// <param name='customHeaders'> |
| | 2290 | | /// Headers that will be added to request. |
| | 2291 | | /// </param> |
| | 2292 | | /// <param name='cancellationToken'> |
| | 2293 | | /// The cancellation token. |
| | 2294 | | /// </param> |
| | 2295 | | /// <exception cref="APIErrorException"> |
| | 2296 | | /// Thrown when the operation returned an invalid status code |
| | 2297 | | /// </exception> |
| | 2298 | | /// <exception cref="SerializationException"> |
| | 2299 | | /// Thrown when unable to deserialize the response |
| | 2300 | | /// </exception> |
| | 2301 | | /// <exception cref="ValidationException"> |
| | 2302 | | /// Thrown when a required parameter is null |
| | 2303 | | /// </exception> |
| | 2304 | | /// <exception cref="System.ArgumentNullException"> |
| | 2305 | | /// Thrown when a required parameter is null |
| | 2306 | | /// </exception> |
| | 2307 | | /// <return> |
| | 2308 | | /// A response object containing the response body and response headers. |
| | 2309 | | /// </return> |
| | 2310 | | public async Task<HttpOperationResponse<PersistedFace>> AddFaceFromStreamWithHttpMessagesAsync(string largeFaceL |
| | 2311 | | { |
| 14 | 2312 | | if (Client.Endpoint == null) |
| | 2313 | | { |
| 0 | 2314 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 2315 | | } |
| 14 | 2316 | | if (largeFaceListId == null) |
| | 2317 | | { |
| 0 | 2318 | | throw new ValidationException(ValidationRules.CannotBeNull, "largeFaceListId"); |
| | 2319 | | } |
| 14 | 2320 | | if (largeFaceListId != null) |
| | 2321 | | { |
| 14 | 2322 | | if (largeFaceListId.Length > 64) |
| | 2323 | | { |
| 0 | 2324 | | throw new ValidationException(ValidationRules.MaxLength, "largeFaceListId", 64); |
| | 2325 | | } |
| 14 | 2326 | | if (!System.Text.RegularExpressions.Regex.IsMatch(largeFaceListId, "^[a-z0-9-_]+$")) |
| | 2327 | | { |
| 0 | 2328 | | throw new ValidationException(ValidationRules.Pattern, "largeFaceListId", "^[a-z0-9-_]+$"); |
| | 2329 | | } |
| | 2330 | | } |
| 14 | 2331 | | if (userData != null) |
| | 2332 | | { |
| 0 | 2333 | | if (userData.Length > 1024) |
| | 2334 | | { |
| 0 | 2335 | | throw new ValidationException(ValidationRules.MaxLength, "userData", 1024); |
| | 2336 | | } |
| | 2337 | | } |
| 14 | 2338 | | if (image == null) |
| | 2339 | | { |
| 0 | 2340 | | throw new ValidationException(ValidationRules.CannotBeNull, "image"); |
| | 2341 | | } |
| | 2342 | | // Tracing |
| 14 | 2343 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 14 | 2344 | | string _invocationId = null; |
| 14 | 2345 | | if (_shouldTrace) |
| | 2346 | | { |
| 0 | 2347 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2348 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2349 | | tracingParameters.Add("largeFaceListId", largeFaceListId); |
| 0 | 2350 | | tracingParameters.Add("userData", userData); |
| 0 | 2351 | | tracingParameters.Add("targetFace", targetFace); |
| 0 | 2352 | | tracingParameters.Add("image", image); |
| 0 | 2353 | | tracingParameters.Add("detectionModel", detectionModel); |
| 0 | 2354 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2355 | | ServiceClientTracing.Enter(_invocationId, this, "AddFaceFromStream", tracingParameters); |
| | 2356 | | } |
| | 2357 | | // Construct URL |
| 14 | 2358 | | var _baseUrl = Client.BaseUri; |
| 14 | 2359 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "largefacelists/{largeFaceListId}/persistedfaces |
| 14 | 2360 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 14 | 2361 | | _url = _url.Replace("{largeFaceListId}", System.Uri.EscapeDataString(largeFaceListId)); |
| 14 | 2362 | | List<string> _queryParameters = new List<string>(); |
| 14 | 2363 | | if (userData != null) |
| | 2364 | | { |
| 0 | 2365 | | _queryParameters.Add(string.Format("userData={0}", System.Uri.EscapeDataString(userData))); |
| | 2366 | | } |
| 14 | 2367 | | if (targetFace != null) |
| | 2368 | | { |
| 12 | 2369 | | _queryParameters.Add(string.Format("targetFace={0}", System.Uri.EscapeDataString(string.Join(",", target |
| | 2370 | | } |
| 14 | 2371 | | if (detectionModel != null) |
| | 2372 | | { |
| 14 | 2373 | | _queryParameters.Add(string.Format("detectionModel={0}", System.Uri.EscapeDataString(detectionModel))); |
| | 2374 | | } |
| 14 | 2375 | | if (_queryParameters.Count > 0) |
| | 2376 | | { |
| 14 | 2377 | | _url += "?" + string.Join("&", _queryParameters); |
| | 2378 | | } |
| | 2379 | | // Create HTTP transport objects |
| 14 | 2380 | | var _httpRequest = new HttpRequestMessage(); |
| 14 | 2381 | | HttpResponseMessage _httpResponse = null; |
| 14 | 2382 | | _httpRequest.Method = new HttpMethod("POST"); |
| 14 | 2383 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2384 | | // Set Headers |
| | 2385 | |
|
| | 2386 | |
|
| 14 | 2387 | | if (customHeaders != null) |
| | 2388 | | { |
| 0 | 2389 | | foreach(var _header in customHeaders) |
| | 2390 | | { |
| 0 | 2391 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2392 | | { |
| 0 | 2393 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2394 | | } |
| 0 | 2395 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2396 | | } |
| | 2397 | | } |
| | 2398 | |
|
| | 2399 | | // Serialize Request |
| 14 | 2400 | | string _requestContent = null; |
| 14 | 2401 | | if(image == null) |
| | 2402 | | { |
| 0 | 2403 | | throw new System.ArgumentNullException("image"); |
| | 2404 | | } |
| 14 | 2405 | | if (image != null && image != Stream.Null) |
| | 2406 | | { |
| 14 | 2407 | | _httpRequest.Content = new StreamContent(image); |
| 14 | 2408 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 2409 | | } |
| | 2410 | | // Set Credentials |
| 14 | 2411 | | if (Client.Credentials != null) |
| | 2412 | | { |
| 14 | 2413 | | cancellationToken.ThrowIfCancellationRequested(); |
| 14 | 2414 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2415 | | } |
| | 2416 | | // Send Request |
| 14 | 2417 | | if (_shouldTrace) |
| | 2418 | | { |
| 0 | 2419 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2420 | | } |
| 14 | 2421 | | cancellationToken.ThrowIfCancellationRequested(); |
| 14 | 2422 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 14 | 2423 | | if (_shouldTrace) |
| | 2424 | | { |
| 0 | 2425 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2426 | | } |
| 14 | 2427 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 14 | 2428 | | cancellationToken.ThrowIfCancellationRequested(); |
| 14 | 2429 | | string _responseContent = null; |
| 14 | 2430 | | if ((int)_statusCode != 200) |
| | 2431 | | { |
| 0 | 2432 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 2433 | | try |
| | 2434 | | { |
| 0 | 2435 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2436 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 2437 | | if (_errorBody != null) |
| | 2438 | | { |
| 0 | 2439 | | ex.Body = _errorBody; |
| | 2440 | | } |
| 0 | 2441 | | } |
| 0 | 2442 | | catch (JsonException) |
| | 2443 | | { |
| | 2444 | | // Ignore the exception |
| 0 | 2445 | | } |
| 0 | 2446 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2447 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2448 | | if (_shouldTrace) |
| | 2449 | | { |
| 0 | 2450 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2451 | | } |
| 0 | 2452 | | _httpRequest.Dispose(); |
| 0 | 2453 | | if (_httpResponse != null) |
| | 2454 | | { |
| 0 | 2455 | | _httpResponse.Dispose(); |
| | 2456 | | } |
| 0 | 2457 | | throw ex; |
| | 2458 | | } |
| | 2459 | | // Create Result |
| 14 | 2460 | | var _result = new HttpOperationResponse<PersistedFace>(); |
| 14 | 2461 | | _result.Request = _httpRequest; |
| 14 | 2462 | | _result.Response = _httpResponse; |
| | 2463 | | // Deserialize Response |
| 14 | 2464 | | if ((int)_statusCode == 200) |
| | 2465 | | { |
| 14 | 2466 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2467 | | try |
| | 2468 | | { |
| 14 | 2469 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent, |
| 14 | 2470 | | } |
| 0 | 2471 | | catch (JsonException ex) |
| | 2472 | | { |
| 0 | 2473 | | _httpRequest.Dispose(); |
| 0 | 2474 | | if (_httpResponse != null) |
| | 2475 | | { |
| 0 | 2476 | | _httpResponse.Dispose(); |
| | 2477 | | } |
| 0 | 2478 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2479 | | } |
| | 2480 | | } |
| 14 | 2481 | | if (_shouldTrace) |
| | 2482 | | { |
| 0 | 2483 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2484 | | } |
| 14 | 2485 | | return _result; |
| 14 | 2486 | | } |
| | 2487 | |
|
| | 2488 | | } |
| | 2489 | | } |