| | 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 | | /// PersonGroupPerson operations. |
| | 27 | | /// </summary> |
| | 28 | | public partial class PersonGroupPerson : IServiceOperations<FaceClient>, IPersonGroupPerson |
| | 29 | | { |
| | 30 | | /// <summary> |
| | 31 | | /// Initializes a new instance of the PersonGroupPerson 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 PersonGroupPerson(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> |
| 292 | 51 | | public FaceClient Client { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Create a new person in a specified person group. |
| | 55 | | /// </summary> |
| | 56 | | /// <param name='personGroupId'> |
| | 57 | | /// Id referencing a particular person group. |
| | 58 | | /// </param> |
| | 59 | | /// <param name='name'> |
| | 60 | | /// User defined name, maximum length is 128. |
| | 61 | | /// </param> |
| | 62 | | /// <param name='userData'> |
| | 63 | | /// User specified data. Length should not exceed 16KB. |
| | 64 | | /// </param> |
| | 65 | | /// <param name='customHeaders'> |
| | 66 | | /// Headers that will be added to request. |
| | 67 | | /// </param> |
| | 68 | | /// <param name='cancellationToken'> |
| | 69 | | /// The cancellation token. |
| | 70 | | /// </param> |
| | 71 | | /// <exception cref="APIErrorException"> |
| | 72 | | /// Thrown when the operation returned an invalid status code |
| | 73 | | /// </exception> |
| | 74 | | /// <exception cref="SerializationException"> |
| | 75 | | /// Thrown when unable to deserialize the response |
| | 76 | | /// </exception> |
| | 77 | | /// <exception cref="ValidationException"> |
| | 78 | | /// Thrown when a required parameter is null |
| | 79 | | /// </exception> |
| | 80 | | /// <exception cref="System.ArgumentNullException"> |
| | 81 | | /// Thrown when a required parameter is null |
| | 82 | | /// </exception> |
| | 83 | | /// <return> |
| | 84 | | /// A response object containing the response body and response headers. |
| | 85 | | /// </return> |
| | 86 | | public async Task<HttpOperationResponse<Person>> CreateWithHttpMessagesAsync(string personGroupId, string name = |
| | 87 | | { |
| 10 | 88 | | if (Client.Endpoint == null) |
| | 89 | | { |
| 0 | 90 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 91 | | } |
| 10 | 92 | | if (personGroupId == null) |
| | 93 | | { |
| 0 | 94 | | throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId"); |
| | 95 | | } |
| 10 | 96 | | if (personGroupId != null) |
| | 97 | | { |
| 10 | 98 | | if (personGroupId.Length > 64) |
| | 99 | | { |
| 0 | 100 | | throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64); |
| | 101 | | } |
| 10 | 102 | | if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$")) |
| | 103 | | { |
| 0 | 104 | | throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$"); |
| | 105 | | } |
| | 106 | | } |
| 10 | 107 | | if (name != null) |
| | 108 | | { |
| 10 | 109 | | if (name.Length > 128) |
| | 110 | | { |
| 0 | 111 | | throw new ValidationException(ValidationRules.MaxLength, "name", 128); |
| | 112 | | } |
| | 113 | | } |
| 10 | 114 | | if (userData != null) |
| | 115 | | { |
| 2 | 116 | | if (userData.Length > 16384) |
| | 117 | | { |
| 0 | 118 | | throw new ValidationException(ValidationRules.MaxLength, "userData", 16384); |
| | 119 | | } |
| | 120 | | } |
| 10 | 121 | | NameAndUserDataContract body = new NameAndUserDataContract(); |
| 10 | 122 | | if (name != null || userData != null) |
| | 123 | | { |
| 10 | 124 | | body.Name = name; |
| 10 | 125 | | body.UserData = userData; |
| | 126 | | } |
| | 127 | | // Tracing |
| 10 | 128 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 10 | 129 | | string _invocationId = null; |
| 10 | 130 | | if (_shouldTrace) |
| | 131 | | { |
| 0 | 132 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 133 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 134 | | tracingParameters.Add("personGroupId", personGroupId); |
| 0 | 135 | | tracingParameters.Add("body", body); |
| 0 | 136 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 137 | | ServiceClientTracing.Enter(_invocationId, this, "Create", tracingParameters); |
| | 138 | | } |
| | 139 | | // Construct URL |
| 10 | 140 | | var _baseUrl = Client.BaseUri; |
| 10 | 141 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/persons"; |
| 10 | 142 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 10 | 143 | | _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId)); |
| | 144 | | // Create HTTP transport objects |
| 10 | 145 | | var _httpRequest = new HttpRequestMessage(); |
| 10 | 146 | | HttpResponseMessage _httpResponse = null; |
| 10 | 147 | | _httpRequest.Method = new HttpMethod("POST"); |
| 10 | 148 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 149 | | // Set Headers |
| | 150 | |
|
| | 151 | |
|
| 10 | 152 | | if (customHeaders != null) |
| | 153 | | { |
| 0 | 154 | | foreach(var _header in customHeaders) |
| | 155 | | { |
| 0 | 156 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 157 | | { |
| 0 | 158 | | _httpRequest.Headers.Remove(_header.Key); |
| | 159 | | } |
| 0 | 160 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 161 | | } |
| | 162 | | } |
| | 163 | |
|
| | 164 | | // Serialize Request |
| 10 | 165 | | string _requestContent = null; |
| 10 | 166 | | if(body != null) |
| | 167 | | { |
| 10 | 168 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings) |
| 10 | 169 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 10 | 170 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 171 | | } |
| | 172 | | // Set Credentials |
| 10 | 173 | | if (Client.Credentials != null) |
| | 174 | | { |
| 10 | 175 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 176 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 177 | | } |
| | 178 | | // Send Request |
| 10 | 179 | | if (_shouldTrace) |
| | 180 | | { |
| 0 | 181 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 182 | | } |
| 10 | 183 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 184 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 10 | 185 | | if (_shouldTrace) |
| | 186 | | { |
| 0 | 187 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 188 | | } |
| 10 | 189 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 10 | 190 | | cancellationToken.ThrowIfCancellationRequested(); |
| 10 | 191 | | string _responseContent = null; |
| 10 | 192 | | if ((int)_statusCode != 200) |
| | 193 | | { |
| 0 | 194 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 195 | | try |
| | 196 | | { |
| 0 | 197 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 198 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 199 | | if (_errorBody != null) |
| | 200 | | { |
| 0 | 201 | | ex.Body = _errorBody; |
| | 202 | | } |
| 0 | 203 | | } |
| 0 | 204 | | catch (JsonException) |
| | 205 | | { |
| | 206 | | // Ignore the exception |
| 0 | 207 | | } |
| 0 | 208 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 209 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 210 | | if (_shouldTrace) |
| | 211 | | { |
| 0 | 212 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 213 | | } |
| 0 | 214 | | _httpRequest.Dispose(); |
| 0 | 215 | | if (_httpResponse != null) |
| | 216 | | { |
| 0 | 217 | | _httpResponse.Dispose(); |
| | 218 | | } |
| 0 | 219 | | throw ex; |
| | 220 | | } |
| | 221 | | // Create Result |
| 10 | 222 | | var _result = new HttpOperationResponse<Person>(); |
| 10 | 223 | | _result.Request = _httpRequest; |
| 10 | 224 | | _result.Response = _httpResponse; |
| | 225 | | // Deserialize Response |
| 10 | 226 | | if ((int)_statusCode == 200) |
| | 227 | | { |
| 10 | 228 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 229 | | try |
| | 230 | | { |
| 10 | 231 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Person>(_responseContent, Client |
| 10 | 232 | | } |
| 0 | 233 | | catch (JsonException ex) |
| | 234 | | { |
| 0 | 235 | | _httpRequest.Dispose(); |
| 0 | 236 | | if (_httpResponse != null) |
| | 237 | | { |
| 0 | 238 | | _httpResponse.Dispose(); |
| | 239 | | } |
| 0 | 240 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 241 | | } |
| | 242 | | } |
| 10 | 243 | | if (_shouldTrace) |
| | 244 | | { |
| 0 | 245 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 246 | | } |
| 10 | 247 | | return _result; |
| 10 | 248 | | } |
| | 249 | |
|
| | 250 | | /// <summary> |
| | 251 | | /// List all persons in a person group, and retrieve person information |
| | 252 | | /// (including personId, name, userData and persistedFaceIds of registered |
| | 253 | | /// faces of the person). |
| | 254 | | /// </summary> |
| | 255 | | /// <param name='personGroupId'> |
| | 256 | | /// Id referencing a particular person group. |
| | 257 | | /// </param> |
| | 258 | | /// <param name='start'> |
| | 259 | | /// Starting person id to return (used to list a range of persons). |
| | 260 | | /// </param> |
| | 261 | | /// <param name='top'> |
| | 262 | | /// Number of persons to return starting with the person id indicated by the |
| | 263 | | /// 'start' parameter. |
| | 264 | | /// </param> |
| | 265 | | /// <param name='customHeaders'> |
| | 266 | | /// Headers that will be added to request. |
| | 267 | | /// </param> |
| | 268 | | /// <param name='cancellationToken'> |
| | 269 | | /// The cancellation token. |
| | 270 | | /// </param> |
| | 271 | | /// <exception cref="APIErrorException"> |
| | 272 | | /// Thrown when the operation returned an invalid status code |
| | 273 | | /// </exception> |
| | 274 | | /// <exception cref="SerializationException"> |
| | 275 | | /// Thrown when unable to deserialize the response |
| | 276 | | /// </exception> |
| | 277 | | /// <exception cref="ValidationException"> |
| | 278 | | /// Thrown when a required parameter is null |
| | 279 | | /// </exception> |
| | 280 | | /// <exception cref="System.ArgumentNullException"> |
| | 281 | | /// Thrown when a required parameter is null |
| | 282 | | /// </exception> |
| | 283 | | /// <return> |
| | 284 | | /// A response object containing the response body and response headers. |
| | 285 | | /// </return> |
| | 286 | | public async Task<HttpOperationResponse<IList<Person>>> ListWithHttpMessagesAsync(string personGroupId, string s |
| | 287 | | { |
| 0 | 288 | | if (Client.Endpoint == null) |
| | 289 | | { |
| 0 | 290 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 291 | | } |
| 0 | 292 | | if (personGroupId == null) |
| | 293 | | { |
| 0 | 294 | | throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId"); |
| | 295 | | } |
| 0 | 296 | | if (personGroupId != null) |
| | 297 | | { |
| 0 | 298 | | if (personGroupId.Length > 64) |
| | 299 | | { |
| 0 | 300 | | throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64); |
| | 301 | | } |
| 0 | 302 | | if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$")) |
| | 303 | | { |
| 0 | 304 | | throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$"); |
| | 305 | | } |
| | 306 | | } |
| 0 | 307 | | if (top > 1000) |
| | 308 | | { |
| 0 | 309 | | throw new ValidationException(ValidationRules.InclusiveMaximum, "top", 1000); |
| | 310 | | } |
| 0 | 311 | | if (top < 1) |
| | 312 | | { |
| 0 | 313 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "top", 1); |
| | 314 | | } |
| | 315 | | // Tracing |
| 0 | 316 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 317 | | string _invocationId = null; |
| 0 | 318 | | if (_shouldTrace) |
| | 319 | | { |
| 0 | 320 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 321 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 322 | | tracingParameters.Add("personGroupId", personGroupId); |
| 0 | 323 | | tracingParameters.Add("start", start); |
| 0 | 324 | | tracingParameters.Add("top", top); |
| 0 | 325 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 326 | | ServiceClientTracing.Enter(_invocationId, this, "List", tracingParameters); |
| | 327 | | } |
| | 328 | | // Construct URL |
| 0 | 329 | | var _baseUrl = Client.BaseUri; |
| 0 | 330 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/persons"; |
| 0 | 331 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 332 | | _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId)); |
| 0 | 333 | | List<string> _queryParameters = new List<string>(); |
| 0 | 334 | | if (start != null) |
| | 335 | | { |
| 0 | 336 | | _queryParameters.Add(string.Format("start={0}", System.Uri.EscapeDataString(start))); |
| | 337 | | } |
| 0 | 338 | | if (top != null) |
| | 339 | | { |
| 0 | 340 | | _queryParameters.Add(string.Format("top={0}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonCon |
| | 341 | | } |
| 0 | 342 | | if (_queryParameters.Count > 0) |
| | 343 | | { |
| 0 | 344 | | _url += "?" + string.Join("&", _queryParameters); |
| | 345 | | } |
| | 346 | | // Create HTTP transport objects |
| 0 | 347 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 348 | | HttpResponseMessage _httpResponse = null; |
| 0 | 349 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 350 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 351 | | // Set Headers |
| | 352 | |
|
| | 353 | |
|
| 0 | 354 | | if (customHeaders != null) |
| | 355 | | { |
| 0 | 356 | | foreach(var _header in customHeaders) |
| | 357 | | { |
| 0 | 358 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 359 | | { |
| 0 | 360 | | _httpRequest.Headers.Remove(_header.Key); |
| | 361 | | } |
| 0 | 362 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 363 | | } |
| | 364 | | } |
| | 365 | |
|
| | 366 | | // Serialize Request |
| 0 | 367 | | string _requestContent = null; |
| | 368 | | // Set Credentials |
| 0 | 369 | | if (Client.Credentials != null) |
| | 370 | | { |
| 0 | 371 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 372 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 373 | | } |
| | 374 | | // Send Request |
| 0 | 375 | | if (_shouldTrace) |
| | 376 | | { |
| 0 | 377 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 378 | | } |
| 0 | 379 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 380 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 381 | | if (_shouldTrace) |
| | 382 | | { |
| 0 | 383 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 384 | | } |
| 0 | 385 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 386 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 387 | | string _responseContent = null; |
| 0 | 388 | | if ((int)_statusCode != 200) |
| | 389 | | { |
| 0 | 390 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 391 | | try |
| | 392 | | { |
| 0 | 393 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 394 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 395 | | if (_errorBody != null) |
| | 396 | | { |
| 0 | 397 | | ex.Body = _errorBody; |
| | 398 | | } |
| 0 | 399 | | } |
| 0 | 400 | | catch (JsonException) |
| | 401 | | { |
| | 402 | | // Ignore the exception |
| 0 | 403 | | } |
| 0 | 404 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 405 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 406 | | if (_shouldTrace) |
| | 407 | | { |
| 0 | 408 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 409 | | } |
| 0 | 410 | | _httpRequest.Dispose(); |
| 0 | 411 | | if (_httpResponse != null) |
| | 412 | | { |
| 0 | 413 | | _httpResponse.Dispose(); |
| | 414 | | } |
| 0 | 415 | | throw ex; |
| | 416 | | } |
| | 417 | | // Create Result |
| 0 | 418 | | var _result = new HttpOperationResponse<IList<Person>>(); |
| 0 | 419 | | _result.Request = _httpRequest; |
| 0 | 420 | | _result.Response = _httpResponse; |
| | 421 | | // Deserialize Response |
| 0 | 422 | | if ((int)_statusCode == 200) |
| | 423 | | { |
| 0 | 424 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 425 | | try |
| | 426 | | { |
| 0 | 427 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<IList<Person>>(_responseContent, |
| 0 | 428 | | } |
| 0 | 429 | | catch (JsonException ex) |
| | 430 | | { |
| 0 | 431 | | _httpRequest.Dispose(); |
| 0 | 432 | | if (_httpResponse != null) |
| | 433 | | { |
| 0 | 434 | | _httpResponse.Dispose(); |
| | 435 | | } |
| 0 | 436 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 437 | | } |
| | 438 | | } |
| 0 | 439 | | if (_shouldTrace) |
| | 440 | | { |
| 0 | 441 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 442 | | } |
| 0 | 443 | | return _result; |
| 0 | 444 | | } |
| | 445 | |
|
| | 446 | | /// <summary> |
| | 447 | | /// Delete an existing person from a person group. The persistedFaceId, |
| | 448 | | /// userData, person name and face feature in the person entry will all be |
| | 449 | | /// deleted. |
| | 450 | | /// </summary> |
| | 451 | | /// <param name='personGroupId'> |
| | 452 | | /// Id referencing a particular person group. |
| | 453 | | /// </param> |
| | 454 | | /// <param name='personId'> |
| | 455 | | /// Id referencing a particular person. |
| | 456 | | /// </param> |
| | 457 | | /// <param name='customHeaders'> |
| | 458 | | /// Headers that will be added to request. |
| | 459 | | /// </param> |
| | 460 | | /// <param name='cancellationToken'> |
| | 461 | | /// The cancellation token. |
| | 462 | | /// </param> |
| | 463 | | /// <exception cref="APIErrorException"> |
| | 464 | | /// Thrown when the operation returned an invalid status code |
| | 465 | | /// </exception> |
| | 466 | | /// <exception cref="ValidationException"> |
| | 467 | | /// Thrown when a required parameter is null |
| | 468 | | /// </exception> |
| | 469 | | /// <exception cref="System.ArgumentNullException"> |
| | 470 | | /// Thrown when a required parameter is null |
| | 471 | | /// </exception> |
| | 472 | | /// <return> |
| | 473 | | /// A response object containing the response body and response headers. |
| | 474 | | /// </return> |
| | 475 | | public async Task<HttpOperationResponse> DeleteWithHttpMessagesAsync(string personGroupId, System.Guid personId, |
| | 476 | | { |
| 0 | 477 | | if (Client.Endpoint == null) |
| | 478 | | { |
| 0 | 479 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 480 | | } |
| 0 | 481 | | if (personGroupId == null) |
| | 482 | | { |
| 0 | 483 | | throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId"); |
| | 484 | | } |
| 0 | 485 | | if (personGroupId != null) |
| | 486 | | { |
| 0 | 487 | | if (personGroupId.Length > 64) |
| | 488 | | { |
| 0 | 489 | | throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64); |
| | 490 | | } |
| 0 | 491 | | if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$")) |
| | 492 | | { |
| 0 | 493 | | throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$"); |
| | 494 | | } |
| | 495 | | } |
| | 496 | | // Tracing |
| 0 | 497 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 498 | | string _invocationId = null; |
| 0 | 499 | | if (_shouldTrace) |
| | 500 | | { |
| 0 | 501 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 502 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 503 | | tracingParameters.Add("personGroupId", personGroupId); |
| 0 | 504 | | tracingParameters.Add("personId", personId); |
| 0 | 505 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 506 | | ServiceClientTracing.Enter(_invocationId, this, "Delete", tracingParameters); |
| | 507 | | } |
| | 508 | | // Construct URL |
| 0 | 509 | | var _baseUrl = Client.BaseUri; |
| 0 | 510 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId} |
| 0 | 511 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 512 | | _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId)); |
| 0 | 513 | | _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb |
| | 514 | | // Create HTTP transport objects |
| 0 | 515 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 516 | | HttpResponseMessage _httpResponse = null; |
| 0 | 517 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 518 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 519 | | // Set Headers |
| | 520 | |
|
| | 521 | |
|
| 0 | 522 | | if (customHeaders != null) |
| | 523 | | { |
| 0 | 524 | | foreach(var _header in customHeaders) |
| | 525 | | { |
| 0 | 526 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 527 | | { |
| 0 | 528 | | _httpRequest.Headers.Remove(_header.Key); |
| | 529 | | } |
| 0 | 530 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 531 | | } |
| | 532 | | } |
| | 533 | |
|
| | 534 | | // Serialize Request |
| 0 | 535 | | string _requestContent = null; |
| | 536 | | // Set Credentials |
| 0 | 537 | | if (Client.Credentials != null) |
| | 538 | | { |
| 0 | 539 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 540 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 541 | | } |
| | 542 | | // Send Request |
| 0 | 543 | | if (_shouldTrace) |
| | 544 | | { |
| 0 | 545 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 546 | | } |
| 0 | 547 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 548 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 549 | | if (_shouldTrace) |
| | 550 | | { |
| 0 | 551 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 552 | | } |
| 0 | 553 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 554 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 555 | | string _responseContent = null; |
| 0 | 556 | | if ((int)_statusCode != 200) |
| | 557 | | { |
| 0 | 558 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 559 | | try |
| | 560 | | { |
| 0 | 561 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 562 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 563 | | if (_errorBody != null) |
| | 564 | | { |
| 0 | 565 | | ex.Body = _errorBody; |
| | 566 | | } |
| 0 | 567 | | } |
| 0 | 568 | | catch (JsonException) |
| | 569 | | { |
| | 570 | | // Ignore the exception |
| 0 | 571 | | } |
| 0 | 572 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 573 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 574 | | if (_shouldTrace) |
| | 575 | | { |
| 0 | 576 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 577 | | } |
| 0 | 578 | | _httpRequest.Dispose(); |
| 0 | 579 | | if (_httpResponse != null) |
| | 580 | | { |
| 0 | 581 | | _httpResponse.Dispose(); |
| | 582 | | } |
| 0 | 583 | | throw ex; |
| | 584 | | } |
| | 585 | | // Create Result |
| 0 | 586 | | var _result = new HttpOperationResponse(); |
| 0 | 587 | | _result.Request = _httpRequest; |
| 0 | 588 | | _result.Response = _httpResponse; |
| 0 | 589 | | if (_shouldTrace) |
| | 590 | | { |
| 0 | 591 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 592 | | } |
| 0 | 593 | | return _result; |
| 0 | 594 | | } |
| | 595 | |
|
| | 596 | | /// <summary> |
| | 597 | | /// Retrieve a person's information, including registered persisted faces, name |
| | 598 | | /// and userData. |
| | 599 | | /// </summary> |
| | 600 | | /// <param name='personGroupId'> |
| | 601 | | /// Id referencing a particular person group. |
| | 602 | | /// </param> |
| | 603 | | /// <param name='personId'> |
| | 604 | | /// Id referencing a particular person. |
| | 605 | | /// </param> |
| | 606 | | /// <param name='customHeaders'> |
| | 607 | | /// Headers that will be added to request. |
| | 608 | | /// </param> |
| | 609 | | /// <param name='cancellationToken'> |
| | 610 | | /// The cancellation token. |
| | 611 | | /// </param> |
| | 612 | | /// <exception cref="APIErrorException"> |
| | 613 | | /// Thrown when the operation returned an invalid status code |
| | 614 | | /// </exception> |
| | 615 | | /// <exception cref="SerializationException"> |
| | 616 | | /// Thrown when unable to deserialize the response |
| | 617 | | /// </exception> |
| | 618 | | /// <exception cref="ValidationException"> |
| | 619 | | /// Thrown when a required parameter is null |
| | 620 | | /// </exception> |
| | 621 | | /// <exception cref="System.ArgumentNullException"> |
| | 622 | | /// Thrown when a required parameter is null |
| | 623 | | /// </exception> |
| | 624 | | /// <return> |
| | 625 | | /// A response object containing the response body and response headers. |
| | 626 | | /// </return> |
| | 627 | | public async Task<HttpOperationResponse<Person>> GetWithHttpMessagesAsync(string personGroupId, System.Guid pers |
| | 628 | | { |
| 2 | 629 | | if (Client.Endpoint == null) |
| | 630 | | { |
| 0 | 631 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 632 | | } |
| 2 | 633 | | if (personGroupId == null) |
| | 634 | | { |
| 0 | 635 | | throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId"); |
| | 636 | | } |
| 2 | 637 | | if (personGroupId != null) |
| | 638 | | { |
| 2 | 639 | | if (personGroupId.Length > 64) |
| | 640 | | { |
| 0 | 641 | | throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64); |
| | 642 | | } |
| 2 | 643 | | if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$")) |
| | 644 | | { |
| 0 | 645 | | throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$"); |
| | 646 | | } |
| | 647 | | } |
| | 648 | | // Tracing |
| 2 | 649 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 650 | | string _invocationId = null; |
| 2 | 651 | | if (_shouldTrace) |
| | 652 | | { |
| 0 | 653 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 654 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 655 | | tracingParameters.Add("personGroupId", personGroupId); |
| 0 | 656 | | tracingParameters.Add("personId", personId); |
| 0 | 657 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 658 | | ServiceClientTracing.Enter(_invocationId, this, "Get", tracingParameters); |
| | 659 | | } |
| | 660 | | // Construct URL |
| 2 | 661 | | var _baseUrl = Client.BaseUri; |
| 2 | 662 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId} |
| 2 | 663 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 2 | 664 | | _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId)); |
| 2 | 665 | | _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb |
| | 666 | | // Create HTTP transport objects |
| 2 | 667 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 668 | | HttpResponseMessage _httpResponse = null; |
| 2 | 669 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 670 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 671 | | // Set Headers |
| | 672 | |
|
| | 673 | |
|
| 2 | 674 | | if (customHeaders != null) |
| | 675 | | { |
| 0 | 676 | | foreach(var _header in customHeaders) |
| | 677 | | { |
| 0 | 678 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 679 | | { |
| 0 | 680 | | _httpRequest.Headers.Remove(_header.Key); |
| | 681 | | } |
| 0 | 682 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 683 | | } |
| | 684 | | } |
| | 685 | |
|
| | 686 | | // Serialize Request |
| 2 | 687 | | string _requestContent = null; |
| | 688 | | // Set Credentials |
| 2 | 689 | | if (Client.Credentials != null) |
| | 690 | | { |
| 2 | 691 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 692 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 693 | | } |
| | 694 | | // Send Request |
| 2 | 695 | | if (_shouldTrace) |
| | 696 | | { |
| 0 | 697 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 698 | | } |
| 2 | 699 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 700 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 701 | | if (_shouldTrace) |
| | 702 | | { |
| 0 | 703 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 704 | | } |
| 2 | 705 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 706 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 707 | | string _responseContent = null; |
| 2 | 708 | | if ((int)_statusCode != 200) |
| | 709 | | { |
| 0 | 710 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 711 | | try |
| | 712 | | { |
| 0 | 713 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 714 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 715 | | if (_errorBody != null) |
| | 716 | | { |
| 0 | 717 | | ex.Body = _errorBody; |
| | 718 | | } |
| 0 | 719 | | } |
| 0 | 720 | | catch (JsonException) |
| | 721 | | { |
| | 722 | | // Ignore the exception |
| 0 | 723 | | } |
| 0 | 724 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 725 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 726 | | if (_shouldTrace) |
| | 727 | | { |
| 0 | 728 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 729 | | } |
| 0 | 730 | | _httpRequest.Dispose(); |
| 0 | 731 | | if (_httpResponse != null) |
| | 732 | | { |
| 0 | 733 | | _httpResponse.Dispose(); |
| | 734 | | } |
| 0 | 735 | | throw ex; |
| | 736 | | } |
| | 737 | | // Create Result |
| 2 | 738 | | var _result = new HttpOperationResponse<Person>(); |
| 2 | 739 | | _result.Request = _httpRequest; |
| 2 | 740 | | _result.Response = _httpResponse; |
| | 741 | | // Deserialize Response |
| 2 | 742 | | if ((int)_statusCode == 200) |
| | 743 | | { |
| 2 | 744 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 745 | | try |
| | 746 | | { |
| 2 | 747 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<Person>(_responseContent, Client |
| 2 | 748 | | } |
| 0 | 749 | | catch (JsonException ex) |
| | 750 | | { |
| 0 | 751 | | _httpRequest.Dispose(); |
| 0 | 752 | | if (_httpResponse != null) |
| | 753 | | { |
| 0 | 754 | | _httpResponse.Dispose(); |
| | 755 | | } |
| 0 | 756 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 757 | | } |
| | 758 | | } |
| 2 | 759 | | if (_shouldTrace) |
| | 760 | | { |
| 0 | 761 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 762 | | } |
| 2 | 763 | | return _result; |
| 2 | 764 | | } |
| | 765 | |
|
| | 766 | | /// <summary> |
| | 767 | | /// Update name or userData of a person. |
| | 768 | | /// </summary> |
| | 769 | | /// <param name='personGroupId'> |
| | 770 | | /// Id referencing a particular person group. |
| | 771 | | /// </param> |
| | 772 | | /// <param name='personId'> |
| | 773 | | /// Id referencing a particular person. |
| | 774 | | /// </param> |
| | 775 | | /// <param name='name'> |
| | 776 | | /// User defined name, maximum length is 128. |
| | 777 | | /// </param> |
| | 778 | | /// <param name='userData'> |
| | 779 | | /// User specified data. Length should not exceed 16KB. |
| | 780 | | /// </param> |
| | 781 | | /// <param name='customHeaders'> |
| | 782 | | /// Headers that will be added to request. |
| | 783 | | /// </param> |
| | 784 | | /// <param name='cancellationToken'> |
| | 785 | | /// The cancellation token. |
| | 786 | | /// </param> |
| | 787 | | /// <exception cref="APIErrorException"> |
| | 788 | | /// Thrown when the operation returned an invalid status code |
| | 789 | | /// </exception> |
| | 790 | | /// <exception cref="ValidationException"> |
| | 791 | | /// Thrown when a required parameter is null |
| | 792 | | /// </exception> |
| | 793 | | /// <exception cref="System.ArgumentNullException"> |
| | 794 | | /// Thrown when a required parameter is null |
| | 795 | | /// </exception> |
| | 796 | | /// <return> |
| | 797 | | /// A response object containing the response body and response headers. |
| | 798 | | /// </return> |
| | 799 | | public async Task<HttpOperationResponse> UpdateWithHttpMessagesAsync(string personGroupId, System.Guid personId, |
| | 800 | | { |
| 0 | 801 | | if (Client.Endpoint == null) |
| | 802 | | { |
| 0 | 803 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 804 | | } |
| 0 | 805 | | if (personGroupId == null) |
| | 806 | | { |
| 0 | 807 | | throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId"); |
| | 808 | | } |
| 0 | 809 | | if (personGroupId != null) |
| | 810 | | { |
| 0 | 811 | | if (personGroupId.Length > 64) |
| | 812 | | { |
| 0 | 813 | | throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64); |
| | 814 | | } |
| 0 | 815 | | if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$")) |
| | 816 | | { |
| 0 | 817 | | throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$"); |
| | 818 | | } |
| | 819 | | } |
| 0 | 820 | | if (name != null) |
| | 821 | | { |
| 0 | 822 | | if (name.Length > 128) |
| | 823 | | { |
| 0 | 824 | | throw new ValidationException(ValidationRules.MaxLength, "name", 128); |
| | 825 | | } |
| | 826 | | } |
| 0 | 827 | | if (userData != null) |
| | 828 | | { |
| 0 | 829 | | if (userData.Length > 16384) |
| | 830 | | { |
| 0 | 831 | | throw new ValidationException(ValidationRules.MaxLength, "userData", 16384); |
| | 832 | | } |
| | 833 | | } |
| 0 | 834 | | NameAndUserDataContract body = new NameAndUserDataContract(); |
| 0 | 835 | | if (name != null || userData != null) |
| | 836 | | { |
| 0 | 837 | | body.Name = name; |
| 0 | 838 | | body.UserData = userData; |
| | 839 | | } |
| | 840 | | // Tracing |
| 0 | 841 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 842 | | string _invocationId = null; |
| 0 | 843 | | if (_shouldTrace) |
| | 844 | | { |
| 0 | 845 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 846 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 847 | | tracingParameters.Add("personGroupId", personGroupId); |
| 0 | 848 | | tracingParameters.Add("personId", personId); |
| 0 | 849 | | tracingParameters.Add("body", body); |
| 0 | 850 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 851 | | ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters); |
| | 852 | | } |
| | 853 | | // Construct URL |
| 0 | 854 | | var _baseUrl = Client.BaseUri; |
| 0 | 855 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId} |
| 0 | 856 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 857 | | _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId)); |
| 0 | 858 | | _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb |
| | 859 | | // Create HTTP transport objects |
| 0 | 860 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 861 | | HttpResponseMessage _httpResponse = null; |
| 0 | 862 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 0 | 863 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 864 | | // Set Headers |
| | 865 | |
|
| | 866 | |
|
| 0 | 867 | | if (customHeaders != null) |
| | 868 | | { |
| 0 | 869 | | foreach(var _header in customHeaders) |
| | 870 | | { |
| 0 | 871 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 872 | | { |
| 0 | 873 | | _httpRequest.Headers.Remove(_header.Key); |
| | 874 | | } |
| 0 | 875 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 876 | | } |
| | 877 | | } |
| | 878 | |
|
| | 879 | | // Serialize Request |
| 0 | 880 | | string _requestContent = null; |
| 0 | 881 | | if(body != null) |
| | 882 | | { |
| 0 | 883 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings) |
| 0 | 884 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 885 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 886 | | } |
| | 887 | | // Set Credentials |
| 0 | 888 | | if (Client.Credentials != null) |
| | 889 | | { |
| 0 | 890 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 891 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 892 | | } |
| | 893 | | // Send Request |
| 0 | 894 | | if (_shouldTrace) |
| | 895 | | { |
| 0 | 896 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 897 | | } |
| 0 | 898 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 899 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 900 | | if (_shouldTrace) |
| | 901 | | { |
| 0 | 902 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 903 | | } |
| 0 | 904 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 905 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 906 | | string _responseContent = null; |
| 0 | 907 | | if ((int)_statusCode != 200) |
| | 908 | | { |
| 0 | 909 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 910 | | try |
| | 911 | | { |
| 0 | 912 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 913 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 914 | | if (_errorBody != null) |
| | 915 | | { |
| 0 | 916 | | ex.Body = _errorBody; |
| | 917 | | } |
| 0 | 918 | | } |
| 0 | 919 | | catch (JsonException) |
| | 920 | | { |
| | 921 | | // Ignore the exception |
| 0 | 922 | | } |
| 0 | 923 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 924 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 925 | | if (_shouldTrace) |
| | 926 | | { |
| 0 | 927 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 928 | | } |
| 0 | 929 | | _httpRequest.Dispose(); |
| 0 | 930 | | if (_httpResponse != null) |
| | 931 | | { |
| 0 | 932 | | _httpResponse.Dispose(); |
| | 933 | | } |
| 0 | 934 | | throw ex; |
| | 935 | | } |
| | 936 | | // Create Result |
| 0 | 937 | | var _result = new HttpOperationResponse(); |
| 0 | 938 | | _result.Request = _httpRequest; |
| 0 | 939 | | _result.Response = _httpResponse; |
| 0 | 940 | | if (_shouldTrace) |
| | 941 | | { |
| 0 | 942 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 943 | | } |
| 0 | 944 | | return _result; |
| 0 | 945 | | } |
| | 946 | |
|
| | 947 | | /// <summary> |
| | 948 | | /// Delete a face from a person in a person group by specified personGroupId, |
| | 949 | | /// personId and persistedFaceId. |
| | 950 | | /// <br /> Adding/deleting faces to/from a same person will be processed |
| | 951 | | /// sequentially. Adding/deleting faces to/from different persons are processed |
| | 952 | | /// in parallel. |
| | 953 | | /// </summary> |
| | 954 | | /// <param name='personGroupId'> |
| | 955 | | /// Id referencing a particular person group. |
| | 956 | | /// </param> |
| | 957 | | /// <param name='personId'> |
| | 958 | | /// Id referencing a particular person. |
| | 959 | | /// </param> |
| | 960 | | /// <param name='persistedFaceId'> |
| | 961 | | /// Id referencing a particular persistedFaceId of an existing face. |
| | 962 | | /// </param> |
| | 963 | | /// <param name='customHeaders'> |
| | 964 | | /// Headers that will be added to request. |
| | 965 | | /// </param> |
| | 966 | | /// <param name='cancellationToken'> |
| | 967 | | /// The cancellation token. |
| | 968 | | /// </param> |
| | 969 | | /// <exception cref="APIErrorException"> |
| | 970 | | /// Thrown when the operation returned an invalid status code |
| | 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> DeleteFaceWithHttpMessagesAsync(string personGroupId, System.Guid perso |
| | 982 | | { |
| 0 | 983 | | if (Client.Endpoint == null) |
| | 984 | | { |
| 0 | 985 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 986 | | } |
| 0 | 987 | | if (personGroupId == null) |
| | 988 | | { |
| 0 | 989 | | throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId"); |
| | 990 | | } |
| 0 | 991 | | if (personGroupId != null) |
| | 992 | | { |
| 0 | 993 | | if (personGroupId.Length > 64) |
| | 994 | | { |
| 0 | 995 | | throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64); |
| | 996 | | } |
| 0 | 997 | | if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$")) |
| | 998 | | { |
| 0 | 999 | | throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$"); |
| | 1000 | | } |
| | 1001 | | } |
| | 1002 | | // Tracing |
| 0 | 1003 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1004 | | string _invocationId = null; |
| 0 | 1005 | | if (_shouldTrace) |
| | 1006 | | { |
| 0 | 1007 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1008 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1009 | | tracingParameters.Add("personGroupId", personGroupId); |
| 0 | 1010 | | tracingParameters.Add("personId", personId); |
| 0 | 1011 | | tracingParameters.Add("persistedFaceId", persistedFaceId); |
| 0 | 1012 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1013 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteFace", tracingParameters); |
| | 1014 | | } |
| | 1015 | | // Construct URL |
| 0 | 1016 | | var _baseUrl = Client.BaseUri; |
| 0 | 1017 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId} |
| 0 | 1018 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1019 | | _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId)); |
| 0 | 1020 | | _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb |
| 0 | 1021 | | _url = _url.Replace("{persistedFaceId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Seri |
| | 1022 | | // Create HTTP transport objects |
| 0 | 1023 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1024 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1025 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 0 | 1026 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1027 | | // Set Headers |
| | 1028 | |
|
| | 1029 | |
|
| 0 | 1030 | | if (customHeaders != null) |
| | 1031 | | { |
| 0 | 1032 | | foreach(var _header in customHeaders) |
| | 1033 | | { |
| 0 | 1034 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1035 | | { |
| 0 | 1036 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1037 | | } |
| 0 | 1038 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1039 | | } |
| | 1040 | | } |
| | 1041 | |
|
| | 1042 | | // Serialize Request |
| 0 | 1043 | | string _requestContent = null; |
| | 1044 | | // Set Credentials |
| 0 | 1045 | | if (Client.Credentials != null) |
| | 1046 | | { |
| 0 | 1047 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1048 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1049 | | } |
| | 1050 | | // Send Request |
| 0 | 1051 | | if (_shouldTrace) |
| | 1052 | | { |
| 0 | 1053 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1054 | | } |
| 0 | 1055 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1056 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1057 | | if (_shouldTrace) |
| | 1058 | | { |
| 0 | 1059 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1060 | | } |
| 0 | 1061 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1062 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1063 | | string _responseContent = null; |
| 0 | 1064 | | if ((int)_statusCode != 200) |
| | 1065 | | { |
| 0 | 1066 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1067 | | try |
| | 1068 | | { |
| 0 | 1069 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1070 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1071 | | if (_errorBody != null) |
| | 1072 | | { |
| 0 | 1073 | | ex.Body = _errorBody; |
| | 1074 | | } |
| 0 | 1075 | | } |
| 0 | 1076 | | catch (JsonException) |
| | 1077 | | { |
| | 1078 | | // Ignore the exception |
| 0 | 1079 | | } |
| 0 | 1080 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1081 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1082 | | if (_shouldTrace) |
| | 1083 | | { |
| 0 | 1084 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1085 | | } |
| 0 | 1086 | | _httpRequest.Dispose(); |
| 0 | 1087 | | if (_httpResponse != null) |
| | 1088 | | { |
| 0 | 1089 | | _httpResponse.Dispose(); |
| | 1090 | | } |
| 0 | 1091 | | throw ex; |
| | 1092 | | } |
| | 1093 | | // Create Result |
| 0 | 1094 | | var _result = new HttpOperationResponse(); |
| 0 | 1095 | | _result.Request = _httpRequest; |
| 0 | 1096 | | _result.Response = _httpResponse; |
| 0 | 1097 | | if (_shouldTrace) |
| | 1098 | | { |
| 0 | 1099 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1100 | | } |
| 0 | 1101 | | return _result; |
| 0 | 1102 | | } |
| | 1103 | |
|
| | 1104 | | /// <summary> |
| | 1105 | | /// Retrieve information about a persisted face (specified by persistedFaceId, |
| | 1106 | | /// personId and its belonging personGroupId). |
| | 1107 | | /// </summary> |
| | 1108 | | /// <param name='personGroupId'> |
| | 1109 | | /// Id referencing a particular person group. |
| | 1110 | | /// </param> |
| | 1111 | | /// <param name='personId'> |
| | 1112 | | /// Id referencing a particular person. |
| | 1113 | | /// </param> |
| | 1114 | | /// <param name='persistedFaceId'> |
| | 1115 | | /// Id referencing a particular persistedFaceId of an existing face. |
| | 1116 | | /// </param> |
| | 1117 | | /// <param name='customHeaders'> |
| | 1118 | | /// Headers that will be added to request. |
| | 1119 | | /// </param> |
| | 1120 | | /// <param name='cancellationToken'> |
| | 1121 | | /// The cancellation token. |
| | 1122 | | /// </param> |
| | 1123 | | /// <exception cref="APIErrorException"> |
| | 1124 | | /// Thrown when the operation returned an invalid status code |
| | 1125 | | /// </exception> |
| | 1126 | | /// <exception cref="SerializationException"> |
| | 1127 | | /// Thrown when unable to deserialize the response |
| | 1128 | | /// </exception> |
| | 1129 | | /// <exception cref="ValidationException"> |
| | 1130 | | /// Thrown when a required parameter is null |
| | 1131 | | /// </exception> |
| | 1132 | | /// <exception cref="System.ArgumentNullException"> |
| | 1133 | | /// Thrown when a required parameter is null |
| | 1134 | | /// </exception> |
| | 1135 | | /// <return> |
| | 1136 | | /// A response object containing the response body and response headers. |
| | 1137 | | /// </return> |
| | 1138 | | public async Task<HttpOperationResponse<PersistedFace>> GetFaceWithHttpMessagesAsync(string personGroupId, Syste |
| | 1139 | | { |
| 2 | 1140 | | if (Client.Endpoint == null) |
| | 1141 | | { |
| 0 | 1142 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1143 | | } |
| 2 | 1144 | | if (personGroupId == null) |
| | 1145 | | { |
| 0 | 1146 | | throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId"); |
| | 1147 | | } |
| 2 | 1148 | | if (personGroupId != null) |
| | 1149 | | { |
| 2 | 1150 | | if (personGroupId.Length > 64) |
| | 1151 | | { |
| 0 | 1152 | | throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64); |
| | 1153 | | } |
| 2 | 1154 | | if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$")) |
| | 1155 | | { |
| 0 | 1156 | | throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$"); |
| | 1157 | | } |
| | 1158 | | } |
| | 1159 | | // Tracing |
| 2 | 1160 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 1161 | | string _invocationId = null; |
| 2 | 1162 | | if (_shouldTrace) |
| | 1163 | | { |
| 0 | 1164 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1165 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1166 | | tracingParameters.Add("personGroupId", personGroupId); |
| 0 | 1167 | | tracingParameters.Add("personId", personId); |
| 0 | 1168 | | tracingParameters.Add("persistedFaceId", persistedFaceId); |
| 0 | 1169 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1170 | | ServiceClientTracing.Enter(_invocationId, this, "GetFace", tracingParameters); |
| | 1171 | | } |
| | 1172 | | // Construct URL |
| 2 | 1173 | | var _baseUrl = Client.BaseUri; |
| 2 | 1174 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId} |
| 2 | 1175 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 2 | 1176 | | _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId)); |
| 2 | 1177 | | _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb |
| 2 | 1178 | | _url = _url.Replace("{persistedFaceId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Seri |
| | 1179 | | // Create HTTP transport objects |
| 2 | 1180 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 1181 | | HttpResponseMessage _httpResponse = null; |
| 2 | 1182 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 1183 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1184 | | // Set Headers |
| | 1185 | |
|
| | 1186 | |
|
| 2 | 1187 | | if (customHeaders != null) |
| | 1188 | | { |
| 0 | 1189 | | foreach(var _header in customHeaders) |
| | 1190 | | { |
| 0 | 1191 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1192 | | { |
| 0 | 1193 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1194 | | } |
| 0 | 1195 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1196 | | } |
| | 1197 | | } |
| | 1198 | |
|
| | 1199 | | // Serialize Request |
| 2 | 1200 | | string _requestContent = null; |
| | 1201 | | // Set Credentials |
| 2 | 1202 | | if (Client.Credentials != null) |
| | 1203 | | { |
| 2 | 1204 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1205 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1206 | | } |
| | 1207 | | // Send Request |
| 2 | 1208 | | if (_shouldTrace) |
| | 1209 | | { |
| 0 | 1210 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1211 | | } |
| 2 | 1212 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1213 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 1214 | | if (_shouldTrace) |
| | 1215 | | { |
| 0 | 1216 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1217 | | } |
| 2 | 1218 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 1219 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1220 | | string _responseContent = null; |
| 2 | 1221 | | if ((int)_statusCode != 200) |
| | 1222 | | { |
| 0 | 1223 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1224 | | try |
| | 1225 | | { |
| 0 | 1226 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1227 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1228 | | if (_errorBody != null) |
| | 1229 | | { |
| 0 | 1230 | | ex.Body = _errorBody; |
| | 1231 | | } |
| 0 | 1232 | | } |
| 0 | 1233 | | catch (JsonException) |
| | 1234 | | { |
| | 1235 | | // Ignore the exception |
| 0 | 1236 | | } |
| 0 | 1237 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1238 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1239 | | if (_shouldTrace) |
| | 1240 | | { |
| 0 | 1241 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1242 | | } |
| 0 | 1243 | | _httpRequest.Dispose(); |
| 0 | 1244 | | if (_httpResponse != null) |
| | 1245 | | { |
| 0 | 1246 | | _httpResponse.Dispose(); |
| | 1247 | | } |
| 0 | 1248 | | throw ex; |
| | 1249 | | } |
| | 1250 | | // Create Result |
| 2 | 1251 | | var _result = new HttpOperationResponse<PersistedFace>(); |
| 2 | 1252 | | _result.Request = _httpRequest; |
| 2 | 1253 | | _result.Response = _httpResponse; |
| | 1254 | | // Deserialize Response |
| 2 | 1255 | | if ((int)_statusCode == 200) |
| | 1256 | | { |
| 2 | 1257 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1258 | | try |
| | 1259 | | { |
| 2 | 1260 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent, |
| 2 | 1261 | | } |
| 0 | 1262 | | catch (JsonException ex) |
| | 1263 | | { |
| 0 | 1264 | | _httpRequest.Dispose(); |
| 0 | 1265 | | if (_httpResponse != null) |
| | 1266 | | { |
| 0 | 1267 | | _httpResponse.Dispose(); |
| | 1268 | | } |
| 0 | 1269 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1270 | | } |
| | 1271 | | } |
| 2 | 1272 | | if (_shouldTrace) |
| | 1273 | | { |
| 0 | 1274 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1275 | | } |
| 2 | 1276 | | return _result; |
| 2 | 1277 | | } |
| | 1278 | |
|
| | 1279 | | /// <summary> |
| | 1280 | | /// Add a face to a person into a person group for face identification or |
| | 1281 | | /// verification. To deal with an image contains multiple faces, input face can |
| | 1282 | | /// be specified as an image with a targetFace rectangle. It returns a |
| | 1283 | | /// persistedFaceId representing the added face. No image will be stored. Only |
| | 1284 | | /// the extracted face feature will be stored on server until [PersonGroup |
| | 1285 | | /// PersonFace - |
| | 1286 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e), |
| | 1287 | | /// [PersonGroup Person - |
| | 1288 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d) |
| | 1289 | | /// or [PersonGroup - |
| | 1290 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245) |
| | 1291 | | /// is called. |
| | 1292 | | /// <br /> Note persistedFaceId is different from faceId generated by |
| | 1293 | | /// [Face - |
| | 1294 | | /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236). |
| | 1295 | | /// * Higher face image quality means better recognition precision. Please |
| | 1296 | | /// consider high-quality faces: frontal, clear, and face size is 200x200 |
| | 1297 | | /// pixels (100 pixels between eyes) or bigger. |
| | 1298 | | /// * Each person entry can hold up to 248 faces. |
| | 1299 | | /// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The |
| | 1300 | | /// allowed image file size is from 1KB to 6MB. |
| | 1301 | | /// * "targetFace" rectangle should contain one face. Zero or multiple faces |
| | 1302 | | /// will be regarded as an error. If the provided "targetFace" rectangle is not |
| | 1303 | | /// returned from [Face - |
| | 1304 | | /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236), |
| | 1305 | | /// there’s no guarantee to detect and add the face successfully. |
| | 1306 | | /// * Out of detectable face size (36x36 - 4096x4096 pixels), large head-pose, |
| | 1307 | | /// or large occlusions will cause failures. |
| | 1308 | | /// * Adding/deleting faces to/from a same person will be processed |
| | 1309 | | /// sequentially. Adding/deleting faces to/from different persons are processed |
| | 1310 | | /// in parallel. |
| | 1311 | | /// </summary> |
| | 1312 | | /// <param name='personGroupId'> |
| | 1313 | | /// Id referencing a particular person group. |
| | 1314 | | /// </param> |
| | 1315 | | /// <param name='personId'> |
| | 1316 | | /// Id referencing a particular person. |
| | 1317 | | /// </param> |
| | 1318 | | /// <param name='persistedFaceId'> |
| | 1319 | | /// Id referencing a particular persistedFaceId of an existing face. |
| | 1320 | | /// </param> |
| | 1321 | | /// <param name='userData'> |
| | 1322 | | /// User-provided data attached to the face. The size limit is 1KB. |
| | 1323 | | /// </param> |
| | 1324 | | /// <param name='customHeaders'> |
| | 1325 | | /// Headers that will be added to request. |
| | 1326 | | /// </param> |
| | 1327 | | /// <param name='cancellationToken'> |
| | 1328 | | /// The cancellation token. |
| | 1329 | | /// </param> |
| | 1330 | | /// <exception cref="APIErrorException"> |
| | 1331 | | /// Thrown when the operation returned an invalid status code |
| | 1332 | | /// </exception> |
| | 1333 | | /// <exception cref="ValidationException"> |
| | 1334 | | /// Thrown when a required parameter is null |
| | 1335 | | /// </exception> |
| | 1336 | | /// <exception cref="System.ArgumentNullException"> |
| | 1337 | | /// Thrown when a required parameter is null |
| | 1338 | | /// </exception> |
| | 1339 | | /// <return> |
| | 1340 | | /// A response object containing the response body and response headers. |
| | 1341 | | /// </return> |
| | 1342 | | public async Task<HttpOperationResponse> UpdateFaceWithHttpMessagesAsync(string personGroupId, System.Guid perso |
| | 1343 | | { |
| 0 | 1344 | | if (Client.Endpoint == null) |
| | 1345 | | { |
| 0 | 1346 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1347 | | } |
| 0 | 1348 | | if (personGroupId == null) |
| | 1349 | | { |
| 0 | 1350 | | throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId"); |
| | 1351 | | } |
| 0 | 1352 | | if (personGroupId != null) |
| | 1353 | | { |
| 0 | 1354 | | if (personGroupId.Length > 64) |
| | 1355 | | { |
| 0 | 1356 | | throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64); |
| | 1357 | | } |
| 0 | 1358 | | if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$")) |
| | 1359 | | { |
| 0 | 1360 | | throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$"); |
| | 1361 | | } |
| | 1362 | | } |
| 0 | 1363 | | if (userData != null) |
| | 1364 | | { |
| 0 | 1365 | | if (userData.Length > 1024) |
| | 1366 | | { |
| 0 | 1367 | | throw new ValidationException(ValidationRules.MaxLength, "userData", 1024); |
| | 1368 | | } |
| | 1369 | | } |
| 0 | 1370 | | UpdateFaceRequest body = new UpdateFaceRequest(); |
| 0 | 1371 | | if (userData != null) |
| | 1372 | | { |
| 0 | 1373 | | body.UserData = userData; |
| | 1374 | | } |
| | 1375 | | // Tracing |
| 0 | 1376 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1377 | | string _invocationId = null; |
| 0 | 1378 | | if (_shouldTrace) |
| | 1379 | | { |
| 0 | 1380 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1381 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1382 | | tracingParameters.Add("personGroupId", personGroupId); |
| 0 | 1383 | | tracingParameters.Add("personId", personId); |
| 0 | 1384 | | tracingParameters.Add("persistedFaceId", persistedFaceId); |
| 0 | 1385 | | tracingParameters.Add("body", body); |
| 0 | 1386 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1387 | | ServiceClientTracing.Enter(_invocationId, this, "UpdateFace", tracingParameters); |
| | 1388 | | } |
| | 1389 | | // Construct URL |
| 0 | 1390 | | var _baseUrl = Client.BaseUri; |
| 0 | 1391 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId} |
| 0 | 1392 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1393 | | _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId)); |
| 0 | 1394 | | _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb |
| 0 | 1395 | | _url = _url.Replace("{persistedFaceId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.Seri |
| | 1396 | | // Create HTTP transport objects |
| 0 | 1397 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1398 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1399 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 0 | 1400 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1401 | | // Set Headers |
| | 1402 | |
|
| | 1403 | |
|
| 0 | 1404 | | if (customHeaders != null) |
| | 1405 | | { |
| 0 | 1406 | | foreach(var _header in customHeaders) |
| | 1407 | | { |
| 0 | 1408 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1409 | | { |
| 0 | 1410 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1411 | | } |
| 0 | 1412 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1413 | | } |
| | 1414 | | } |
| | 1415 | |
|
| | 1416 | | // Serialize Request |
| 0 | 1417 | | string _requestContent = null; |
| 0 | 1418 | | if(body != null) |
| | 1419 | | { |
| 0 | 1420 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(body, Client.SerializationSettings) |
| 0 | 1421 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1422 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1423 | | } |
| | 1424 | | // Set Credentials |
| 0 | 1425 | | if (Client.Credentials != null) |
| | 1426 | | { |
| 0 | 1427 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1428 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1429 | | } |
| | 1430 | | // Send Request |
| 0 | 1431 | | if (_shouldTrace) |
| | 1432 | | { |
| 0 | 1433 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1434 | | } |
| 0 | 1435 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1436 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1437 | | if (_shouldTrace) |
| | 1438 | | { |
| 0 | 1439 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1440 | | } |
| 0 | 1441 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1442 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1443 | | string _responseContent = null; |
| 0 | 1444 | | if ((int)_statusCode != 200) |
| | 1445 | | { |
| 0 | 1446 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1447 | | try |
| | 1448 | | { |
| 0 | 1449 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1450 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1451 | | if (_errorBody != null) |
| | 1452 | | { |
| 0 | 1453 | | ex.Body = _errorBody; |
| | 1454 | | } |
| 0 | 1455 | | } |
| 0 | 1456 | | catch (JsonException) |
| | 1457 | | { |
| | 1458 | | // Ignore the exception |
| 0 | 1459 | | } |
| 0 | 1460 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1461 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1462 | | if (_shouldTrace) |
| | 1463 | | { |
| 0 | 1464 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1465 | | } |
| 0 | 1466 | | _httpRequest.Dispose(); |
| 0 | 1467 | | if (_httpResponse != null) |
| | 1468 | | { |
| 0 | 1469 | | _httpResponse.Dispose(); |
| | 1470 | | } |
| 0 | 1471 | | throw ex; |
| | 1472 | | } |
| | 1473 | | // Create Result |
| 0 | 1474 | | var _result = new HttpOperationResponse(); |
| 0 | 1475 | | _result.Request = _httpRequest; |
| 0 | 1476 | | _result.Response = _httpResponse; |
| 0 | 1477 | | if (_shouldTrace) |
| | 1478 | | { |
| 0 | 1479 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1480 | | } |
| 0 | 1481 | | return _result; |
| 0 | 1482 | | } |
| | 1483 | |
|
| | 1484 | | /// <summary> |
| | 1485 | | /// Add a face to a person into a person group for face identification or |
| | 1486 | | /// verification. To deal with an image contains multiple faces, input face can |
| | 1487 | | /// be specified as an image with a targetFace rectangle. It returns a |
| | 1488 | | /// persistedFaceId representing the added face. No image will be stored. Only |
| | 1489 | | /// the extracted face feature will be stored on server until [PersonGroup |
| | 1490 | | /// PersonFace - |
| | 1491 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e), |
| | 1492 | | /// [PersonGroup Person - |
| | 1493 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d) |
| | 1494 | | /// or [PersonGroup - |
| | 1495 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245) |
| | 1496 | | /// is called. |
| | 1497 | | /// <br /> Note persistedFaceId is different from faceId generated by |
| | 1498 | | /// [Face - |
| | 1499 | | /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236). |
| | 1500 | | /// * Higher face image quality means better recognition precision. Please |
| | 1501 | | /// consider high-quality faces: frontal, clear, and face size is 200x200 |
| | 1502 | | /// pixels (100 pixels between eyes) or bigger. |
| | 1503 | | /// * Each person entry can hold up to 248 faces. |
| | 1504 | | /// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The |
| | 1505 | | /// allowed image file size is from 1KB to 6MB. |
| | 1506 | | /// * "targetFace" rectangle should contain one face. Zero or multiple faces |
| | 1507 | | /// will be regarded as an error. If the provided "targetFace" rectangle is not |
| | 1508 | | /// returned from [Face - |
| | 1509 | | /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236), |
| | 1510 | | /// there’s no guarantee to detect and add the face successfully. |
| | 1511 | | /// * Out of detectable face size (36x36 - 4096x4096 pixels), large |
| | 1512 | | /// head-pose, or large occlusions will cause failures. |
| | 1513 | | /// * Adding/deleting faces to/from a same person will be processed |
| | 1514 | | /// sequentially. Adding/deleting faces to/from different persons are processed |
| | 1515 | | /// in parallel. |
| | 1516 | | /// * The minimum detectable face size is 36x36 pixels in an image no larger |
| | 1517 | | /// than 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels |
| | 1518 | | /// will need a proportionally larger minimum face size. |
| | 1519 | | /// * Different 'detectionModel' values can be provided. To use and compare |
| | 1520 | | /// different detection models, please refer to [How to specify a detection |
| | 1521 | | /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detecti |
| | 1522 | | /// | Model | Recommended use-case(s) | |
| | 1523 | | /// | ---------- | -------- | |
| | 1524 | | /// | 'detection_01': | The default detection model for [PersonGroup Person - |
| | 1525 | | /// Add |
| | 1526 | | /// Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523b). |
| | 1527 | | /// Recommend for near frontal face detection. For scenarios with exceptionally |
| | 1528 | | /// large angle (head-pose) faces, occluded faces or wrong image orientation, |
| | 1529 | | /// the faces in such cases may not be detected. | |
| | 1530 | | /// | 'detection_02': | Detection model released in 2019 May with improved |
| | 1531 | | /// accuracy especially on small, side and blurry faces. | |
| | 1532 | | /// </summary> |
| | 1533 | | /// <param name='personGroupId'> |
| | 1534 | | /// Id referencing a particular person group. |
| | 1535 | | /// </param> |
| | 1536 | | /// <param name='personId'> |
| | 1537 | | /// Id referencing a particular person. |
| | 1538 | | /// </param> |
| | 1539 | | /// <param name='url'> |
| | 1540 | | /// Publicly reachable URL of an image |
| | 1541 | | /// </param> |
| | 1542 | | /// <param name='userData'> |
| | 1543 | | /// User-specified data about the face for any purpose. The maximum length is |
| | 1544 | | /// 1KB. |
| | 1545 | | /// </param> |
| | 1546 | | /// <param name='targetFace'> |
| | 1547 | | /// A face rectangle to specify the target face to be added to a person in the |
| | 1548 | | /// format of "targetFace=left,top,width,height". E.g. |
| | 1549 | | /// "targetFace=10,10,100,100". If there is more than one face in the image, |
| | 1550 | | /// targetFace is required to specify which face to add. No targetFace means |
| | 1551 | | /// there is only one face detected in the entire image. |
| | 1552 | | /// </param> |
| | 1553 | | /// <param name='detectionModel'> |
| | 1554 | | /// Name of detection model. Detection model is used to detect faces in the |
| | 1555 | | /// submitted image. A detection model name can be provided when performing |
| | 1556 | | /// Face - Detect or (Large)FaceList - Add Face or (Large)PersonGroup - Add |
| | 1557 | | /// Face. The default value is 'detection_01', if another model is needed, |
| | 1558 | | /// please explicitly specify it. Possible values include: 'detection_01', |
| | 1559 | | /// 'detection_02' |
| | 1560 | | /// </param> |
| | 1561 | | /// <param name='customHeaders'> |
| | 1562 | | /// Headers that will be added to request. |
| | 1563 | | /// </param> |
| | 1564 | | /// <param name='cancellationToken'> |
| | 1565 | | /// The cancellation token. |
| | 1566 | | /// </param> |
| | 1567 | | /// <exception cref="APIErrorException"> |
| | 1568 | | /// Thrown when the operation returned an invalid status code |
| | 1569 | | /// </exception> |
| | 1570 | | /// <exception cref="SerializationException"> |
| | 1571 | | /// Thrown when unable to deserialize the response |
| | 1572 | | /// </exception> |
| | 1573 | | /// <exception cref="ValidationException"> |
| | 1574 | | /// Thrown when a required parameter is null |
| | 1575 | | /// </exception> |
| | 1576 | | /// <exception cref="System.ArgumentNullException"> |
| | 1577 | | /// Thrown when a required parameter is null |
| | 1578 | | /// </exception> |
| | 1579 | | /// <return> |
| | 1580 | | /// A response object containing the response body and response headers. |
| | 1581 | | /// </return> |
| | 1582 | | public async Task<HttpOperationResponse<PersistedFace>> AddFaceFromUrlWithHttpMessagesAsync(string personGroupId |
| | 1583 | | { |
| 0 | 1584 | | if (Client.Endpoint == null) |
| | 1585 | | { |
| 0 | 1586 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1587 | | } |
| 0 | 1588 | | if (personGroupId == null) |
| | 1589 | | { |
| 0 | 1590 | | throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId"); |
| | 1591 | | } |
| 0 | 1592 | | if (personGroupId != null) |
| | 1593 | | { |
| 0 | 1594 | | if (personGroupId.Length > 64) |
| | 1595 | | { |
| 0 | 1596 | | throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64); |
| | 1597 | | } |
| 0 | 1598 | | if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$")) |
| | 1599 | | { |
| 0 | 1600 | | throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$"); |
| | 1601 | | } |
| | 1602 | | } |
| 0 | 1603 | | if (userData != null) |
| | 1604 | | { |
| 0 | 1605 | | if (userData.Length > 1024) |
| | 1606 | | { |
| 0 | 1607 | | throw new ValidationException(ValidationRules.MaxLength, "userData", 1024); |
| | 1608 | | } |
| | 1609 | | } |
| 0 | 1610 | | if (url == null) |
| | 1611 | | { |
| 0 | 1612 | | throw new ValidationException(ValidationRules.CannotBeNull, "url"); |
| | 1613 | | } |
| 0 | 1614 | | ImageUrl imageUrl = new ImageUrl(); |
| 0 | 1615 | | if (url != null) |
| | 1616 | | { |
| 0 | 1617 | | imageUrl.Url = url; |
| | 1618 | | } |
| | 1619 | | // Tracing |
| 0 | 1620 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 1621 | | string _invocationId = null; |
| 0 | 1622 | | if (_shouldTrace) |
| | 1623 | | { |
| 0 | 1624 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1625 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1626 | | tracingParameters.Add("personGroupId", personGroupId); |
| 0 | 1627 | | tracingParameters.Add("personId", personId); |
| 0 | 1628 | | tracingParameters.Add("userData", userData); |
| 0 | 1629 | | tracingParameters.Add("targetFace", targetFace); |
| 0 | 1630 | | tracingParameters.Add("detectionModel", detectionModel); |
| 0 | 1631 | | tracingParameters.Add("imageUrl", imageUrl); |
| 0 | 1632 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1633 | | ServiceClientTracing.Enter(_invocationId, this, "AddFaceFromUrl", tracingParameters); |
| | 1634 | | } |
| | 1635 | | // Construct URL |
| 0 | 1636 | | var _baseUrl = Client.BaseUri; |
| 0 | 1637 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId} |
| 0 | 1638 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 0 | 1639 | | _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId)); |
| 0 | 1640 | | _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb |
| 0 | 1641 | | List<string> _queryParameters = new List<string>(); |
| 0 | 1642 | | if (userData != null) |
| | 1643 | | { |
| 0 | 1644 | | _queryParameters.Add(string.Format("userData={0}", System.Uri.EscapeDataString(userData))); |
| | 1645 | | } |
| 0 | 1646 | | if (targetFace != null) |
| | 1647 | | { |
| 0 | 1648 | | _queryParameters.Add(string.Format("targetFace={0}", System.Uri.EscapeDataString(string.Join(",", target |
| | 1649 | | } |
| 0 | 1650 | | if (detectionModel != null) |
| | 1651 | | { |
| 0 | 1652 | | _queryParameters.Add(string.Format("detectionModel={0}", System.Uri.EscapeDataString(detectionModel))); |
| | 1653 | | } |
| 0 | 1654 | | if (_queryParameters.Count > 0) |
| | 1655 | | { |
| 0 | 1656 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1657 | | } |
| | 1658 | | // Create HTTP transport objects |
| 0 | 1659 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 1660 | | HttpResponseMessage _httpResponse = null; |
| 0 | 1661 | | _httpRequest.Method = new HttpMethod("POST"); |
| 0 | 1662 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1663 | | // Set Headers |
| | 1664 | |
|
| | 1665 | |
|
| 0 | 1666 | | if (customHeaders != null) |
| | 1667 | | { |
| 0 | 1668 | | foreach(var _header in customHeaders) |
| | 1669 | | { |
| 0 | 1670 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1671 | | { |
| 0 | 1672 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1673 | | } |
| 0 | 1674 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1675 | | } |
| | 1676 | | } |
| | 1677 | |
|
| | 1678 | | // Serialize Request |
| 0 | 1679 | | string _requestContent = null; |
| 0 | 1680 | | if(imageUrl != null) |
| | 1681 | | { |
| 0 | 1682 | | _requestContent = Rest.Serialization.SafeJsonConvert.SerializeObject(imageUrl, Client.SerializationSetti |
| 0 | 1683 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 1684 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1685 | | } |
| | 1686 | | // Set Credentials |
| 0 | 1687 | | if (Client.Credentials != null) |
| | 1688 | | { |
| 0 | 1689 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1690 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1691 | | } |
| | 1692 | | // Send Request |
| 0 | 1693 | | if (_shouldTrace) |
| | 1694 | | { |
| 0 | 1695 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1696 | | } |
| 0 | 1697 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1698 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 1699 | | if (_shouldTrace) |
| | 1700 | | { |
| 0 | 1701 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1702 | | } |
| 0 | 1703 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 1704 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 1705 | | string _responseContent = null; |
| 0 | 1706 | | if ((int)_statusCode != 200) |
| | 1707 | | { |
| 0 | 1708 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1709 | | try |
| | 1710 | | { |
| 0 | 1711 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1712 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1713 | | if (_errorBody != null) |
| | 1714 | | { |
| 0 | 1715 | | ex.Body = _errorBody; |
| | 1716 | | } |
| 0 | 1717 | | } |
| 0 | 1718 | | catch (JsonException) |
| | 1719 | | { |
| | 1720 | | // Ignore the exception |
| 0 | 1721 | | } |
| 0 | 1722 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1723 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1724 | | if (_shouldTrace) |
| | 1725 | | { |
| 0 | 1726 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1727 | | } |
| 0 | 1728 | | _httpRequest.Dispose(); |
| 0 | 1729 | | if (_httpResponse != null) |
| | 1730 | | { |
| 0 | 1731 | | _httpResponse.Dispose(); |
| | 1732 | | } |
| 0 | 1733 | | throw ex; |
| | 1734 | | } |
| | 1735 | | // Create Result |
| 0 | 1736 | | var _result = new HttpOperationResponse<PersistedFace>(); |
| 0 | 1737 | | _result.Request = _httpRequest; |
| 0 | 1738 | | _result.Response = _httpResponse; |
| | 1739 | | // Deserialize Response |
| 0 | 1740 | | if ((int)_statusCode == 200) |
| | 1741 | | { |
| 0 | 1742 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1743 | | try |
| | 1744 | | { |
| 0 | 1745 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent, |
| 0 | 1746 | | } |
| 0 | 1747 | | catch (JsonException ex) |
| | 1748 | | { |
| 0 | 1749 | | _httpRequest.Dispose(); |
| 0 | 1750 | | if (_httpResponse != null) |
| | 1751 | | { |
| 0 | 1752 | | _httpResponse.Dispose(); |
| | 1753 | | } |
| 0 | 1754 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1755 | | } |
| | 1756 | | } |
| 0 | 1757 | | if (_shouldTrace) |
| | 1758 | | { |
| 0 | 1759 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1760 | | } |
| 0 | 1761 | | return _result; |
| 0 | 1762 | | } |
| | 1763 | |
|
| | 1764 | | /// <summary> |
| | 1765 | | /// Add a face to a person into a person group for face identification or |
| | 1766 | | /// verification. To deal with an image contains multiple faces, input face can |
| | 1767 | | /// be specified as an image with a targetFace rectangle. It returns a |
| | 1768 | | /// persistedFaceId representing the added face. No image will be stored. Only |
| | 1769 | | /// the extracted face feature will be stored on server until [PersonGroup |
| | 1770 | | /// PersonFace - |
| | 1771 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523e), |
| | 1772 | | /// [PersonGroup Person - |
| | 1773 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523d) |
| | 1774 | | /// or [PersonGroup - |
| | 1775 | | /// Delete](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395245) |
| | 1776 | | /// is called. |
| | 1777 | | /// <br /> Note persistedFaceId is different from faceId generated by |
| | 1778 | | /// [Face - |
| | 1779 | | /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236). |
| | 1780 | | /// * Higher face image quality means better recognition precision. Please |
| | 1781 | | /// consider high-quality faces: frontal, clear, and face size is 200x200 |
| | 1782 | | /// pixels (100 pixels between eyes) or bigger. |
| | 1783 | | /// * Each person entry can hold up to 248 faces. |
| | 1784 | | /// * JPEG, PNG, GIF (the first frame), and BMP format are supported. The |
| | 1785 | | /// allowed image file size is from 1KB to 6MB. |
| | 1786 | | /// * "targetFace" rectangle should contain one face. Zero or multiple faces |
| | 1787 | | /// will be regarded as an error. If the provided "targetFace" rectangle is not |
| | 1788 | | /// returned from [Face - |
| | 1789 | | /// Detect](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236), |
| | 1790 | | /// there’s no guarantee to detect and add the face successfully. |
| | 1791 | | /// * Out of detectable face size (36x36 - 4096x4096 pixels), large |
| | 1792 | | /// head-pose, or large occlusions will cause failures. |
| | 1793 | | /// * Adding/deleting faces to/from a same person will be processed |
| | 1794 | | /// sequentially. Adding/deleting faces to/from different persons are processed |
| | 1795 | | /// in parallel. |
| | 1796 | | /// * The minimum detectable face size is 36x36 pixels in an image no larger |
| | 1797 | | /// than 1920x1080 pixels. Images with dimensions higher than 1920x1080 pixels |
| | 1798 | | /// will need a proportionally larger minimum face size. |
| | 1799 | | /// * Different 'detectionModel' values can be provided. To use and compare |
| | 1800 | | /// different detection models, please refer to [How to specify a detection |
| | 1801 | | /// model](https://docs.microsoft.com/en-us/azure/cognitive-services/face/face-api-how-to-topics/specify-detecti |
| | 1802 | | /// | Model | Recommended use-case(s) | |
| | 1803 | | /// | ---------- | -------- | |
| | 1804 | | /// | 'detection_01': | The default detection model for [PersonGroup Person - |
| | 1805 | | /// Add |
| | 1806 | | /// Face](/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523b). |
| | 1807 | | /// Recommend for near frontal face detection. For scenarios with exceptionally |
| | 1808 | | /// large angle (head-pose) faces, occluded faces or wrong image orientation, |
| | 1809 | | /// the faces in such cases may not be detected. | |
| | 1810 | | /// | 'detection_02': | Detection model released in 2019 May with improved |
| | 1811 | | /// accuracy especially on small, side and blurry faces. | |
| | 1812 | | /// </summary> |
| | 1813 | | /// <param name='personGroupId'> |
| | 1814 | | /// Id referencing a particular person group. |
| | 1815 | | /// </param> |
| | 1816 | | /// <param name='personId'> |
| | 1817 | | /// Id referencing a particular person. |
| | 1818 | | /// </param> |
| | 1819 | | /// <param name='image'> |
| | 1820 | | /// An image stream. |
| | 1821 | | /// </param> |
| | 1822 | | /// <param name='userData'> |
| | 1823 | | /// User-specified data about the face for any purpose. The maximum length is |
| | 1824 | | /// 1KB. |
| | 1825 | | /// </param> |
| | 1826 | | /// <param name='targetFace'> |
| | 1827 | | /// A face rectangle to specify the target face to be added to a person in the |
| | 1828 | | /// format of "targetFace=left,top,width,height". E.g. |
| | 1829 | | /// "targetFace=10,10,100,100". If there is more than one face in the image, |
| | 1830 | | /// targetFace is required to specify which face to add. No targetFace means |
| | 1831 | | /// there is only one face detected in the entire image. |
| | 1832 | | /// </param> |
| | 1833 | | /// <param name='detectionModel'> |
| | 1834 | | /// Name of detection model. Detection model is used to detect faces in the |
| | 1835 | | /// submitted image. A detection model name can be provided when performing |
| | 1836 | | /// Face - Detect or (Large)FaceList - Add Face or (Large)PersonGroup - Add |
| | 1837 | | /// Face. The default value is 'detection_01', if another model is needed, |
| | 1838 | | /// please explicitly specify it. Possible values include: 'detection_01', |
| | 1839 | | /// 'detection_02' |
| | 1840 | | /// </param> |
| | 1841 | | /// <param name='customHeaders'> |
| | 1842 | | /// Headers that will be added to request. |
| | 1843 | | /// </param> |
| | 1844 | | /// <param name='cancellationToken'> |
| | 1845 | | /// The cancellation token. |
| | 1846 | | /// </param> |
| | 1847 | | /// <exception cref="APIErrorException"> |
| | 1848 | | /// Thrown when the operation returned an invalid status code |
| | 1849 | | /// </exception> |
| | 1850 | | /// <exception cref="SerializationException"> |
| | 1851 | | /// Thrown when unable to deserialize the response |
| | 1852 | | /// </exception> |
| | 1853 | | /// <exception cref="ValidationException"> |
| | 1854 | | /// Thrown when a required parameter is null |
| | 1855 | | /// </exception> |
| | 1856 | | /// <exception cref="System.ArgumentNullException"> |
| | 1857 | | /// Thrown when a required parameter is null |
| | 1858 | | /// </exception> |
| | 1859 | | /// <return> |
| | 1860 | | /// A response object containing the response body and response headers. |
| | 1861 | | /// </return> |
| | 1862 | | public async Task<HttpOperationResponse<PersistedFace>> AddFaceFromStreamWithHttpMessagesAsync(string personGrou |
| | 1863 | | { |
| 18 | 1864 | | if (Client.Endpoint == null) |
| | 1865 | | { |
| 0 | 1866 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Client.Endpoint"); |
| | 1867 | | } |
| 18 | 1868 | | if (personGroupId == null) |
| | 1869 | | { |
| 0 | 1870 | | throw new ValidationException(ValidationRules.CannotBeNull, "personGroupId"); |
| | 1871 | | } |
| 18 | 1872 | | if (personGroupId != null) |
| | 1873 | | { |
| 18 | 1874 | | if (personGroupId.Length > 64) |
| | 1875 | | { |
| 0 | 1876 | | throw new ValidationException(ValidationRules.MaxLength, "personGroupId", 64); |
| | 1877 | | } |
| 18 | 1878 | | if (!System.Text.RegularExpressions.Regex.IsMatch(personGroupId, "^[a-z0-9-_]+$")) |
| | 1879 | | { |
| 0 | 1880 | | throw new ValidationException(ValidationRules.Pattern, "personGroupId", "^[a-z0-9-_]+$"); |
| | 1881 | | } |
| | 1882 | | } |
| 18 | 1883 | | if (userData != null) |
| | 1884 | | { |
| 0 | 1885 | | if (userData.Length > 1024) |
| | 1886 | | { |
| 0 | 1887 | | throw new ValidationException(ValidationRules.MaxLength, "userData", 1024); |
| | 1888 | | } |
| | 1889 | | } |
| 18 | 1890 | | if (image == null) |
| | 1891 | | { |
| 0 | 1892 | | throw new ValidationException(ValidationRules.CannotBeNull, "image"); |
| | 1893 | | } |
| | 1894 | | // Tracing |
| 18 | 1895 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 18 | 1896 | | string _invocationId = null; |
| 18 | 1897 | | if (_shouldTrace) |
| | 1898 | | { |
| 0 | 1899 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1900 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1901 | | tracingParameters.Add("personGroupId", personGroupId); |
| 0 | 1902 | | tracingParameters.Add("personId", personId); |
| 0 | 1903 | | tracingParameters.Add("userData", userData); |
| 0 | 1904 | | tracingParameters.Add("targetFace", targetFace); |
| 0 | 1905 | | tracingParameters.Add("image", image); |
| 0 | 1906 | | tracingParameters.Add("detectionModel", detectionModel); |
| 0 | 1907 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1908 | | ServiceClientTracing.Enter(_invocationId, this, "AddFaceFromStream", tracingParameters); |
| | 1909 | | } |
| | 1910 | | // Construct URL |
| 18 | 1911 | | var _baseUrl = Client.BaseUri; |
| 18 | 1912 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "persongroups/{personGroupId}/persons/{personId} |
| 18 | 1913 | | _url = _url.Replace("{Endpoint}", Client.Endpoint); |
| 18 | 1914 | | _url = _url.Replace("{personGroupId}", System.Uri.EscapeDataString(personGroupId)); |
| 18 | 1915 | | _url = _url.Replace("{personId}", System.Uri.EscapeDataString(Rest.Serialization.SafeJsonConvert.SerializeOb |
| 18 | 1916 | | List<string> _queryParameters = new List<string>(); |
| 18 | 1917 | | if (userData != null) |
| | 1918 | | { |
| 0 | 1919 | | _queryParameters.Add(string.Format("userData={0}", System.Uri.EscapeDataString(userData))); |
| | 1920 | | } |
| 18 | 1921 | | if (targetFace != null) |
| | 1922 | | { |
| 12 | 1923 | | _queryParameters.Add(string.Format("targetFace={0}", System.Uri.EscapeDataString(string.Join(",", target |
| | 1924 | | } |
| 18 | 1925 | | if (detectionModel != null) |
| | 1926 | | { |
| 18 | 1927 | | _queryParameters.Add(string.Format("detectionModel={0}", System.Uri.EscapeDataString(detectionModel))); |
| | 1928 | | } |
| 18 | 1929 | | if (_queryParameters.Count > 0) |
| | 1930 | | { |
| 18 | 1931 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1932 | | } |
| | 1933 | | // Create HTTP transport objects |
| 18 | 1934 | | var _httpRequest = new HttpRequestMessage(); |
| 18 | 1935 | | HttpResponseMessage _httpResponse = null; |
| 18 | 1936 | | _httpRequest.Method = new HttpMethod("POST"); |
| 18 | 1937 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1938 | | // Set Headers |
| | 1939 | |
|
| | 1940 | |
|
| 18 | 1941 | | if (customHeaders != null) |
| | 1942 | | { |
| 0 | 1943 | | foreach(var _header in customHeaders) |
| | 1944 | | { |
| 0 | 1945 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1946 | | { |
| 0 | 1947 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1948 | | } |
| 0 | 1949 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1950 | | } |
| | 1951 | | } |
| | 1952 | |
|
| | 1953 | | // Serialize Request |
| 18 | 1954 | | string _requestContent = null; |
| 18 | 1955 | | if(image == null) |
| | 1956 | | { |
| 0 | 1957 | | throw new System.ArgumentNullException("image"); |
| | 1958 | | } |
| 18 | 1959 | | if (image != null && image != Stream.Null) |
| | 1960 | | { |
| 18 | 1961 | | _httpRequest.Content = new StreamContent(image); |
| 18 | 1962 | | _httpRequest.Content.Headers.ContentType =System.Net.Http.Headers.MediaTypeHeaderValue.Parse("applicatio |
| | 1963 | | } |
| | 1964 | | // Set Credentials |
| 18 | 1965 | | if (Client.Credentials != null) |
| | 1966 | | { |
| 18 | 1967 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 1968 | | await Client.Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1969 | | } |
| | 1970 | | // Send Request |
| 18 | 1971 | | if (_shouldTrace) |
| | 1972 | | { |
| 0 | 1973 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1974 | | } |
| 18 | 1975 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 1976 | | _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 18 | 1977 | | if (_shouldTrace) |
| | 1978 | | { |
| 0 | 1979 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1980 | | } |
| 18 | 1981 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 18 | 1982 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 1983 | | string _responseContent = null; |
| 18 | 1984 | | if ((int)_statusCode != 200) |
| | 1985 | | { |
| 0 | 1986 | | var ex = new APIErrorException(string.Format("Operation returned an invalid status code '{0}'", _statusC |
| | 1987 | | try |
| | 1988 | | { |
| 0 | 1989 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1990 | | APIError _errorBody = Rest.Serialization.SafeJsonConvert.DeserializeObject<APIError>(_responseConte |
| 0 | 1991 | | if (_errorBody != null) |
| | 1992 | | { |
| 0 | 1993 | | ex.Body = _errorBody; |
| | 1994 | | } |
| 0 | 1995 | | } |
| 0 | 1996 | | catch (JsonException) |
| | 1997 | | { |
| | 1998 | | // Ignore the exception |
| 0 | 1999 | | } |
| 0 | 2000 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2001 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2002 | | if (_shouldTrace) |
| | 2003 | | { |
| 0 | 2004 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2005 | | } |
| 0 | 2006 | | _httpRequest.Dispose(); |
| 0 | 2007 | | if (_httpResponse != null) |
| | 2008 | | { |
| 0 | 2009 | | _httpResponse.Dispose(); |
| | 2010 | | } |
| 0 | 2011 | | throw ex; |
| | 2012 | | } |
| | 2013 | | // Create Result |
| 18 | 2014 | | var _result = new HttpOperationResponse<PersistedFace>(); |
| 18 | 2015 | | _result.Request = _httpRequest; |
| 18 | 2016 | | _result.Response = _httpResponse; |
| | 2017 | | // Deserialize Response |
| 18 | 2018 | | if ((int)_statusCode == 200) |
| | 2019 | | { |
| 18 | 2020 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2021 | | try |
| | 2022 | | { |
| 18 | 2023 | | _result.Body = Rest.Serialization.SafeJsonConvert.DeserializeObject<PersistedFace>(_responseContent, |
| 18 | 2024 | | } |
| 0 | 2025 | | catch (JsonException ex) |
| | 2026 | | { |
| 0 | 2027 | | _httpRequest.Dispose(); |
| 0 | 2028 | | if (_httpResponse != null) |
| | 2029 | | { |
| 0 | 2030 | | _httpResponse.Dispose(); |
| | 2031 | | } |
| 0 | 2032 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2033 | | } |
| | 2034 | | } |
| 18 | 2035 | | if (_shouldTrace) |
| | 2036 | | { |
| 0 | 2037 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2038 | | } |
| 18 | 2039 | | return _result; |
| 18 | 2040 | | } |
| | 2041 | |
|
| | 2042 | | } |
| | 2043 | | } |