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