| | 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.CustomVision.Training |
| | 12 | | { |
| | 13 | | using Microsoft.Rest; |
| | 14 | | using Microsoft.Rest.Serialization; |
| | 15 | | using Models; |
| | 16 | | using Newtonsoft.Json; |
| | 17 | | using System.Collections; |
| | 18 | | using System.Collections.Generic; |
| | 19 | | using System.IO; |
| | 20 | | using System.Net; |
| | 21 | | using System.Net.Http; |
| | 22 | | using System.Net.Http.Headers; |
| | 23 | | using System.Threading; |
| | 24 | | using System.Threading.Tasks; |
| | 25 | |
|
| | 26 | | public partial class CustomVisionTrainingClient : ServiceClient<CustomVisionTrainingClient>, ICustomVisionTrainingCl |
| | 27 | | { |
| | 28 | | /// <summary> |
| | 29 | | /// The base URI of the service. |
| | 30 | | /// </summary> |
| 330 | 31 | | internal string BaseUri {get; set;} |
| | 32 | |
|
| | 33 | | /// <summary> |
| | 34 | | /// Gets or sets json serialization settings. |
| | 35 | | /// </summary> |
| 530 | 36 | | public JsonSerializerSettings SerializationSettings { get; private set; } |
| | 37 | |
|
| | 38 | | /// <summary> |
| | 39 | | /// Gets or sets json deserialization settings. |
| | 40 | | /// </summary> |
| 294 | 41 | | public JsonSerializerSettings DeserializationSettings { get; private set; } |
| | 42 | |
|
| | 43 | | /// <summary> |
| | 44 | | /// Supported Cognitive Services endpoints. |
| | 45 | | /// </summary> |
| 594 | 46 | | public string Endpoint { get; set; } |
| | 47 | |
|
| | 48 | | /// <summary> |
| | 49 | | /// Subscription credentials which uniquely identify client subscription. |
| | 50 | | /// </summary> |
| 726 | 51 | | public ServiceClientCredentials Credentials { get; private set; } |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Initializes a new instance of the CustomVisionTrainingClient class. |
| | 55 | | /// </summary> |
| | 56 | | /// <param name='httpClient'> |
| | 57 | | /// HttpClient to be used |
| | 58 | | /// </param> |
| | 59 | | /// <param name='disposeHttpClient'> |
| | 60 | | /// True: will dispose the provided httpClient on calling CustomVisionTrainingClient.Dispose(). False: will not |
| 0 | 61 | | protected CustomVisionTrainingClient(HttpClient httpClient, bool disposeHttpClient) : base(httpClient, disposeHt |
| | 62 | | { |
| 0 | 63 | | Initialize(); |
| 0 | 64 | | } |
| | 65 | |
|
| | 66 | | /// <summary> |
| | 67 | | /// Initializes a new instance of the CustomVisionTrainingClient class. |
| | 68 | | /// </summary> |
| | 69 | | /// <param name='handlers'> |
| | 70 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 71 | | /// </param> |
| 66 | 72 | | protected CustomVisionTrainingClient(params DelegatingHandler[] handlers) : base(handlers) |
| | 73 | | { |
| 66 | 74 | | Initialize(); |
| 66 | 75 | | } |
| | 76 | |
|
| | 77 | | /// <summary> |
| | 78 | | /// Initializes a new instance of the CustomVisionTrainingClient class. |
| | 79 | | /// </summary> |
| | 80 | | /// <param name='rootHandler'> |
| | 81 | | /// Optional. The http client handler used to handle http transport. |
| | 82 | | /// </param> |
| | 83 | | /// <param name='handlers'> |
| | 84 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 85 | | /// </param> |
| 0 | 86 | | protected CustomVisionTrainingClient(HttpClientHandler rootHandler, params DelegatingHandler[] handlers) : base( |
| | 87 | | { |
| 0 | 88 | | Initialize(); |
| 0 | 89 | | } |
| | 90 | |
|
| | 91 | | /// <summary> |
| | 92 | | /// Initializes a new instance of the CustomVisionTrainingClient class. |
| | 93 | | /// </summary> |
| | 94 | | /// <param name='credentials'> |
| | 95 | | /// Required. Subscription credentials which uniquely identify client subscription. |
| | 96 | | /// </param> |
| | 97 | | /// <param name='handlers'> |
| | 98 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 99 | | /// </param> |
| | 100 | | /// <exception cref="System.ArgumentNullException"> |
| | 101 | | /// Thrown when a required parameter is null |
| | 102 | | /// </exception> |
| 66 | 103 | | public CustomVisionTrainingClient(ServiceClientCredentials credentials, params DelegatingHandler[] handlers) : t |
| | 104 | | { |
| 66 | 105 | | if (credentials == null) |
| | 106 | | { |
| 0 | 107 | | throw new System.ArgumentNullException("credentials"); |
| | 108 | | } |
| 66 | 109 | | Credentials = credentials; |
| 66 | 110 | | if (Credentials != null) |
| | 111 | | { |
| 66 | 112 | | Credentials.InitializeServiceClient(this); |
| | 113 | | } |
| 66 | 114 | | } |
| | 115 | |
|
| | 116 | | /// <summary> |
| | 117 | | /// Initializes a new instance of the CustomVisionTrainingClient class. |
| | 118 | | /// </summary> |
| | 119 | | /// <param name='credentials'> |
| | 120 | | /// Required. Subscription credentials which uniquely identify client subscription. |
| | 121 | | /// </param> |
| | 122 | | /// <param name='httpClient'> |
| | 123 | | /// HttpClient to be used |
| | 124 | | /// </param> |
| | 125 | | /// <param name='disposeHttpClient'> |
| | 126 | | /// True: will dispose the provided httpClient on calling CustomVisionTrainingClient.Dispose(). False: will not |
| | 127 | | /// <exception cref="System.ArgumentNullException"> |
| | 128 | | /// Thrown when a required parameter is null |
| | 129 | | /// </exception> |
| 0 | 130 | | public CustomVisionTrainingClient(ServiceClientCredentials credentials, HttpClient httpClient, bool disposeHttpC |
| | 131 | | { |
| 0 | 132 | | if (credentials == null) |
| | 133 | | { |
| 0 | 134 | | throw new System.ArgumentNullException("credentials"); |
| | 135 | | } |
| 0 | 136 | | Credentials = credentials; |
| 0 | 137 | | if (Credentials != null) |
| | 138 | | { |
| 0 | 139 | | Credentials.InitializeServiceClient(this); |
| | 140 | | } |
| 0 | 141 | | } |
| | 142 | |
|
| | 143 | | /// <summary> |
| | 144 | | /// Initializes a new instance of the CustomVisionTrainingClient class. |
| | 145 | | /// </summary> |
| | 146 | | /// <param name='credentials'> |
| | 147 | | /// Required. Subscription credentials which uniquely identify client subscription. |
| | 148 | | /// </param> |
| | 149 | | /// <param name='rootHandler'> |
| | 150 | | /// Optional. The http client handler used to handle http transport. |
| | 151 | | /// </param> |
| | 152 | | /// <param name='handlers'> |
| | 153 | | /// Optional. The delegating handlers to add to the http client pipeline. |
| | 154 | | /// </param> |
| | 155 | | /// <exception cref="System.ArgumentNullException"> |
| | 156 | | /// Thrown when a required parameter is null |
| | 157 | | /// </exception> |
| 0 | 158 | | public CustomVisionTrainingClient(ServiceClientCredentials credentials, HttpClientHandler rootHandler, params De |
| | 159 | | { |
| 0 | 160 | | if (credentials == null) |
| | 161 | | { |
| 0 | 162 | | throw new System.ArgumentNullException("credentials"); |
| | 163 | | } |
| 0 | 164 | | Credentials = credentials; |
| 0 | 165 | | if (Credentials != null) |
| | 166 | | { |
| 0 | 167 | | Credentials.InitializeServiceClient(this); |
| | 168 | | } |
| 0 | 169 | | } |
| | 170 | |
|
| | 171 | | /// <summary> |
| | 172 | | /// An optional partial-method to perform custom initialization. |
| | 173 | | ///</summary> |
| | 174 | | partial void CustomInitialize(); |
| | 175 | | /// <summary> |
| | 176 | | /// Initializes client properties. |
| | 177 | | /// </summary> |
| | 178 | | private void Initialize() |
| | 179 | | { |
| 66 | 180 | | BaseUri = "{Endpoint}/customvision/v3.3/training"; |
| 66 | 181 | | SerializationSettings = new JsonSerializerSettings |
| 66 | 182 | | { |
| 66 | 183 | | Formatting = Newtonsoft.Json.Formatting.Indented, |
| 66 | 184 | | DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, |
| 66 | 185 | | DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, |
| 66 | 186 | | NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, |
| 66 | 187 | | ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, |
| 66 | 188 | | ContractResolver = new ReadOnlyJsonContractResolver(), |
| 66 | 189 | | Converters = new List<JsonConverter> |
| 66 | 190 | | { |
| 66 | 191 | | new Iso8601TimeSpanConverter() |
| 66 | 192 | | } |
| 66 | 193 | | }; |
| 66 | 194 | | DeserializationSettings = new JsonSerializerSettings |
| 66 | 195 | | { |
| 66 | 196 | | DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat, |
| 66 | 197 | | DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc, |
| 66 | 198 | | NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, |
| 66 | 199 | | ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Serialize, |
| 66 | 200 | | ContractResolver = new ReadOnlyJsonContractResolver(), |
| 66 | 201 | | Converters = new List<JsonConverter> |
| 66 | 202 | | { |
| 66 | 203 | | new Iso8601TimeSpanConverter() |
| 66 | 204 | | } |
| 66 | 205 | | }; |
| | 206 | | CustomInitialize(); |
| 66 | 207 | | } |
| | 208 | | /// <summary> |
| | 209 | | /// Get a list of the available domains. |
| | 210 | | /// </summary> |
| | 211 | | /// <param name='customHeaders'> |
| | 212 | | /// Headers that will be added to request. |
| | 213 | | /// </param> |
| | 214 | | /// <param name='cancellationToken'> |
| | 215 | | /// The cancellation token. |
| | 216 | | /// </param> |
| | 217 | | /// <exception cref="CustomVisionErrorException"> |
| | 218 | | /// Thrown when the operation returned an invalid status code |
| | 219 | | /// </exception> |
| | 220 | | /// <exception cref="SerializationException"> |
| | 221 | | /// Thrown when unable to deserialize the response |
| | 222 | | /// </exception> |
| | 223 | | /// <exception cref="ValidationException"> |
| | 224 | | /// Thrown when a required parameter is null |
| | 225 | | /// </exception> |
| | 226 | | /// <exception cref="System.ArgumentNullException"> |
| | 227 | | /// Thrown when a required parameter is null |
| | 228 | | /// </exception> |
| | 229 | | /// <return> |
| | 230 | | /// A response object containing the response body and response headers. |
| | 231 | | /// </return> |
| | 232 | | public async Task<HttpOperationResponse<IList<Domain>>> GetDomainsWithHttpMessagesAsync(Dictionary<string, List< |
| | 233 | | { |
| 2 | 234 | | if (Endpoint == null) |
| | 235 | | { |
| 0 | 236 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 237 | | } |
| | 238 | | // Tracing |
| 2 | 239 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 240 | | string _invocationId = null; |
| 2 | 241 | | if (_shouldTrace) |
| | 242 | | { |
| 0 | 243 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 244 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 245 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 246 | | ServiceClientTracing.Enter(_invocationId, this, "GetDomains", tracingParameters); |
| | 247 | | } |
| | 248 | | // Construct URL |
| 2 | 249 | | var _baseUrl = BaseUri; |
| 2 | 250 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "domains"; |
| 2 | 251 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| | 252 | | // Create HTTP transport objects |
| 2 | 253 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 254 | | HttpResponseMessage _httpResponse = null; |
| 2 | 255 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 256 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 257 | | // Set Headers |
| | 258 | |
|
| | 259 | |
|
| 2 | 260 | | if (customHeaders != null) |
| | 261 | | { |
| 0 | 262 | | foreach(var _header in customHeaders) |
| | 263 | | { |
| 0 | 264 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 265 | | { |
| 0 | 266 | | _httpRequest.Headers.Remove(_header.Key); |
| | 267 | | } |
| 0 | 268 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 269 | | } |
| | 270 | | } |
| | 271 | |
|
| | 272 | | // Serialize Request |
| 2 | 273 | | string _requestContent = null; |
| | 274 | | // Set Credentials |
| 2 | 275 | | if (Credentials != null) |
| | 276 | | { |
| 2 | 277 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 278 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 279 | | } |
| | 280 | | // Send Request |
| 2 | 281 | | if (_shouldTrace) |
| | 282 | | { |
| 0 | 283 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 284 | | } |
| 2 | 285 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 286 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 287 | | if (_shouldTrace) |
| | 288 | | { |
| 0 | 289 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 290 | | } |
| 2 | 291 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 292 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 293 | | string _responseContent = null; |
| 2 | 294 | | if ((int)_statusCode != 200) |
| | 295 | | { |
| 0 | 296 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 297 | | try |
| | 298 | | { |
| 0 | 299 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 300 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 301 | | if (_errorBody != null) |
| | 302 | | { |
| 0 | 303 | | ex.Body = _errorBody; |
| | 304 | | } |
| 0 | 305 | | } |
| 0 | 306 | | catch (JsonException) |
| | 307 | | { |
| | 308 | | // Ignore the exception |
| 0 | 309 | | } |
| 0 | 310 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 311 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 312 | | if (_shouldTrace) |
| | 313 | | { |
| 0 | 314 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 315 | | } |
| 0 | 316 | | _httpRequest.Dispose(); |
| 0 | 317 | | if (_httpResponse != null) |
| | 318 | | { |
| 0 | 319 | | _httpResponse.Dispose(); |
| | 320 | | } |
| 0 | 321 | | throw ex; |
| | 322 | | } |
| | 323 | | // Create Result |
| 2 | 324 | | var _result = new HttpOperationResponse<IList<Domain>>(); |
| 2 | 325 | | _result.Request = _httpRequest; |
| 2 | 326 | | _result.Response = _httpResponse; |
| | 327 | | // Deserialize Response |
| 2 | 328 | | if ((int)_statusCode == 200) |
| | 329 | | { |
| 2 | 330 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 331 | | try |
| | 332 | | { |
| 2 | 333 | | _result.Body = SafeJsonConvert.DeserializeObject<IList<Domain>>(_responseContent, DeserializationSet |
| 2 | 334 | | } |
| 0 | 335 | | catch (JsonException ex) |
| | 336 | | { |
| 0 | 337 | | _httpRequest.Dispose(); |
| 0 | 338 | | if (_httpResponse != null) |
| | 339 | | { |
| 0 | 340 | | _httpResponse.Dispose(); |
| | 341 | | } |
| 0 | 342 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 343 | | } |
| | 344 | | } |
| 2 | 345 | | if (_shouldTrace) |
| | 346 | | { |
| 0 | 347 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 348 | | } |
| 2 | 349 | | return _result; |
| 2 | 350 | | } |
| | 351 | |
|
| | 352 | | /// <summary> |
| | 353 | | /// Get information about a specific domain. |
| | 354 | | /// </summary> |
| | 355 | | /// <param name='domainId'> |
| | 356 | | /// The id of the domain to get information about. |
| | 357 | | /// </param> |
| | 358 | | /// <param name='customHeaders'> |
| | 359 | | /// Headers that will be added to request. |
| | 360 | | /// </param> |
| | 361 | | /// <param name='cancellationToken'> |
| | 362 | | /// The cancellation token. |
| | 363 | | /// </param> |
| | 364 | | /// <exception cref="CustomVisionErrorException"> |
| | 365 | | /// Thrown when the operation returned an invalid status code |
| | 366 | | /// </exception> |
| | 367 | | /// <exception cref="SerializationException"> |
| | 368 | | /// Thrown when unable to deserialize the response |
| | 369 | | /// </exception> |
| | 370 | | /// <exception cref="ValidationException"> |
| | 371 | | /// Thrown when a required parameter is null |
| | 372 | | /// </exception> |
| | 373 | | /// <exception cref="System.ArgumentNullException"> |
| | 374 | | /// Thrown when a required parameter is null |
| | 375 | | /// </exception> |
| | 376 | | /// <return> |
| | 377 | | /// A response object containing the response body and response headers. |
| | 378 | | /// </return> |
| | 379 | | public async Task<HttpOperationResponse<Domain>> GetDomainWithHttpMessagesAsync(System.Guid domainId, Dictionary |
| | 380 | | { |
| 2 | 381 | | if (Endpoint == null) |
| | 382 | | { |
| 0 | 383 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 384 | | } |
| | 385 | | // Tracing |
| 2 | 386 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 387 | | string _invocationId = null; |
| 2 | 388 | | if (_shouldTrace) |
| | 389 | | { |
| 0 | 390 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 391 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 392 | | tracingParameters.Add("domainId", domainId); |
| 0 | 393 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 394 | | ServiceClientTracing.Enter(_invocationId, this, "GetDomain", tracingParameters); |
| | 395 | | } |
| | 396 | | // Construct URL |
| 2 | 397 | | var _baseUrl = BaseUri; |
| 2 | 398 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "domains/{domainId}"; |
| 2 | 399 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 400 | | _url = _url.Replace("{domainId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(domainId, Seri |
| | 401 | | // Create HTTP transport objects |
| 2 | 402 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 403 | | HttpResponseMessage _httpResponse = null; |
| 2 | 404 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 405 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 406 | | // Set Headers |
| | 407 | |
|
| | 408 | |
|
| 2 | 409 | | if (customHeaders != null) |
| | 410 | | { |
| 0 | 411 | | foreach(var _header in customHeaders) |
| | 412 | | { |
| 0 | 413 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 414 | | { |
| 0 | 415 | | _httpRequest.Headers.Remove(_header.Key); |
| | 416 | | } |
| 0 | 417 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 418 | | } |
| | 419 | | } |
| | 420 | |
|
| | 421 | | // Serialize Request |
| 2 | 422 | | string _requestContent = null; |
| | 423 | | // Set Credentials |
| 2 | 424 | | if (Credentials != null) |
| | 425 | | { |
| 2 | 426 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 427 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 428 | | } |
| | 429 | | // Send Request |
| 2 | 430 | | if (_shouldTrace) |
| | 431 | | { |
| 0 | 432 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 433 | | } |
| 2 | 434 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 435 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 436 | | if (_shouldTrace) |
| | 437 | | { |
| 0 | 438 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 439 | | } |
| 2 | 440 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 441 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 442 | | string _responseContent = null; |
| 2 | 443 | | if ((int)_statusCode != 200) |
| | 444 | | { |
| 0 | 445 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 446 | | try |
| | 447 | | { |
| 0 | 448 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 449 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 450 | | if (_errorBody != null) |
| | 451 | | { |
| 0 | 452 | | ex.Body = _errorBody; |
| | 453 | | } |
| 0 | 454 | | } |
| 0 | 455 | | catch (JsonException) |
| | 456 | | { |
| | 457 | | // Ignore the exception |
| 0 | 458 | | } |
| 0 | 459 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 460 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 461 | | if (_shouldTrace) |
| | 462 | | { |
| 0 | 463 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 464 | | } |
| 0 | 465 | | _httpRequest.Dispose(); |
| 0 | 466 | | if (_httpResponse != null) |
| | 467 | | { |
| 0 | 468 | | _httpResponse.Dispose(); |
| | 469 | | } |
| 0 | 470 | | throw ex; |
| | 471 | | } |
| | 472 | | // Create Result |
| 2 | 473 | | var _result = new HttpOperationResponse<Domain>(); |
| 2 | 474 | | _result.Request = _httpRequest; |
| 2 | 475 | | _result.Response = _httpResponse; |
| | 476 | | // Deserialize Response |
| 2 | 477 | | if ((int)_statusCode == 200) |
| | 478 | | { |
| 2 | 479 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 480 | | try |
| | 481 | | { |
| 2 | 482 | | _result.Body = SafeJsonConvert.DeserializeObject<Domain>(_responseContent, DeserializationSettings); |
| 2 | 483 | | } |
| 0 | 484 | | catch (JsonException ex) |
| | 485 | | { |
| 0 | 486 | | _httpRequest.Dispose(); |
| 0 | 487 | | if (_httpResponse != null) |
| | 488 | | { |
| 0 | 489 | | _httpResponse.Dispose(); |
| | 490 | | } |
| 0 | 491 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 492 | | } |
| | 493 | | } |
| 2 | 494 | | if (_shouldTrace) |
| | 495 | | { |
| 0 | 496 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 497 | | } |
| 2 | 498 | | return _result; |
| 2 | 499 | | } |
| | 500 | |
|
| | 501 | | /// <summary> |
| | 502 | | /// Get your projects. |
| | 503 | | /// </summary> |
| | 504 | | /// <param name='customHeaders'> |
| | 505 | | /// Headers that will be added to request. |
| | 506 | | /// </param> |
| | 507 | | /// <param name='cancellationToken'> |
| | 508 | | /// The cancellation token. |
| | 509 | | /// </param> |
| | 510 | | /// <exception cref="CustomVisionErrorException"> |
| | 511 | | /// Thrown when the operation returned an invalid status code |
| | 512 | | /// </exception> |
| | 513 | | /// <exception cref="SerializationException"> |
| | 514 | | /// Thrown when unable to deserialize the response |
| | 515 | | /// </exception> |
| | 516 | | /// <exception cref="ValidationException"> |
| | 517 | | /// Thrown when a required parameter is null |
| | 518 | | /// </exception> |
| | 519 | | /// <exception cref="System.ArgumentNullException"> |
| | 520 | | /// Thrown when a required parameter is null |
| | 521 | | /// </exception> |
| | 522 | | /// <return> |
| | 523 | | /// A response object containing the response body and response headers. |
| | 524 | | /// </return> |
| | 525 | | public async Task<HttpOperationResponse<IList<Project>>> GetProjectsWithHttpMessagesAsync(Dictionary<string, Lis |
| | 526 | | { |
| 2 | 527 | | if (Endpoint == null) |
| | 528 | | { |
| 0 | 529 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 530 | | } |
| | 531 | | // Tracing |
| 2 | 532 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 533 | | string _invocationId = null; |
| 2 | 534 | | if (_shouldTrace) |
| | 535 | | { |
| 0 | 536 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 537 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 538 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 539 | | ServiceClientTracing.Enter(_invocationId, this, "GetProjects", tracingParameters); |
| | 540 | | } |
| | 541 | | // Construct URL |
| 2 | 542 | | var _baseUrl = BaseUri; |
| 2 | 543 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects"; |
| 2 | 544 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| | 545 | | // Create HTTP transport objects |
| 2 | 546 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 547 | | HttpResponseMessage _httpResponse = null; |
| 2 | 548 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 549 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 550 | | // Set Headers |
| | 551 | |
|
| | 552 | |
|
| 2 | 553 | | if (customHeaders != null) |
| | 554 | | { |
| 0 | 555 | | foreach(var _header in customHeaders) |
| | 556 | | { |
| 0 | 557 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 558 | | { |
| 0 | 559 | | _httpRequest.Headers.Remove(_header.Key); |
| | 560 | | } |
| 0 | 561 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 562 | | } |
| | 563 | | } |
| | 564 | |
|
| | 565 | | // Serialize Request |
| 2 | 566 | | string _requestContent = null; |
| | 567 | | // Set Credentials |
| 2 | 568 | | if (Credentials != null) |
| | 569 | | { |
| 2 | 570 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 571 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 572 | | } |
| | 573 | | // Send Request |
| 2 | 574 | | if (_shouldTrace) |
| | 575 | | { |
| 0 | 576 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 577 | | } |
| 2 | 578 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 579 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 580 | | if (_shouldTrace) |
| | 581 | | { |
| 0 | 582 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 583 | | } |
| 2 | 584 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 585 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 586 | | string _responseContent = null; |
| 2 | 587 | | if ((int)_statusCode != 200) |
| | 588 | | { |
| 0 | 589 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 590 | | try |
| | 591 | | { |
| 0 | 592 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 593 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 594 | | if (_errorBody != null) |
| | 595 | | { |
| 0 | 596 | | ex.Body = _errorBody; |
| | 597 | | } |
| 0 | 598 | | } |
| 0 | 599 | | catch (JsonException) |
| | 600 | | { |
| | 601 | | // Ignore the exception |
| 0 | 602 | | } |
| 0 | 603 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 604 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 605 | | if (_shouldTrace) |
| | 606 | | { |
| 0 | 607 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 608 | | } |
| 0 | 609 | | _httpRequest.Dispose(); |
| 0 | 610 | | if (_httpResponse != null) |
| | 611 | | { |
| 0 | 612 | | _httpResponse.Dispose(); |
| | 613 | | } |
| 0 | 614 | | throw ex; |
| | 615 | | } |
| | 616 | | // Create Result |
| 2 | 617 | | var _result = new HttpOperationResponse<IList<Project>>(); |
| 2 | 618 | | _result.Request = _httpRequest; |
| 2 | 619 | | _result.Response = _httpResponse; |
| | 620 | | // Deserialize Response |
| 2 | 621 | | if ((int)_statusCode == 200) |
| | 622 | | { |
| 2 | 623 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 624 | | try |
| | 625 | | { |
| 2 | 626 | | _result.Body = SafeJsonConvert.DeserializeObject<IList<Project>>(_responseContent, DeserializationSe |
| 2 | 627 | | } |
| 0 | 628 | | catch (JsonException ex) |
| | 629 | | { |
| 0 | 630 | | _httpRequest.Dispose(); |
| 0 | 631 | | if (_httpResponse != null) |
| | 632 | | { |
| 0 | 633 | | _httpResponse.Dispose(); |
| | 634 | | } |
| 0 | 635 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 636 | | } |
| | 637 | | } |
| 2 | 638 | | if (_shouldTrace) |
| | 639 | | { |
| 0 | 640 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 641 | | } |
| 2 | 642 | | return _result; |
| 2 | 643 | | } |
| | 644 | |
|
| | 645 | | /// <summary> |
| | 646 | | /// Create a project. |
| | 647 | | /// </summary> |
| | 648 | | /// <param name='name'> |
| | 649 | | /// Name of the project. |
| | 650 | | /// </param> |
| | 651 | | /// <param name='description'> |
| | 652 | | /// The description of the project. |
| | 653 | | /// </param> |
| | 654 | | /// <param name='domainId'> |
| | 655 | | /// The id of the domain to use for this project. Defaults to General. |
| | 656 | | /// </param> |
| | 657 | | /// <param name='classificationType'> |
| | 658 | | /// The type of classifier to create for this project. Possible values include: |
| | 659 | | /// 'Multiclass', 'Multilabel' |
| | 660 | | /// </param> |
| | 661 | | /// <param name='targetExportPlatforms'> |
| | 662 | | /// List of platforms the trained model is intending exporting to. |
| | 663 | | /// </param> |
| | 664 | | /// <param name='customHeaders'> |
| | 665 | | /// Headers that will be added to request. |
| | 666 | | /// </param> |
| | 667 | | /// <param name='cancellationToken'> |
| | 668 | | /// The cancellation token. |
| | 669 | | /// </param> |
| | 670 | | /// <exception cref="CustomVisionErrorException"> |
| | 671 | | /// Thrown when the operation returned an invalid status code |
| | 672 | | /// </exception> |
| | 673 | | /// <exception cref="SerializationException"> |
| | 674 | | /// Thrown when unable to deserialize the response |
| | 675 | | /// </exception> |
| | 676 | | /// <exception cref="ValidationException"> |
| | 677 | | /// Thrown when a required parameter is null |
| | 678 | | /// </exception> |
| | 679 | | /// <exception cref="System.ArgumentNullException"> |
| | 680 | | /// Thrown when a required parameter is null |
| | 681 | | /// </exception> |
| | 682 | | /// <return> |
| | 683 | | /// A response object containing the response body and response headers. |
| | 684 | | /// </return> |
| | 685 | | public async Task<HttpOperationResponse<Project>> CreateProjectWithHttpMessagesAsync(string name, string descrip |
| | 686 | | { |
| 18 | 687 | | if (Endpoint == null) |
| | 688 | | { |
| 0 | 689 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 690 | | } |
| 18 | 691 | | if (name == null) |
| | 692 | | { |
| 0 | 693 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 694 | | } |
| | 695 | | // Tracing |
| 18 | 696 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 18 | 697 | | string _invocationId = null; |
| 18 | 698 | | if (_shouldTrace) |
| | 699 | | { |
| 0 | 700 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 701 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 702 | | tracingParameters.Add("name", name); |
| 0 | 703 | | tracingParameters.Add("description", description); |
| 0 | 704 | | tracingParameters.Add("domainId", domainId); |
| 0 | 705 | | tracingParameters.Add("classificationType", classificationType); |
| 0 | 706 | | tracingParameters.Add("targetExportPlatforms", targetExportPlatforms); |
| 0 | 707 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 708 | | ServiceClientTracing.Enter(_invocationId, this, "CreateProject", tracingParameters); |
| | 709 | | } |
| | 710 | | // Construct URL |
| 18 | 711 | | var _baseUrl = BaseUri; |
| 18 | 712 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects"; |
| 18 | 713 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 18 | 714 | | List<string> _queryParameters = new List<string>(); |
| 18 | 715 | | if (name != null) |
| | 716 | | { |
| 18 | 717 | | _queryParameters.Add(string.Format("name={0}", System.Uri.EscapeDataString(name))); |
| | 718 | | } |
| 18 | 719 | | if (description != null) |
| | 720 | | { |
| 14 | 721 | | _queryParameters.Add(string.Format("description={0}", System.Uri.EscapeDataString(description))); |
| | 722 | | } |
| 18 | 723 | | if (domainId != null) |
| | 724 | | { |
| 12 | 725 | | _queryParameters.Add(string.Format("domainId={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serialize |
| | 726 | | } |
| 18 | 727 | | if (classificationType != null) |
| | 728 | | { |
| 0 | 729 | | _queryParameters.Add(string.Format("classificationType={0}", System.Uri.EscapeDataString(SafeJsonConvert |
| | 730 | | } |
| 18 | 731 | | if (targetExportPlatforms != null) |
| | 732 | | { |
| 0 | 733 | | _queryParameters.Add(string.Format("targetExportPlatforms={0}", System.Uri.EscapeDataString(string.Join( |
| | 734 | | } |
| 18 | 735 | | if (_queryParameters.Count > 0) |
| | 736 | | { |
| 18 | 737 | | _url += "?" + string.Join("&", _queryParameters); |
| | 738 | | } |
| | 739 | | // Create HTTP transport objects |
| 18 | 740 | | var _httpRequest = new HttpRequestMessage(); |
| 18 | 741 | | HttpResponseMessage _httpResponse = null; |
| 18 | 742 | | _httpRequest.Method = new HttpMethod("POST"); |
| 18 | 743 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 744 | | // Set Headers |
| | 745 | |
|
| | 746 | |
|
| 18 | 747 | | if (customHeaders != null) |
| | 748 | | { |
| 0 | 749 | | foreach(var _header in customHeaders) |
| | 750 | | { |
| 0 | 751 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 752 | | { |
| 0 | 753 | | _httpRequest.Headers.Remove(_header.Key); |
| | 754 | | } |
| 0 | 755 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 756 | | } |
| | 757 | | } |
| | 758 | |
|
| | 759 | | // Serialize Request |
| 18 | 760 | | string _requestContent = null; |
| | 761 | | // Set Credentials |
| 18 | 762 | | if (Credentials != null) |
| | 763 | | { |
| 18 | 764 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 765 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 766 | | } |
| | 767 | | // Send Request |
| 18 | 768 | | if (_shouldTrace) |
| | 769 | | { |
| 0 | 770 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 771 | | } |
| 18 | 772 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 773 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 18 | 774 | | if (_shouldTrace) |
| | 775 | | { |
| 0 | 776 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 777 | | } |
| 18 | 778 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 18 | 779 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 780 | | string _responseContent = null; |
| 18 | 781 | | if ((int)_statusCode != 200) |
| | 782 | | { |
| 0 | 783 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 784 | | try |
| | 785 | | { |
| 0 | 786 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 787 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 788 | | if (_errorBody != null) |
| | 789 | | { |
| 0 | 790 | | ex.Body = _errorBody; |
| | 791 | | } |
| 0 | 792 | | } |
| 0 | 793 | | catch (JsonException) |
| | 794 | | { |
| | 795 | | // Ignore the exception |
| 0 | 796 | | } |
| 0 | 797 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 798 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 799 | | if (_shouldTrace) |
| | 800 | | { |
| 0 | 801 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 802 | | } |
| 0 | 803 | | _httpRequest.Dispose(); |
| 0 | 804 | | if (_httpResponse != null) |
| | 805 | | { |
| 0 | 806 | | _httpResponse.Dispose(); |
| | 807 | | } |
| 0 | 808 | | throw ex; |
| | 809 | | } |
| | 810 | | // Create Result |
| 18 | 811 | | var _result = new HttpOperationResponse<Project>(); |
| 18 | 812 | | _result.Request = _httpRequest; |
| 18 | 813 | | _result.Response = _httpResponse; |
| | 814 | | // Deserialize Response |
| 18 | 815 | | if ((int)_statusCode == 200) |
| | 816 | | { |
| 18 | 817 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 818 | | try |
| | 819 | | { |
| 18 | 820 | | _result.Body = SafeJsonConvert.DeserializeObject<Project>(_responseContent, DeserializationSettings) |
| 18 | 821 | | } |
| 0 | 822 | | catch (JsonException ex) |
| | 823 | | { |
| 0 | 824 | | _httpRequest.Dispose(); |
| 0 | 825 | | if (_httpResponse != null) |
| | 826 | | { |
| 0 | 827 | | _httpResponse.Dispose(); |
| | 828 | | } |
| 0 | 829 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 830 | | } |
| | 831 | | } |
| 18 | 832 | | if (_shouldTrace) |
| | 833 | | { |
| 0 | 834 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 835 | | } |
| 18 | 836 | | return _result; |
| 18 | 837 | | } |
| | 838 | |
|
| | 839 | | /// <summary> |
| | 840 | | /// Get a specific project. |
| | 841 | | /// </summary> |
| | 842 | | /// <param name='projectId'> |
| | 843 | | /// The id of the project to get. |
| | 844 | | /// </param> |
| | 845 | | /// <param name='customHeaders'> |
| | 846 | | /// Headers that will be added to request. |
| | 847 | | /// </param> |
| | 848 | | /// <param name='cancellationToken'> |
| | 849 | | /// The cancellation token. |
| | 850 | | /// </param> |
| | 851 | | /// <exception cref="CustomVisionErrorException"> |
| | 852 | | /// Thrown when the operation returned an invalid status code |
| | 853 | | /// </exception> |
| | 854 | | /// <exception cref="SerializationException"> |
| | 855 | | /// Thrown when unable to deserialize the response |
| | 856 | | /// </exception> |
| | 857 | | /// <exception cref="ValidationException"> |
| | 858 | | /// Thrown when a required parameter is null |
| | 859 | | /// </exception> |
| | 860 | | /// <exception cref="System.ArgumentNullException"> |
| | 861 | | /// Thrown when a required parameter is null |
| | 862 | | /// </exception> |
| | 863 | | /// <return> |
| | 864 | | /// A response object containing the response body and response headers. |
| | 865 | | /// </return> |
| | 866 | | public async Task<HttpOperationResponse<Project>> GetProjectWithHttpMessagesAsync(System.Guid projectId, Diction |
| | 867 | | { |
| 4 | 868 | | if (Endpoint == null) |
| | 869 | | { |
| 0 | 870 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 871 | | } |
| | 872 | | // Tracing |
| 4 | 873 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 874 | | string _invocationId = null; |
| 4 | 875 | | if (_shouldTrace) |
| | 876 | | { |
| 0 | 877 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 878 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 879 | | tracingParameters.Add("projectId", projectId); |
| 0 | 880 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 881 | | ServiceClientTracing.Enter(_invocationId, this, "GetProject", tracingParameters); |
| | 882 | | } |
| | 883 | | // Construct URL |
| 4 | 884 | | var _baseUrl = BaseUri; |
| 4 | 885 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}"; |
| 4 | 886 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 4 | 887 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| | 888 | | // Create HTTP transport objects |
| 4 | 889 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 890 | | HttpResponseMessage _httpResponse = null; |
| 4 | 891 | | _httpRequest.Method = new HttpMethod("GET"); |
| 4 | 892 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 893 | | // Set Headers |
| | 894 | |
|
| | 895 | |
|
| 4 | 896 | | if (customHeaders != null) |
| | 897 | | { |
| 0 | 898 | | foreach(var _header in customHeaders) |
| | 899 | | { |
| 0 | 900 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 901 | | { |
| 0 | 902 | | _httpRequest.Headers.Remove(_header.Key); |
| | 903 | | } |
| 0 | 904 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 905 | | } |
| | 906 | | } |
| | 907 | |
|
| | 908 | | // Serialize Request |
| 4 | 909 | | string _requestContent = null; |
| | 910 | | // Set Credentials |
| 4 | 911 | | if (Credentials != null) |
| | 912 | | { |
| 4 | 913 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 914 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 915 | | } |
| | 916 | | // Send Request |
| 4 | 917 | | if (_shouldTrace) |
| | 918 | | { |
| 0 | 919 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 920 | | } |
| 4 | 921 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 922 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 923 | | if (_shouldTrace) |
| | 924 | | { |
| 0 | 925 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 926 | | } |
| 4 | 927 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 928 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 929 | | string _responseContent = null; |
| 4 | 930 | | if ((int)_statusCode != 200) |
| | 931 | | { |
| 0 | 932 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 933 | | try |
| | 934 | | { |
| 0 | 935 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 936 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 937 | | if (_errorBody != null) |
| | 938 | | { |
| 0 | 939 | | ex.Body = _errorBody; |
| | 940 | | } |
| 0 | 941 | | } |
| 0 | 942 | | catch (JsonException) |
| | 943 | | { |
| | 944 | | // Ignore the exception |
| 0 | 945 | | } |
| 0 | 946 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 947 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 948 | | if (_shouldTrace) |
| | 949 | | { |
| 0 | 950 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 951 | | } |
| 0 | 952 | | _httpRequest.Dispose(); |
| 0 | 953 | | if (_httpResponse != null) |
| | 954 | | { |
| 0 | 955 | | _httpResponse.Dispose(); |
| | 956 | | } |
| 0 | 957 | | throw ex; |
| | 958 | | } |
| | 959 | | // Create Result |
| 4 | 960 | | var _result = new HttpOperationResponse<Project>(); |
| 4 | 961 | | _result.Request = _httpRequest; |
| 4 | 962 | | _result.Response = _httpResponse; |
| | 963 | | // Deserialize Response |
| 4 | 964 | | if ((int)_statusCode == 200) |
| | 965 | | { |
| 4 | 966 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 967 | | try |
| | 968 | | { |
| 4 | 969 | | _result.Body = SafeJsonConvert.DeserializeObject<Project>(_responseContent, DeserializationSettings) |
| 4 | 970 | | } |
| 0 | 971 | | catch (JsonException ex) |
| | 972 | | { |
| 0 | 973 | | _httpRequest.Dispose(); |
| 0 | 974 | | if (_httpResponse != null) |
| | 975 | | { |
| 0 | 976 | | _httpResponse.Dispose(); |
| | 977 | | } |
| 0 | 978 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 979 | | } |
| | 980 | | } |
| 4 | 981 | | if (_shouldTrace) |
| | 982 | | { |
| 0 | 983 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 984 | | } |
| 4 | 985 | | return _result; |
| 4 | 986 | | } |
| | 987 | |
|
| | 988 | | /// <summary> |
| | 989 | | /// Delete a specific project. |
| | 990 | | /// </summary> |
| | 991 | | /// <param name='projectId'> |
| | 992 | | /// The project id. |
| | 993 | | /// </param> |
| | 994 | | /// <param name='customHeaders'> |
| | 995 | | /// Headers that will be added to request. |
| | 996 | | /// </param> |
| | 997 | | /// <param name='cancellationToken'> |
| | 998 | | /// The cancellation token. |
| | 999 | | /// </param> |
| | 1000 | | /// <exception cref="CustomVisionErrorException"> |
| | 1001 | | /// Thrown when the operation returned an invalid status code |
| | 1002 | | /// </exception> |
| | 1003 | | /// <exception cref="ValidationException"> |
| | 1004 | | /// Thrown when a required parameter is null |
| | 1005 | | /// </exception> |
| | 1006 | | /// <exception cref="System.ArgumentNullException"> |
| | 1007 | | /// Thrown when a required parameter is null |
| | 1008 | | /// </exception> |
| | 1009 | | /// <return> |
| | 1010 | | /// A response object containing the response body and response headers. |
| | 1011 | | /// </return> |
| | 1012 | | public async Task<HttpOperationResponse> DeleteProjectWithHttpMessagesAsync(System.Guid projectId, Dictionary<st |
| | 1013 | | { |
| 18 | 1014 | | if (Endpoint == null) |
| | 1015 | | { |
| 0 | 1016 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 1017 | | } |
| | 1018 | | // Tracing |
| 18 | 1019 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 18 | 1020 | | string _invocationId = null; |
| 18 | 1021 | | if (_shouldTrace) |
| | 1022 | | { |
| 0 | 1023 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1024 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1025 | | tracingParameters.Add("projectId", projectId); |
| 0 | 1026 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1027 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteProject", tracingParameters); |
| | 1028 | | } |
| | 1029 | | // Construct URL |
| 18 | 1030 | | var _baseUrl = BaseUri; |
| 18 | 1031 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}"; |
| 18 | 1032 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 18 | 1033 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| | 1034 | | // Create HTTP transport objects |
| 18 | 1035 | | var _httpRequest = new HttpRequestMessage(); |
| 18 | 1036 | | HttpResponseMessage _httpResponse = null; |
| 18 | 1037 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 18 | 1038 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1039 | | // Set Headers |
| | 1040 | |
|
| | 1041 | |
|
| 18 | 1042 | | if (customHeaders != null) |
| | 1043 | | { |
| 0 | 1044 | | foreach(var _header in customHeaders) |
| | 1045 | | { |
| 0 | 1046 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1047 | | { |
| 0 | 1048 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1049 | | } |
| 0 | 1050 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1051 | | } |
| | 1052 | | } |
| | 1053 | |
|
| | 1054 | | // Serialize Request |
| 18 | 1055 | | string _requestContent = null; |
| | 1056 | | // Set Credentials |
| 18 | 1057 | | if (Credentials != null) |
| | 1058 | | { |
| 18 | 1059 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 1060 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1061 | | } |
| | 1062 | | // Send Request |
| 18 | 1063 | | if (_shouldTrace) |
| | 1064 | | { |
| 0 | 1065 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1066 | | } |
| 18 | 1067 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 1068 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 18 | 1069 | | if (_shouldTrace) |
| | 1070 | | { |
| 0 | 1071 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1072 | | } |
| 18 | 1073 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 18 | 1074 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 1075 | | string _responseContent = null; |
| 18 | 1076 | | if ((int)_statusCode != 204) |
| | 1077 | | { |
| 0 | 1078 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 1079 | | try |
| | 1080 | | { |
| 0 | 1081 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1082 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 1083 | | if (_errorBody != null) |
| | 1084 | | { |
| 0 | 1085 | | ex.Body = _errorBody; |
| | 1086 | | } |
| 0 | 1087 | | } |
| 0 | 1088 | | catch (JsonException) |
| | 1089 | | { |
| | 1090 | | // Ignore the exception |
| 0 | 1091 | | } |
| 0 | 1092 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1093 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1094 | | if (_shouldTrace) |
| | 1095 | | { |
| 0 | 1096 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1097 | | } |
| 0 | 1098 | | _httpRequest.Dispose(); |
| 0 | 1099 | | if (_httpResponse != null) |
| | 1100 | | { |
| 0 | 1101 | | _httpResponse.Dispose(); |
| | 1102 | | } |
| 0 | 1103 | | throw ex; |
| | 1104 | | } |
| | 1105 | | // Create Result |
| 18 | 1106 | | var _result = new HttpOperationResponse(); |
| 18 | 1107 | | _result.Request = _httpRequest; |
| 18 | 1108 | | _result.Response = _httpResponse; |
| 18 | 1109 | | if (_shouldTrace) |
| | 1110 | | { |
| 0 | 1111 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1112 | | } |
| 18 | 1113 | | return _result; |
| 18 | 1114 | | } |
| | 1115 | |
|
| | 1116 | | /// <summary> |
| | 1117 | | /// Update a specific project. |
| | 1118 | | /// </summary> |
| | 1119 | | /// <param name='projectId'> |
| | 1120 | | /// The id of the project to update. |
| | 1121 | | /// </param> |
| | 1122 | | /// <param name='updatedProject'> |
| | 1123 | | /// The updated project model. |
| | 1124 | | /// </param> |
| | 1125 | | /// <param name='customHeaders'> |
| | 1126 | | /// Headers that will be added to request. |
| | 1127 | | /// </param> |
| | 1128 | | /// <param name='cancellationToken'> |
| | 1129 | | /// The cancellation token. |
| | 1130 | | /// </param> |
| | 1131 | | /// <exception cref="CustomVisionErrorException"> |
| | 1132 | | /// Thrown when the operation returned an invalid status code |
| | 1133 | | /// </exception> |
| | 1134 | | /// <exception cref="SerializationException"> |
| | 1135 | | /// Thrown when unable to deserialize the response |
| | 1136 | | /// </exception> |
| | 1137 | | /// <exception cref="ValidationException"> |
| | 1138 | | /// Thrown when a required parameter is null |
| | 1139 | | /// </exception> |
| | 1140 | | /// <exception cref="System.ArgumentNullException"> |
| | 1141 | | /// Thrown when a required parameter is null |
| | 1142 | | /// </exception> |
| | 1143 | | /// <return> |
| | 1144 | | /// A response object containing the response body and response headers. |
| | 1145 | | /// </return> |
| | 1146 | | public async Task<HttpOperationResponse<Project>> UpdateProjectWithHttpMessagesAsync(System.Guid projectId, Proj |
| | 1147 | | { |
| 2 | 1148 | | if (Endpoint == null) |
| | 1149 | | { |
| 0 | 1150 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 1151 | | } |
| 2 | 1152 | | if (updatedProject == null) |
| | 1153 | | { |
| 0 | 1154 | | throw new ValidationException(ValidationRules.CannotBeNull, "updatedProject"); |
| | 1155 | | } |
| | 1156 | | // Tracing |
| 2 | 1157 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 1158 | | string _invocationId = null; |
| 2 | 1159 | | if (_shouldTrace) |
| | 1160 | | { |
| 0 | 1161 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1162 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1163 | | tracingParameters.Add("projectId", projectId); |
| 0 | 1164 | | tracingParameters.Add("updatedProject", updatedProject); |
| 0 | 1165 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1166 | | ServiceClientTracing.Enter(_invocationId, this, "UpdateProject", tracingParameters); |
| | 1167 | | } |
| | 1168 | | // Construct URL |
| 2 | 1169 | | var _baseUrl = BaseUri; |
| 2 | 1170 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}"; |
| 2 | 1171 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 1172 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| | 1173 | | // Create HTTP transport objects |
| 2 | 1174 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 1175 | | HttpResponseMessage _httpResponse = null; |
| 2 | 1176 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 2 | 1177 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1178 | | // Set Headers |
| | 1179 | |
|
| | 1180 | |
|
| 2 | 1181 | | if (customHeaders != null) |
| | 1182 | | { |
| 0 | 1183 | | foreach(var _header in customHeaders) |
| | 1184 | | { |
| 0 | 1185 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1186 | | { |
| 0 | 1187 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1188 | | } |
| 0 | 1189 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1190 | | } |
| | 1191 | | } |
| | 1192 | |
|
| | 1193 | | // Serialize Request |
| 2 | 1194 | | string _requestContent = null; |
| 2 | 1195 | | if(updatedProject != null) |
| | 1196 | | { |
| 2 | 1197 | | _requestContent = SafeJsonConvert.SerializeObject(updatedProject, SerializationSettings); |
| 2 | 1198 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 2 | 1199 | | _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); |
| | 1200 | | } |
| | 1201 | | // Set Credentials |
| 2 | 1202 | | if (Credentials != null) |
| | 1203 | | { |
| 2 | 1204 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1205 | | await 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 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 CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 1224 | | try |
| | 1225 | | { |
| 0 | 1226 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1227 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 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<Project>(); |
| 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 = SafeJsonConvert.DeserializeObject<Project>(_responseContent, DeserializationSettings) |
| 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 | | /// Get artifact content from blob storage, based on artifact relative path in |
| | 1281 | | /// the blob. |
| | 1282 | | /// </summary> |
| | 1283 | | /// <param name='projectId'> |
| | 1284 | | /// The project id. |
| | 1285 | | /// </param> |
| | 1286 | | /// <param name='path'> |
| | 1287 | | /// The relative path for artifact. |
| | 1288 | | /// </param> |
| | 1289 | | /// <param name='customHeaders'> |
| | 1290 | | /// Headers that will be added to request. |
| | 1291 | | /// </param> |
| | 1292 | | /// <param name='cancellationToken'> |
| | 1293 | | /// The cancellation token. |
| | 1294 | | /// </param> |
| | 1295 | | /// <exception cref="HttpOperationException"> |
| | 1296 | | /// Thrown when the operation returned an invalid status code |
| | 1297 | | /// </exception> |
| | 1298 | | /// <exception cref="SerializationException"> |
| | 1299 | | /// Thrown when unable to deserialize the response |
| | 1300 | | /// </exception> |
| | 1301 | | /// <exception cref="ValidationException"> |
| | 1302 | | /// Thrown when a required parameter is null |
| | 1303 | | /// </exception> |
| | 1304 | | /// <exception cref="System.ArgumentNullException"> |
| | 1305 | | /// Thrown when a required parameter is null |
| | 1306 | | /// </exception> |
| | 1307 | | /// <return> |
| | 1308 | | /// A response object containing the response body and response headers. |
| | 1309 | | /// </return> |
| | 1310 | | public async Task<HttpOperationResponse<Stream>> GetArtifactWithHttpMessagesAsync(System.Guid projectId, string |
| | 1311 | | { |
| 2 | 1312 | | if (Endpoint == null) |
| | 1313 | | { |
| 0 | 1314 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 1315 | | } |
| 2 | 1316 | | if (path == null) |
| | 1317 | | { |
| 0 | 1318 | | throw new ValidationException(ValidationRules.CannotBeNull, "path"); |
| | 1319 | | } |
| | 1320 | | // Tracing |
| 2 | 1321 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 1322 | | string _invocationId = null; |
| 2 | 1323 | | if (_shouldTrace) |
| | 1324 | | { |
| 0 | 1325 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1326 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1327 | | tracingParameters.Add("projectId", projectId); |
| 0 | 1328 | | tracingParameters.Add("path", path); |
| 0 | 1329 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1330 | | ServiceClientTracing.Enter(_invocationId, this, "GetArtifact", tracingParameters); |
| | 1331 | | } |
| | 1332 | | // Construct URL |
| 2 | 1333 | | var _baseUrl = BaseUri; |
| 2 | 1334 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/artifacts"; |
| 2 | 1335 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 1336 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 1337 | | List<string> _queryParameters = new List<string>(); |
| 2 | 1338 | | if (path != null) |
| | 1339 | | { |
| 2 | 1340 | | _queryParameters.Add(string.Format("path={0}", System.Uri.EscapeDataString(path))); |
| | 1341 | | } |
| 2 | 1342 | | if (_queryParameters.Count > 0) |
| | 1343 | | { |
| 2 | 1344 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1345 | | } |
| | 1346 | | // Create HTTP transport objects |
| 2 | 1347 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 1348 | | HttpResponseMessage _httpResponse = null; |
| 2 | 1349 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 1350 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1351 | | // Set Headers |
| | 1352 | |
|
| | 1353 | |
|
| 2 | 1354 | | if (customHeaders != null) |
| | 1355 | | { |
| 0 | 1356 | | foreach(var _header in customHeaders) |
| | 1357 | | { |
| 0 | 1358 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1359 | | { |
| 0 | 1360 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1361 | | } |
| 0 | 1362 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1363 | | } |
| | 1364 | | } |
| | 1365 | |
|
| | 1366 | | // Serialize Request |
| 2 | 1367 | | string _requestContent = null; |
| | 1368 | | // Set Credentials |
| 2 | 1369 | | if (Credentials != null) |
| | 1370 | | { |
| 2 | 1371 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1372 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1373 | | } |
| | 1374 | | // Send Request |
| 2 | 1375 | | if (_shouldTrace) |
| | 1376 | | { |
| 0 | 1377 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1378 | | } |
| 2 | 1379 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1380 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.ResponseHeader |
| 2 | 1381 | | if (_shouldTrace) |
| | 1382 | | { |
| 0 | 1383 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1384 | | } |
| 2 | 1385 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 1386 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1387 | | string _responseContent = null; |
| 2 | 1388 | | if ((int)_statusCode != 200) |
| | 1389 | | { |
| 0 | 1390 | | var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _st |
| 0 | 1391 | | if (_httpResponse.Content != null) { |
| 0 | 1392 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1393 | | } |
| | 1394 | | else { |
| 0 | 1395 | | _responseContent = string.Empty; |
| | 1396 | | } |
| 0 | 1397 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1398 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1399 | | if (_shouldTrace) |
| | 1400 | | { |
| 0 | 1401 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1402 | | } |
| 0 | 1403 | | _httpRequest.Dispose(); |
| 0 | 1404 | | if (_httpResponse != null) |
| | 1405 | | { |
| 0 | 1406 | | _httpResponse.Dispose(); |
| | 1407 | | } |
| 0 | 1408 | | throw ex; |
| | 1409 | | } |
| | 1410 | | // Create Result |
| 2 | 1411 | | var _result = new HttpOperationResponse<Stream>(); |
| 2 | 1412 | | _result.Request = _httpRequest; |
| 2 | 1413 | | _result.Response = _httpResponse; |
| | 1414 | | // Deserialize Response |
| 2 | 1415 | | if ((int)_statusCode == 200) |
| | 1416 | | { |
| 2 | 1417 | | _result.Body = await _httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false); |
| | 1418 | | } |
| 2 | 1419 | | if (_shouldTrace) |
| | 1420 | | { |
| 0 | 1421 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1422 | | } |
| 2 | 1423 | | return _result; |
| 2 | 1424 | | } |
| | 1425 | |
|
| | 1426 | | /// <summary> |
| | 1427 | | /// Exports a project. |
| | 1428 | | /// </summary> |
| | 1429 | | /// <param name='projectId'> |
| | 1430 | | /// The project id of the project to export. |
| | 1431 | | /// </param> |
| | 1432 | | /// <param name='customHeaders'> |
| | 1433 | | /// Headers that will be added to request. |
| | 1434 | | /// </param> |
| | 1435 | | /// <param name='cancellationToken'> |
| | 1436 | | /// The cancellation token. |
| | 1437 | | /// </param> |
| | 1438 | | /// <exception cref="CustomVisionErrorException"> |
| | 1439 | | /// Thrown when the operation returned an invalid status code |
| | 1440 | | /// </exception> |
| | 1441 | | /// <exception cref="SerializationException"> |
| | 1442 | | /// Thrown when unable to deserialize the response |
| | 1443 | | /// </exception> |
| | 1444 | | /// <exception cref="ValidationException"> |
| | 1445 | | /// Thrown when a required parameter is null |
| | 1446 | | /// </exception> |
| | 1447 | | /// <exception cref="System.ArgumentNullException"> |
| | 1448 | | /// Thrown when a required parameter is null |
| | 1449 | | /// </exception> |
| | 1450 | | /// <return> |
| | 1451 | | /// A response object containing the response body and response headers. |
| | 1452 | | /// </return> |
| | 1453 | | public async Task<HttpOperationResponse<ProjectExport>> ExportProjectWithHttpMessagesAsync(System.Guid projectId |
| | 1454 | | { |
| 2 | 1455 | | if (Endpoint == null) |
| | 1456 | | { |
| 0 | 1457 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 1458 | | } |
| | 1459 | | // Tracing |
| 2 | 1460 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 1461 | | string _invocationId = null; |
| 2 | 1462 | | if (_shouldTrace) |
| | 1463 | | { |
| 0 | 1464 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1465 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1466 | | tracingParameters.Add("projectId", projectId); |
| 0 | 1467 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1468 | | ServiceClientTracing.Enter(_invocationId, this, "ExportProject", tracingParameters); |
| | 1469 | | } |
| | 1470 | | // Construct URL |
| 2 | 1471 | | var _baseUrl = BaseUri; |
| 2 | 1472 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/export"; |
| 2 | 1473 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 1474 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| | 1475 | | // Create HTTP transport objects |
| 2 | 1476 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 1477 | | HttpResponseMessage _httpResponse = null; |
| 2 | 1478 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 1479 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1480 | | // Set Headers |
| | 1481 | |
|
| | 1482 | |
|
| 2 | 1483 | | if (customHeaders != null) |
| | 1484 | | { |
| 0 | 1485 | | foreach(var _header in customHeaders) |
| | 1486 | | { |
| 0 | 1487 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1488 | | { |
| 0 | 1489 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1490 | | } |
| 0 | 1491 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1492 | | } |
| | 1493 | | } |
| | 1494 | |
|
| | 1495 | | // Serialize Request |
| 2 | 1496 | | string _requestContent = null; |
| | 1497 | | // Set Credentials |
| 2 | 1498 | | if (Credentials != null) |
| | 1499 | | { |
| 2 | 1500 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1501 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1502 | | } |
| | 1503 | | // Send Request |
| 2 | 1504 | | if (_shouldTrace) |
| | 1505 | | { |
| 0 | 1506 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1507 | | } |
| 2 | 1508 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1509 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 1510 | | if (_shouldTrace) |
| | 1511 | | { |
| 0 | 1512 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1513 | | } |
| 2 | 1514 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 1515 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 1516 | | string _responseContent = null; |
| 2 | 1517 | | if ((int)_statusCode != 200) |
| | 1518 | | { |
| 0 | 1519 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 1520 | | try |
| | 1521 | | { |
| 0 | 1522 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1523 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 1524 | | if (_errorBody != null) |
| | 1525 | | { |
| 0 | 1526 | | ex.Body = _errorBody; |
| | 1527 | | } |
| 0 | 1528 | | } |
| 0 | 1529 | | catch (JsonException) |
| | 1530 | | { |
| | 1531 | | // Ignore the exception |
| 0 | 1532 | | } |
| 0 | 1533 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1534 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1535 | | if (_shouldTrace) |
| | 1536 | | { |
| 0 | 1537 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1538 | | } |
| 0 | 1539 | | _httpRequest.Dispose(); |
| 0 | 1540 | | if (_httpResponse != null) |
| | 1541 | | { |
| 0 | 1542 | | _httpResponse.Dispose(); |
| | 1543 | | } |
| 0 | 1544 | | throw ex; |
| | 1545 | | } |
| | 1546 | | // Create Result |
| 2 | 1547 | | var _result = new HttpOperationResponse<ProjectExport>(); |
| 2 | 1548 | | _result.Request = _httpRequest; |
| 2 | 1549 | | _result.Response = _httpResponse; |
| | 1550 | | // Deserialize Response |
| 2 | 1551 | | if ((int)_statusCode == 200) |
| | 1552 | | { |
| 2 | 1553 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1554 | | try |
| | 1555 | | { |
| 2 | 1556 | | _result.Body = SafeJsonConvert.DeserializeObject<ProjectExport>(_responseContent, DeserializationSet |
| 2 | 1557 | | } |
| 0 | 1558 | | catch (JsonException ex) |
| | 1559 | | { |
| 0 | 1560 | | _httpRequest.Dispose(); |
| 0 | 1561 | | if (_httpResponse != null) |
| | 1562 | | { |
| 0 | 1563 | | _httpResponse.Dispose(); |
| | 1564 | | } |
| 0 | 1565 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1566 | | } |
| | 1567 | | } |
| 2 | 1568 | | if (_shouldTrace) |
| | 1569 | | { |
| 0 | 1570 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1571 | | } |
| 2 | 1572 | | return _result; |
| 2 | 1573 | | } |
| | 1574 | |
|
| | 1575 | | /// <summary> |
| | 1576 | | /// Get images for a given project iteration or workspace. |
| | 1577 | | /// </summary> |
| | 1578 | | /// <remarks> |
| | 1579 | | /// This API supports batching and range selection. By default it will only |
| | 1580 | | /// return first 50 images matching images. |
| | 1581 | | /// Use the {take} and {skip} parameters to control how many images to return |
| | 1582 | | /// in a given batch. |
| | 1583 | | /// The filtering is on an and/or relationship. For example, if the provided |
| | 1584 | | /// tag ids are for the "Dog" and |
| | 1585 | | /// "Cat" tags, then only images tagged with Dog and/or Cat will be returned |
| | 1586 | | /// </remarks> |
| | 1587 | | /// <param name='projectId'> |
| | 1588 | | /// The project id. |
| | 1589 | | /// </param> |
| | 1590 | | /// <param name='iterationId'> |
| | 1591 | | /// The iteration id. Defaults to workspace. |
| | 1592 | | /// </param> |
| | 1593 | | /// <param name='tagIds'> |
| | 1594 | | /// A list of tags ids to filter the images. Defaults to all tagged images when |
| | 1595 | | /// null. Limited to 20. |
| | 1596 | | /// </param> |
| | 1597 | | /// <param name='taggingStatus'> |
| | 1598 | | /// The tagging status filter. It can be 'All', 'Tagged', or 'Untagged'. |
| | 1599 | | /// Defaults to 'All'. Possible values include: 'All', 'Tagged', 'Untagged' |
| | 1600 | | /// </param> |
| | 1601 | | /// <param name='filter'> |
| | 1602 | | /// An expression to filter the images against image metadata. Only images |
| | 1603 | | /// where the expression evaluates to true are included in the response. |
| | 1604 | | /// The expression supports eq (Equal), ne (Not equal), and (Logical and), or |
| | 1605 | | /// (Logical or) operators. |
| | 1606 | | /// Here is an example, metadata=key1 eq 'value1' and key2 ne 'value2'. |
| | 1607 | | /// </param> |
| | 1608 | | /// <param name='orderBy'> |
| | 1609 | | /// The ordering. Defaults to newest. Possible values include: 'Newest', |
| | 1610 | | /// 'Oldest' |
| | 1611 | | /// </param> |
| | 1612 | | /// <param name='take'> |
| | 1613 | | /// Maximum number of images to return. Defaults to 50, limited to 256. |
| | 1614 | | /// </param> |
| | 1615 | | /// <param name='skip'> |
| | 1616 | | /// Number of images to skip before beginning the image batch. Defaults to 0. |
| | 1617 | | /// </param> |
| | 1618 | | /// <param name='customHeaders'> |
| | 1619 | | /// Headers that will be added to request. |
| | 1620 | | /// </param> |
| | 1621 | | /// <param name='cancellationToken'> |
| | 1622 | | /// The cancellation token. |
| | 1623 | | /// </param> |
| | 1624 | | /// <exception cref="CustomVisionErrorException"> |
| | 1625 | | /// Thrown when the operation returned an invalid status code |
| | 1626 | | /// </exception> |
| | 1627 | | /// <exception cref="SerializationException"> |
| | 1628 | | /// Thrown when unable to deserialize the response |
| | 1629 | | /// </exception> |
| | 1630 | | /// <exception cref="ValidationException"> |
| | 1631 | | /// Thrown when a required parameter is null |
| | 1632 | | /// </exception> |
| | 1633 | | /// <exception cref="System.ArgumentNullException"> |
| | 1634 | | /// Thrown when a required parameter is null |
| | 1635 | | /// </exception> |
| | 1636 | | /// <return> |
| | 1637 | | /// A response object containing the response body and response headers. |
| | 1638 | | /// </return> |
| | 1639 | | public async Task<HttpOperationResponse<IList<Image>>> GetImagesWithHttpMessagesAsync(System.Guid projectId, Sys |
| | 1640 | | { |
| 6 | 1641 | | if (Endpoint == null) |
| | 1642 | | { |
| 0 | 1643 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 1644 | | } |
| 6 | 1645 | | if (tagIds != null) |
| | 1646 | | { |
| 0 | 1647 | | if (tagIds.Count > 20) |
| | 1648 | | { |
| 0 | 1649 | | throw new ValidationException(ValidationRules.MaxItems, "tagIds", 20); |
| | 1650 | | } |
| 0 | 1651 | | if (tagIds.Count < 0) |
| | 1652 | | { |
| 0 | 1653 | | throw new ValidationException(ValidationRules.MinItems, "tagIds", 0); |
| | 1654 | | } |
| | 1655 | | } |
| 6 | 1656 | | if (take > 256) |
| | 1657 | | { |
| 0 | 1658 | | throw new ValidationException(ValidationRules.InclusiveMaximum, "take", 256); |
| | 1659 | | } |
| 6 | 1660 | | if (take < 0) |
| | 1661 | | { |
| 0 | 1662 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "take", 0); |
| | 1663 | | } |
| | 1664 | | // Tracing |
| 6 | 1665 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 6 | 1666 | | string _invocationId = null; |
| 6 | 1667 | | if (_shouldTrace) |
| | 1668 | | { |
| 0 | 1669 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 1670 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 1671 | | tracingParameters.Add("projectId", projectId); |
| 0 | 1672 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 1673 | | tracingParameters.Add("tagIds", tagIds); |
| 0 | 1674 | | tracingParameters.Add("taggingStatus", taggingStatus); |
| 0 | 1675 | | tracingParameters.Add("filter", filter); |
| 0 | 1676 | | tracingParameters.Add("orderBy", orderBy); |
| 0 | 1677 | | tracingParameters.Add("take", take); |
| 0 | 1678 | | tracingParameters.Add("skip", skip); |
| 0 | 1679 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 1680 | | ServiceClientTracing.Enter(_invocationId, this, "GetImages", tracingParameters); |
| | 1681 | | } |
| | 1682 | | // Construct URL |
| 6 | 1683 | | var _baseUrl = BaseUri; |
| 6 | 1684 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images"; |
| 6 | 1685 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 6 | 1686 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 6 | 1687 | | List<string> _queryParameters = new List<string>(); |
| 6 | 1688 | | if (iterationId != null) |
| | 1689 | | { |
| 0 | 1690 | | _queryParameters.Add(string.Format("iterationId={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serial |
| | 1691 | | } |
| 6 | 1692 | | if (tagIds != null) |
| | 1693 | | { |
| 0 | 1694 | | _queryParameters.Add(string.Format("tagIds={0}", System.Uri.EscapeDataString(string.Join(",", tagIds)))) |
| | 1695 | | } |
| 6 | 1696 | | if (taggingStatus != null) |
| | 1697 | | { |
| 4 | 1698 | | _queryParameters.Add(string.Format("taggingStatus={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seri |
| | 1699 | | } |
| 6 | 1700 | | if (filter != null) |
| | 1701 | | { |
| 0 | 1702 | | _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter))); |
| | 1703 | | } |
| 6 | 1704 | | if (orderBy != null) |
| | 1705 | | { |
| 0 | 1706 | | _queryParameters.Add(string.Format("orderBy={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 1707 | | } |
| 6 | 1708 | | if (take != null) |
| | 1709 | | { |
| 6 | 1710 | | _queryParameters.Add(string.Format("take={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObje |
| | 1711 | | } |
| 6 | 1712 | | if (skip != null) |
| | 1713 | | { |
| 6 | 1714 | | _queryParameters.Add(string.Format("skip={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObje |
| | 1715 | | } |
| 6 | 1716 | | if (_queryParameters.Count > 0) |
| | 1717 | | { |
| 6 | 1718 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1719 | | } |
| | 1720 | | // Create HTTP transport objects |
| 6 | 1721 | | var _httpRequest = new HttpRequestMessage(); |
| 6 | 1722 | | HttpResponseMessage _httpResponse = null; |
| 6 | 1723 | | _httpRequest.Method = new HttpMethod("GET"); |
| 6 | 1724 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1725 | | // Set Headers |
| | 1726 | |
|
| | 1727 | |
|
| 6 | 1728 | | if (customHeaders != null) |
| | 1729 | | { |
| 0 | 1730 | | foreach(var _header in customHeaders) |
| | 1731 | | { |
| 0 | 1732 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1733 | | { |
| 0 | 1734 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1735 | | } |
| 0 | 1736 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1737 | | } |
| | 1738 | | } |
| | 1739 | |
|
| | 1740 | | // Serialize Request |
| 6 | 1741 | | string _requestContent = null; |
| | 1742 | | // Set Credentials |
| 6 | 1743 | | if (Credentials != null) |
| | 1744 | | { |
| 6 | 1745 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 1746 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1747 | | } |
| | 1748 | | // Send Request |
| 6 | 1749 | | if (_shouldTrace) |
| | 1750 | | { |
| 0 | 1751 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1752 | | } |
| 6 | 1753 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 1754 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 6 | 1755 | | if (_shouldTrace) |
| | 1756 | | { |
| 0 | 1757 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1758 | | } |
| 6 | 1759 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 6 | 1760 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 1761 | | string _responseContent = null; |
| 6 | 1762 | | if ((int)_statusCode != 200) |
| | 1763 | | { |
| 0 | 1764 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 1765 | | try |
| | 1766 | | { |
| 0 | 1767 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 1768 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 1769 | | if (_errorBody != null) |
| | 1770 | | { |
| 0 | 1771 | | ex.Body = _errorBody; |
| | 1772 | | } |
| 0 | 1773 | | } |
| 0 | 1774 | | catch (JsonException) |
| | 1775 | | { |
| | 1776 | | // Ignore the exception |
| 0 | 1777 | | } |
| 0 | 1778 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 1779 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 1780 | | if (_shouldTrace) |
| | 1781 | | { |
| 0 | 1782 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1783 | | } |
| 0 | 1784 | | _httpRequest.Dispose(); |
| 0 | 1785 | | if (_httpResponse != null) |
| | 1786 | | { |
| 0 | 1787 | | _httpResponse.Dispose(); |
| | 1788 | | } |
| 0 | 1789 | | throw ex; |
| | 1790 | | } |
| | 1791 | | // Create Result |
| 6 | 1792 | | var _result = new HttpOperationResponse<IList<Image>>(); |
| 6 | 1793 | | _result.Request = _httpRequest; |
| 6 | 1794 | | _result.Response = _httpResponse; |
| | 1795 | | // Deserialize Response |
| 6 | 1796 | | if ((int)_statusCode == 200) |
| | 1797 | | { |
| 6 | 1798 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1799 | | try |
| | 1800 | | { |
| 6 | 1801 | | _result.Body = SafeJsonConvert.DeserializeObject<IList<Image>>(_responseContent, DeserializationSett |
| 6 | 1802 | | } |
| 0 | 1803 | | catch (JsonException ex) |
| | 1804 | | { |
| 0 | 1805 | | _httpRequest.Dispose(); |
| 0 | 1806 | | if (_httpResponse != null) |
| | 1807 | | { |
| 0 | 1808 | | _httpResponse.Dispose(); |
| | 1809 | | } |
| 0 | 1810 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 1811 | | } |
| | 1812 | | } |
| 6 | 1813 | | if (_shouldTrace) |
| | 1814 | | { |
| 0 | 1815 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 1816 | | } |
| 6 | 1817 | | return _result; |
| 6 | 1818 | | } |
| | 1819 | |
|
| | 1820 | | /// <summary> |
| | 1821 | | /// Add the provided images to the set of training images. |
| | 1822 | | /// </summary> |
| | 1823 | | /// <remarks> |
| | 1824 | | /// This API accepts body content as multipart/form-data and |
| | 1825 | | /// application/octet-stream. When using multipart |
| | 1826 | | /// multiple image files can be sent at once, with a maximum of 64 files. |
| | 1827 | | /// If all images are successful created, 200(OK) status code will be returned. |
| | 1828 | | /// Otherwise, 207 (Multi-Status) status code will be returned and detail |
| | 1829 | | /// status for each image will be listed in the response payload. |
| | 1830 | | /// </remarks> |
| | 1831 | | /// <param name='projectId'> |
| | 1832 | | /// The project id. |
| | 1833 | | /// </param> |
| | 1834 | | /// <param name='imageData'> |
| | 1835 | | /// Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports |
| | 1836 | | /// images up to 6MB. |
| | 1837 | | /// </param> |
| | 1838 | | /// <param name='tagIds'> |
| | 1839 | | /// The tags ids with which to tag each image. Limited to 20. |
| | 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="CustomVisionErrorException"> |
| | 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<ImageCreateSummary>> CreateImagesFromDataWithHttpMessagesAsync(System.Gu |
| | 1863 | | { |
| | 1864 | | if (Endpoint == null) |
| | 1865 | | { |
| | 1866 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 1867 | | } |
| | 1868 | | if (tagIds != null) |
| | 1869 | | { |
| | 1870 | | if (tagIds.Count > 20) |
| | 1871 | | { |
| | 1872 | | throw new ValidationException(ValidationRules.MaxItems, "tagIds", 20); |
| | 1873 | | } |
| | 1874 | | if (tagIds.Count < 0) |
| | 1875 | | { |
| | 1876 | | throw new ValidationException(ValidationRules.MinItems, "tagIds", 0); |
| | 1877 | | } |
| | 1878 | | } |
| | 1879 | | if (imageData == null) |
| | 1880 | | { |
| | 1881 | | throw new ValidationException(ValidationRules.CannotBeNull, "imageData"); |
| | 1882 | | } |
| | 1883 | | // Tracing |
| | 1884 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 1885 | | string _invocationId = null; |
| | 1886 | | if (_shouldTrace) |
| | 1887 | | { |
| | 1888 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 1889 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 1890 | | tracingParameters.Add("projectId", projectId); |
| | 1891 | | tracingParameters.Add("tagIds", tagIds); |
| | 1892 | | tracingParameters.Add("imageData", imageData); |
| | 1893 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 1894 | | ServiceClientTracing.Enter(_invocationId, this, "CreateImagesFromData", tracingParameters); |
| | 1895 | | } |
| | 1896 | | // Construct URL |
| | 1897 | | var _baseUrl = BaseUri; |
| | 1898 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images"; |
| | 1899 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| | 1900 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| | 1901 | | List<string> _queryParameters = new List<string>(); |
| | 1902 | | if (tagIds != null) |
| | 1903 | | { |
| | 1904 | | _queryParameters.Add(string.Format("tagIds={0}", System.Uri.EscapeDataString(string.Join(",", tagIds)))) |
| | 1905 | | } |
| | 1906 | | if (_queryParameters.Count > 0) |
| | 1907 | | { |
| | 1908 | | _url += "?" + string.Join("&", _queryParameters); |
| | 1909 | | } |
| | 1910 | | // Create HTTP transport objects |
| | 1911 | | var _httpRequest = new HttpRequestMessage(); |
| | 1912 | | HttpResponseMessage _httpResponse = null; |
| | 1913 | | _httpRequest.Method = new HttpMethod("POST"); |
| | 1914 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 1915 | | // Set Headers |
| | 1916 | |
|
| | 1917 | |
|
| | 1918 | | if (customHeaders != null) |
| | 1919 | | { |
| | 1920 | | foreach(var _header in customHeaders) |
| | 1921 | | { |
| | 1922 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 1923 | | { |
| | 1924 | | _httpRequest.Headers.Remove(_header.Key); |
| | 1925 | | } |
| | 1926 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 1927 | | } |
| | 1928 | | } |
| | 1929 | |
|
| | 1930 | | // Serialize Request |
| | 1931 | | string _requestContent = null; |
| | 1932 | | MultipartFormDataContent _multiPartContent = new MultipartFormDataContent(); |
| | 1933 | | if (imageData != null) |
| | 1934 | | { |
| | 1935 | | StreamContent _imageData = new StreamContent(imageData); |
| | 1936 | | _imageData.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); |
| | 1937 | | ContentDispositionHeaderValue _contentDispositionHeaderValue = new ContentDispositionHeaderValue("form-d |
| | 1938 | | _contentDispositionHeaderValue.Name = "imageData"; |
| | 1939 | | // get filename from stream if it's a file otherwise, just use 'unknown' |
| | 1940 | | var _fileStream = imageData as FileStream; |
| | 1941 | | var _fileName = (_fileStream != null ? _fileStream.Name : null) ?? "unknown"; |
| 320 | 1942 | | if(System.Linq.Enumerable.Any(_fileName, c => c > 127) ) |
| | 1943 | | { |
| | 1944 | | // non ASCII chars detected, need UTF encoding: |
| | 1945 | | _contentDispositionHeaderValue.FileNameStar = _fileName; |
| | 1946 | | } |
| | 1947 | | else |
| | 1948 | | { |
| | 1949 | | // ASCII only |
| | 1950 | | _contentDispositionHeaderValue.FileName = _fileName; |
| | 1951 | | } |
| | 1952 | | _imageData.Headers.ContentDisposition = _contentDispositionHeaderValue; |
| | 1953 | | _multiPartContent.Add(_imageData, "imageData"); |
| | 1954 | | } |
| | 1955 | | _httpRequest.Content = _multiPartContent; |
| | 1956 | | // Set Credentials |
| | 1957 | | if (Credentials != null) |
| | 1958 | | { |
| | 1959 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 1960 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1961 | | } |
| | 1962 | | // Send Request |
| | 1963 | | if (_shouldTrace) |
| | 1964 | | { |
| | 1965 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 1966 | | } |
| | 1967 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 1968 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 1969 | | if (_shouldTrace) |
| | 1970 | | { |
| | 1971 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 1972 | | } |
| | 1973 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 1974 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 1975 | | string _responseContent = null; |
| | 1976 | | if ((int)_statusCode != 200 && (int)_statusCode != 207) |
| | 1977 | | { |
| | 1978 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 1979 | | try |
| | 1980 | | { |
| | 1981 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 1982 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| | 1983 | | if (_errorBody != null) |
| | 1984 | | { |
| | 1985 | | ex.Body = _errorBody; |
| | 1986 | | } |
| | 1987 | | } |
| | 1988 | | catch (JsonException) |
| | 1989 | | { |
| | 1990 | | // Ignore the exception |
| | 1991 | | } |
| | 1992 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 1993 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 1994 | | if (_shouldTrace) |
| | 1995 | | { |
| | 1996 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 1997 | | } |
| | 1998 | | _httpRequest.Dispose(); |
| | 1999 | | if (_httpResponse != null) |
| | 2000 | | { |
| | 2001 | | _httpResponse.Dispose(); |
| | 2002 | | } |
| | 2003 | | throw ex; |
| | 2004 | | } |
| | 2005 | | // Create Result |
| | 2006 | | var _result = new HttpOperationResponse<ImageCreateSummary>(); |
| | 2007 | | _result.Request = _httpRequest; |
| | 2008 | | _result.Response = _httpResponse; |
| | 2009 | | // Deserialize Response |
| | 2010 | | if ((int)_statusCode == 200) |
| | 2011 | | { |
| | 2012 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2013 | | try |
| | 2014 | | { |
| | 2015 | | _result.Body = SafeJsonConvert.DeserializeObject<ImageCreateSummary>(_responseContent, Deserializati |
| | 2016 | | } |
| | 2017 | | catch (JsonException ex) |
| | 2018 | | { |
| | 2019 | | _httpRequest.Dispose(); |
| | 2020 | | if (_httpResponse != null) |
| | 2021 | | { |
| | 2022 | | _httpResponse.Dispose(); |
| | 2023 | | } |
| | 2024 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2025 | | } |
| | 2026 | | } |
| | 2027 | | // Deserialize Response |
| | 2028 | | if ((int)_statusCode == 207) |
| | 2029 | | { |
| | 2030 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2031 | | try |
| | 2032 | | { |
| | 2033 | | _result.Body = SafeJsonConvert.DeserializeObject<ImageCreateSummary>(_responseContent, Deserializati |
| | 2034 | | } |
| | 2035 | | catch (JsonException ex) |
| | 2036 | | { |
| | 2037 | | _httpRequest.Dispose(); |
| | 2038 | | if (_httpResponse != null) |
| | 2039 | | { |
| | 2040 | | _httpResponse.Dispose(); |
| | 2041 | | } |
| | 2042 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2043 | | } |
| | 2044 | | } |
| | 2045 | | if (_shouldTrace) |
| | 2046 | | { |
| | 2047 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2048 | | } |
| | 2049 | | return _result; |
| | 2050 | | } |
| | 2051 | |
|
| | 2052 | | /// <summary> |
| | 2053 | | /// Delete images from the set of training images. |
| | 2054 | | /// </summary> |
| | 2055 | | /// <param name='projectId'> |
| | 2056 | | /// The project id. |
| | 2057 | | /// </param> |
| | 2058 | | /// <param name='imageIds'> |
| | 2059 | | /// Ids of the images to be deleted. Limited to 256 images per batch. |
| | 2060 | | /// </param> |
| | 2061 | | /// <param name='allImages'> |
| | 2062 | | /// Flag to specify delete all images, specify this flag or a list of images. |
| | 2063 | | /// Using this flag will return a 202 response to indicate the images are being |
| | 2064 | | /// deleted. |
| | 2065 | | /// </param> |
| | 2066 | | /// <param name='allIterations'> |
| | 2067 | | /// Removes these images from all iterations, not just the current workspace. |
| | 2068 | | /// Using this flag will return a 202 response to indicate the images are being |
| | 2069 | | /// deleted. |
| | 2070 | | /// </param> |
| | 2071 | | /// <param name='customHeaders'> |
| | 2072 | | /// Headers that will be added to request. |
| | 2073 | | /// </param> |
| | 2074 | | /// <param name='cancellationToken'> |
| | 2075 | | /// The cancellation token. |
| | 2076 | | /// </param> |
| | 2077 | | /// <exception cref="CustomVisionErrorException"> |
| | 2078 | | /// Thrown when the operation returned an invalid status code |
| | 2079 | | /// </exception> |
| | 2080 | | /// <exception cref="ValidationException"> |
| | 2081 | | /// Thrown when a required parameter is null |
| | 2082 | | /// </exception> |
| | 2083 | | /// <exception cref="System.ArgumentNullException"> |
| | 2084 | | /// Thrown when a required parameter is null |
| | 2085 | | /// </exception> |
| | 2086 | | /// <return> |
| | 2087 | | /// A response object containing the response body and response headers. |
| | 2088 | | /// </return> |
| | 2089 | | public async Task<HttpOperationResponse> DeleteImagesWithHttpMessagesAsync(System.Guid projectId, IList<System.G |
| | 2090 | | { |
| 2 | 2091 | | if (Endpoint == null) |
| | 2092 | | { |
| 0 | 2093 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 2094 | | } |
| 2 | 2095 | | if (imageIds != null) |
| | 2096 | | { |
| 2 | 2097 | | if (imageIds.Count > 256) |
| | 2098 | | { |
| 0 | 2099 | | throw new ValidationException(ValidationRules.MaxItems, "imageIds", 256); |
| | 2100 | | } |
| 2 | 2101 | | if (imageIds.Count < 0) |
| | 2102 | | { |
| 0 | 2103 | | throw new ValidationException(ValidationRules.MinItems, "imageIds", 0); |
| | 2104 | | } |
| | 2105 | | } |
| | 2106 | | // Tracing |
| 2 | 2107 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 2108 | | string _invocationId = null; |
| 2 | 2109 | | if (_shouldTrace) |
| | 2110 | | { |
| 0 | 2111 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2112 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2113 | | tracingParameters.Add("projectId", projectId); |
| 0 | 2114 | | tracingParameters.Add("imageIds", imageIds); |
| 0 | 2115 | | tracingParameters.Add("allImages", allImages); |
| 0 | 2116 | | tracingParameters.Add("allIterations", allIterations); |
| 0 | 2117 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2118 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteImages", tracingParameters); |
| | 2119 | | } |
| | 2120 | | // Construct URL |
| 2 | 2121 | | var _baseUrl = BaseUri; |
| 2 | 2122 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images"; |
| 2 | 2123 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 2124 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 2125 | | List<string> _queryParameters = new List<string>(); |
| 2 | 2126 | | if (imageIds != null) |
| | 2127 | | { |
| 2 | 2128 | | _queryParameters.Add(string.Format("imageIds={0}", System.Uri.EscapeDataString(string.Join(",", imageIds |
| | 2129 | | } |
| 2 | 2130 | | if (allImages != null) |
| | 2131 | | { |
| 0 | 2132 | | _queryParameters.Add(string.Format("allImages={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serializ |
| | 2133 | | } |
| 2 | 2134 | | if (allIterations != null) |
| | 2135 | | { |
| 0 | 2136 | | _queryParameters.Add(string.Format("allIterations={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seri |
| | 2137 | | } |
| 2 | 2138 | | if (_queryParameters.Count > 0) |
| | 2139 | | { |
| 2 | 2140 | | _url += "?" + string.Join("&", _queryParameters); |
| | 2141 | | } |
| | 2142 | | // Create HTTP transport objects |
| 2 | 2143 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 2144 | | HttpResponseMessage _httpResponse = null; |
| 2 | 2145 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 2 | 2146 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2147 | | // Set Headers |
| | 2148 | |
|
| | 2149 | |
|
| 2 | 2150 | | if (customHeaders != null) |
| | 2151 | | { |
| 0 | 2152 | | foreach(var _header in customHeaders) |
| | 2153 | | { |
| 0 | 2154 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2155 | | { |
| 0 | 2156 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2157 | | } |
| 0 | 2158 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2159 | | } |
| | 2160 | | } |
| | 2161 | |
|
| | 2162 | | // Serialize Request |
| 2 | 2163 | | string _requestContent = null; |
| | 2164 | | // Set Credentials |
| 2 | 2165 | | if (Credentials != null) |
| | 2166 | | { |
| 2 | 2167 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2168 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2169 | | } |
| | 2170 | | // Send Request |
| 2 | 2171 | | if (_shouldTrace) |
| | 2172 | | { |
| 0 | 2173 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2174 | | } |
| 2 | 2175 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2176 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 2177 | | if (_shouldTrace) |
| | 2178 | | { |
| 0 | 2179 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2180 | | } |
| 2 | 2181 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 2182 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2183 | | string _responseContent = null; |
| 2 | 2184 | | if ((int)_statusCode != 202 && (int)_statusCode != 204) |
| | 2185 | | { |
| 0 | 2186 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 2187 | | try |
| | 2188 | | { |
| 0 | 2189 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2190 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 2191 | | if (_errorBody != null) |
| | 2192 | | { |
| 0 | 2193 | | ex.Body = _errorBody; |
| | 2194 | | } |
| 0 | 2195 | | } |
| 0 | 2196 | | catch (JsonException) |
| | 2197 | | { |
| | 2198 | | // Ignore the exception |
| 0 | 2199 | | } |
| 0 | 2200 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2201 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2202 | | if (_shouldTrace) |
| | 2203 | | { |
| 0 | 2204 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2205 | | } |
| 0 | 2206 | | _httpRequest.Dispose(); |
| 0 | 2207 | | if (_httpResponse != null) |
| | 2208 | | { |
| 0 | 2209 | | _httpResponse.Dispose(); |
| | 2210 | | } |
| 0 | 2211 | | throw ex; |
| | 2212 | | } |
| | 2213 | | // Create Result |
| 2 | 2214 | | var _result = new HttpOperationResponse(); |
| 2 | 2215 | | _result.Request = _httpRequest; |
| 2 | 2216 | | _result.Response = _httpResponse; |
| 2 | 2217 | | if (_shouldTrace) |
| | 2218 | | { |
| 0 | 2219 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2220 | | } |
| 2 | 2221 | | return _result; |
| 2 | 2222 | | } |
| | 2223 | |
|
| | 2224 | | /// <summary> |
| | 2225 | | /// Get region proposals for an image. Returns empty array if no proposals are |
| | 2226 | | /// found. |
| | 2227 | | /// </summary> |
| | 2228 | | /// <remarks> |
| | 2229 | | /// This API will get region proposals for an image along with confidences for |
| | 2230 | | /// the region. It returns an empty array if no proposals are found. |
| | 2231 | | /// </remarks> |
| | 2232 | | /// <param name='projectId'> |
| | 2233 | | /// The project id. |
| | 2234 | | /// </param> |
| | 2235 | | /// <param name='imageId'> |
| | 2236 | | /// The image id. |
| | 2237 | | /// </param> |
| | 2238 | | /// <param name='customHeaders'> |
| | 2239 | | /// Headers that will be added to request. |
| | 2240 | | /// </param> |
| | 2241 | | /// <param name='cancellationToken'> |
| | 2242 | | /// The cancellation token. |
| | 2243 | | /// </param> |
| | 2244 | | /// <exception cref="CustomVisionErrorException"> |
| | 2245 | | /// Thrown when the operation returned an invalid status code |
| | 2246 | | /// </exception> |
| | 2247 | | /// <exception cref="SerializationException"> |
| | 2248 | | /// Thrown when unable to deserialize the response |
| | 2249 | | /// </exception> |
| | 2250 | | /// <exception cref="ValidationException"> |
| | 2251 | | /// Thrown when a required parameter is null |
| | 2252 | | /// </exception> |
| | 2253 | | /// <exception cref="System.ArgumentNullException"> |
| | 2254 | | /// Thrown when a required parameter is null |
| | 2255 | | /// </exception> |
| | 2256 | | /// <return> |
| | 2257 | | /// A response object containing the response body and response headers. |
| | 2258 | | /// </return> |
| | 2259 | | public async Task<HttpOperationResponse<ImageRegionProposal>> GetImageRegionProposalsWithHttpMessagesAsync(Syste |
| | 2260 | | { |
| 2 | 2261 | | if (Endpoint == null) |
| | 2262 | | { |
| 0 | 2263 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 2264 | | } |
| | 2265 | | // Tracing |
| 2 | 2266 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 2267 | | string _invocationId = null; |
| 2 | 2268 | | if (_shouldTrace) |
| | 2269 | | { |
| 0 | 2270 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2271 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2272 | | tracingParameters.Add("projectId", projectId); |
| 0 | 2273 | | tracingParameters.Add("imageId", imageId); |
| 0 | 2274 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2275 | | ServiceClientTracing.Enter(_invocationId, this, "GetImageRegionProposals", tracingParameters); |
| | 2276 | | } |
| | 2277 | | // Construct URL |
| 2 | 2278 | | var _baseUrl = BaseUri; |
| 2 | 2279 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/{imageId}/regionpro |
| 2 | 2280 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 2281 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 2282 | | _url = _url.Replace("{imageId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(imageId, Serial |
| | 2283 | | // Create HTTP transport objects |
| 2 | 2284 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 2285 | | HttpResponseMessage _httpResponse = null; |
| 2 | 2286 | | _httpRequest.Method = new HttpMethod("POST"); |
| 2 | 2287 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2288 | | // Set Headers |
| | 2289 | |
|
| | 2290 | |
|
| 2 | 2291 | | if (customHeaders != null) |
| | 2292 | | { |
| 0 | 2293 | | foreach(var _header in customHeaders) |
| | 2294 | | { |
| 0 | 2295 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2296 | | { |
| 0 | 2297 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2298 | | } |
| 0 | 2299 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2300 | | } |
| | 2301 | | } |
| | 2302 | |
|
| | 2303 | | // Serialize Request |
| 2 | 2304 | | string _requestContent = null; |
| | 2305 | | // Set Credentials |
| 2 | 2306 | | if (Credentials != null) |
| | 2307 | | { |
| 2 | 2308 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2309 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2310 | | } |
| | 2311 | | // Send Request |
| 2 | 2312 | | if (_shouldTrace) |
| | 2313 | | { |
| 0 | 2314 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2315 | | } |
| 2 | 2316 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2317 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 2318 | | if (_shouldTrace) |
| | 2319 | | { |
| 0 | 2320 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2321 | | } |
| 2 | 2322 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 2323 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2324 | | string _responseContent = null; |
| 2 | 2325 | | if ((int)_statusCode != 200) |
| | 2326 | | { |
| 0 | 2327 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 2328 | | try |
| | 2329 | | { |
| 0 | 2330 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2331 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 2332 | | if (_errorBody != null) |
| | 2333 | | { |
| 0 | 2334 | | ex.Body = _errorBody; |
| | 2335 | | } |
| 0 | 2336 | | } |
| 0 | 2337 | | catch (JsonException) |
| | 2338 | | { |
| | 2339 | | // Ignore the exception |
| 0 | 2340 | | } |
| 0 | 2341 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2342 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2343 | | if (_shouldTrace) |
| | 2344 | | { |
| 0 | 2345 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2346 | | } |
| 0 | 2347 | | _httpRequest.Dispose(); |
| 0 | 2348 | | if (_httpResponse != null) |
| | 2349 | | { |
| 0 | 2350 | | _httpResponse.Dispose(); |
| | 2351 | | } |
| 0 | 2352 | | throw ex; |
| | 2353 | | } |
| | 2354 | | // Create Result |
| 2 | 2355 | | var _result = new HttpOperationResponse<ImageRegionProposal>(); |
| 2 | 2356 | | _result.Request = _httpRequest; |
| 2 | 2357 | | _result.Response = _httpResponse; |
| | 2358 | | // Deserialize Response |
| 2 | 2359 | | if ((int)_statusCode == 200) |
| | 2360 | | { |
| 2 | 2361 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2362 | | try |
| | 2363 | | { |
| 2 | 2364 | | _result.Body = SafeJsonConvert.DeserializeObject<ImageRegionProposal>(_responseContent, Deserializat |
| 2 | 2365 | | } |
| 0 | 2366 | | catch (JsonException ex) |
| | 2367 | | { |
| 0 | 2368 | | _httpRequest.Dispose(); |
| 0 | 2369 | | if (_httpResponse != null) |
| | 2370 | | { |
| 0 | 2371 | | _httpResponse.Dispose(); |
| | 2372 | | } |
| 0 | 2373 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2374 | | } |
| | 2375 | | } |
| 2 | 2376 | | if (_shouldTrace) |
| | 2377 | | { |
| 0 | 2378 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2379 | | } |
| 2 | 2380 | | return _result; |
| 2 | 2381 | | } |
| | 2382 | |
|
| | 2383 | | /// <summary> |
| | 2384 | | /// Get the number of images. |
| | 2385 | | /// </summary> |
| | 2386 | | /// <remarks> |
| | 2387 | | /// The filtering is on an and/or relationship. For example, if the provided |
| | 2388 | | /// tag ids are for the "Dog" and |
| | 2389 | | /// "Cat" tags, then only images tagged with Dog and/or Cat will be returned |
| | 2390 | | /// </remarks> |
| | 2391 | | /// <param name='projectId'> |
| | 2392 | | /// The project id. |
| | 2393 | | /// </param> |
| | 2394 | | /// <param name='iterationId'> |
| | 2395 | | /// The iteration id. Defaults to workspace. |
| | 2396 | | /// </param> |
| | 2397 | | /// <param name='taggingStatus'> |
| | 2398 | | /// The tagging status filter. It can be 'All', 'Tagged', or 'Untagged'. |
| | 2399 | | /// Defaults to 'All'. Possible values include: 'All', 'Tagged', 'Untagged' |
| | 2400 | | /// </param> |
| | 2401 | | /// <param name='filter'> |
| | 2402 | | /// An expression to filter the images against image metadata. Only images |
| | 2403 | | /// where the expression evaluates to true are included in the response. |
| | 2404 | | /// The expression supports eq (Equal), ne (Not equal), and (Logical and), or |
| | 2405 | | /// (Logical or) operators. |
| | 2406 | | /// Here is an example, metadata=key1 eq 'value1' and key2 ne 'value2'. |
| | 2407 | | /// </param> |
| | 2408 | | /// <param name='tagIds'> |
| | 2409 | | /// A list of tags ids to filter the images to count. Defaults to all tags when |
| | 2410 | | /// null. |
| | 2411 | | /// </param> |
| | 2412 | | /// <param name='customHeaders'> |
| | 2413 | | /// Headers that will be added to request. |
| | 2414 | | /// </param> |
| | 2415 | | /// <param name='cancellationToken'> |
| | 2416 | | /// The cancellation token. |
| | 2417 | | /// </param> |
| | 2418 | | /// <exception cref="CustomVisionErrorException"> |
| | 2419 | | /// Thrown when the operation returned an invalid status code |
| | 2420 | | /// </exception> |
| | 2421 | | /// <exception cref="SerializationException"> |
| | 2422 | | /// Thrown when unable to deserialize the response |
| | 2423 | | /// </exception> |
| | 2424 | | /// <exception cref="ValidationException"> |
| | 2425 | | /// Thrown when a required parameter is null |
| | 2426 | | /// </exception> |
| | 2427 | | /// <exception cref="System.ArgumentNullException"> |
| | 2428 | | /// Thrown when a required parameter is null |
| | 2429 | | /// </exception> |
| | 2430 | | /// <return> |
| | 2431 | | /// A response object containing the response body and response headers. |
| | 2432 | | /// </return> |
| | 2433 | | public async Task<HttpOperationResponse<int?>> GetImageCountWithHttpMessagesAsync(System.Guid projectId, System. |
| | 2434 | | { |
| 2 | 2435 | | if (Endpoint == null) |
| | 2436 | | { |
| 0 | 2437 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 2438 | | } |
| | 2439 | | // Tracing |
| 2 | 2440 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 2441 | | string _invocationId = null; |
| 2 | 2442 | | if (_shouldTrace) |
| | 2443 | | { |
| 0 | 2444 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2445 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2446 | | tracingParameters.Add("projectId", projectId); |
| 0 | 2447 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 2448 | | tracingParameters.Add("taggingStatus", taggingStatus); |
| 0 | 2449 | | tracingParameters.Add("filter", filter); |
| 0 | 2450 | | tracingParameters.Add("tagIds", tagIds); |
| 0 | 2451 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2452 | | ServiceClientTracing.Enter(_invocationId, this, "GetImageCount", tracingParameters); |
| | 2453 | | } |
| | 2454 | | // Construct URL |
| 2 | 2455 | | var _baseUrl = BaseUri; |
| 2 | 2456 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/count"; |
| 2 | 2457 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 2458 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 2459 | | List<string> _queryParameters = new List<string>(); |
| 2 | 2460 | | if (iterationId != null) |
| | 2461 | | { |
| 0 | 2462 | | _queryParameters.Add(string.Format("iterationId={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serial |
| | 2463 | | } |
| 2 | 2464 | | if (taggingStatus != null) |
| | 2465 | | { |
| 2 | 2466 | | _queryParameters.Add(string.Format("taggingStatus={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seri |
| | 2467 | | } |
| 2 | 2468 | | if (filter != null) |
| | 2469 | | { |
| 0 | 2470 | | _queryParameters.Add(string.Format("$filter={0}", System.Uri.EscapeDataString(filter))); |
| | 2471 | | } |
| 2 | 2472 | | if (tagIds != null) |
| | 2473 | | { |
| 0 | 2474 | | _queryParameters.Add(string.Format("tagIds={0}", System.Uri.EscapeDataString(string.Join(",", tagIds)))) |
| | 2475 | | } |
| 2 | 2476 | | if (_queryParameters.Count > 0) |
| | 2477 | | { |
| 2 | 2478 | | _url += "?" + string.Join("&", _queryParameters); |
| | 2479 | | } |
| | 2480 | | // Create HTTP transport objects |
| 2 | 2481 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 2482 | | HttpResponseMessage _httpResponse = null; |
| 2 | 2483 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 2484 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2485 | | // Set Headers |
| | 2486 | |
|
| | 2487 | |
|
| 2 | 2488 | | if (customHeaders != null) |
| | 2489 | | { |
| 0 | 2490 | | foreach(var _header in customHeaders) |
| | 2491 | | { |
| 0 | 2492 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2493 | | { |
| 0 | 2494 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2495 | | } |
| 0 | 2496 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2497 | | } |
| | 2498 | | } |
| | 2499 | |
|
| | 2500 | | // Serialize Request |
| 2 | 2501 | | string _requestContent = null; |
| | 2502 | | // Set Credentials |
| 2 | 2503 | | if (Credentials != null) |
| | 2504 | | { |
| 2 | 2505 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2506 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2507 | | } |
| | 2508 | | // Send Request |
| 2 | 2509 | | if (_shouldTrace) |
| | 2510 | | { |
| 0 | 2511 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2512 | | } |
| 2 | 2513 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2514 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 2515 | | if (_shouldTrace) |
| | 2516 | | { |
| 0 | 2517 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2518 | | } |
| 2 | 2519 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 2520 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 2521 | | string _responseContent = null; |
| 2 | 2522 | | if ((int)_statusCode != 200) |
| | 2523 | | { |
| 0 | 2524 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 2525 | | try |
| | 2526 | | { |
| 0 | 2527 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2528 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 2529 | | if (_errorBody != null) |
| | 2530 | | { |
| 0 | 2531 | | ex.Body = _errorBody; |
| | 2532 | | } |
| 0 | 2533 | | } |
| 0 | 2534 | | catch (JsonException) |
| | 2535 | | { |
| | 2536 | | // Ignore the exception |
| 0 | 2537 | | } |
| 0 | 2538 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2539 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2540 | | if (_shouldTrace) |
| | 2541 | | { |
| 0 | 2542 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2543 | | } |
| 0 | 2544 | | _httpRequest.Dispose(); |
| 0 | 2545 | | if (_httpResponse != null) |
| | 2546 | | { |
| 0 | 2547 | | _httpResponse.Dispose(); |
| | 2548 | | } |
| 0 | 2549 | | throw ex; |
| | 2550 | | } |
| | 2551 | | // Create Result |
| 2 | 2552 | | var _result = new HttpOperationResponse<int?>(); |
| 2 | 2553 | | _result.Request = _httpRequest; |
| 2 | 2554 | | _result.Response = _httpResponse; |
| | 2555 | | // Deserialize Response |
| 2 | 2556 | | if ((int)_statusCode == 200) |
| | 2557 | | { |
| 2 | 2558 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2559 | | try |
| | 2560 | | { |
| 2 | 2561 | | _result.Body = SafeJsonConvert.DeserializeObject<int?>(_responseContent, DeserializationSettings); |
| 2 | 2562 | | } |
| 0 | 2563 | | catch (JsonException ex) |
| | 2564 | | { |
| 0 | 2565 | | _httpRequest.Dispose(); |
| 0 | 2566 | | if (_httpResponse != null) |
| | 2567 | | { |
| 0 | 2568 | | _httpResponse.Dispose(); |
| | 2569 | | } |
| 0 | 2570 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2571 | | } |
| | 2572 | | } |
| 2 | 2573 | | if (_shouldTrace) |
| | 2574 | | { |
| 0 | 2575 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2576 | | } |
| 2 | 2577 | | return _result; |
| 2 | 2578 | | } |
| | 2579 | |
|
| | 2580 | | /// <summary> |
| | 2581 | | /// Add the provided batch of images to the set of training images. |
| | 2582 | | /// </summary> |
| | 2583 | | /// <remarks> |
| | 2584 | | /// This API accepts a batch of files, and optionally tags, to create images. |
| | 2585 | | /// There is a limit of 64 images and 20 tags. |
| | 2586 | | /// If all images are successful created, 200(OK) status code will be returned. |
| | 2587 | | /// Otherwise, 207 (Multi-Status) status code will be returned and detail |
| | 2588 | | /// status for each image will be listed in the response payload. |
| | 2589 | | /// </remarks> |
| | 2590 | | /// <param name='projectId'> |
| | 2591 | | /// The project id. |
| | 2592 | | /// </param> |
| | 2593 | | /// <param name='batch'> |
| | 2594 | | /// The batch of image files to add. Limited to 64 images and 20 tags per |
| | 2595 | | /// batch. |
| | 2596 | | /// </param> |
| | 2597 | | /// <param name='customHeaders'> |
| | 2598 | | /// Headers that will be added to request. |
| | 2599 | | /// </param> |
| | 2600 | | /// <param name='cancellationToken'> |
| | 2601 | | /// The cancellation token. |
| | 2602 | | /// </param> |
| | 2603 | | /// <exception cref="CustomVisionErrorException"> |
| | 2604 | | /// Thrown when the operation returned an invalid status code |
| | 2605 | | /// </exception> |
| | 2606 | | /// <exception cref="SerializationException"> |
| | 2607 | | /// Thrown when unable to deserialize the response |
| | 2608 | | /// </exception> |
| | 2609 | | /// <exception cref="ValidationException"> |
| | 2610 | | /// Thrown when a required parameter is null |
| | 2611 | | /// </exception> |
| | 2612 | | /// <exception cref="System.ArgumentNullException"> |
| | 2613 | | /// Thrown when a required parameter is null |
| | 2614 | | /// </exception> |
| | 2615 | | /// <return> |
| | 2616 | | /// A response object containing the response body and response headers. |
| | 2617 | | /// </return> |
| | 2618 | | public async Task<HttpOperationResponse<ImageCreateSummary>> CreateImagesFromFilesWithHttpMessagesAsync(System.G |
| | 2619 | | { |
| 8 | 2620 | | if (Endpoint == null) |
| | 2621 | | { |
| 0 | 2622 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 2623 | | } |
| 8 | 2624 | | if (batch == null) |
| | 2625 | | { |
| 0 | 2626 | | throw new ValidationException(ValidationRules.CannotBeNull, "batch"); |
| | 2627 | | } |
| | 2628 | | // Tracing |
| 8 | 2629 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 8 | 2630 | | string _invocationId = null; |
| 8 | 2631 | | if (_shouldTrace) |
| | 2632 | | { |
| 0 | 2633 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2634 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2635 | | tracingParameters.Add("projectId", projectId); |
| 0 | 2636 | | tracingParameters.Add("batch", batch); |
| 0 | 2637 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2638 | | ServiceClientTracing.Enter(_invocationId, this, "CreateImagesFromFiles", tracingParameters); |
| | 2639 | | } |
| | 2640 | | // Construct URL |
| 8 | 2641 | | var _baseUrl = BaseUri; |
| 8 | 2642 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/files"; |
| 8 | 2643 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 8 | 2644 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| | 2645 | | // Create HTTP transport objects |
| 8 | 2646 | | var _httpRequest = new HttpRequestMessage(); |
| 8 | 2647 | | HttpResponseMessage _httpResponse = null; |
| 8 | 2648 | | _httpRequest.Method = new HttpMethod("POST"); |
| 8 | 2649 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2650 | | // Set Headers |
| | 2651 | |
|
| | 2652 | |
|
| 8 | 2653 | | if (customHeaders != null) |
| | 2654 | | { |
| 0 | 2655 | | foreach(var _header in customHeaders) |
| | 2656 | | { |
| 0 | 2657 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2658 | | { |
| 0 | 2659 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2660 | | } |
| 0 | 2661 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2662 | | } |
| | 2663 | | } |
| | 2664 | |
|
| | 2665 | | // Serialize Request |
| 8 | 2666 | | string _requestContent = null; |
| 8 | 2667 | | if(batch != null) |
| | 2668 | | { |
| 8 | 2669 | | _requestContent = SafeJsonConvert.SerializeObject(batch, SerializationSettings); |
| 8 | 2670 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 8 | 2671 | | _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); |
| | 2672 | | } |
| | 2673 | | // Set Credentials |
| 8 | 2674 | | if (Credentials != null) |
| | 2675 | | { |
| 8 | 2676 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 2677 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2678 | | } |
| | 2679 | | // Send Request |
| 8 | 2680 | | if (_shouldTrace) |
| | 2681 | | { |
| 0 | 2682 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2683 | | } |
| 8 | 2684 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 2685 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 8 | 2686 | | if (_shouldTrace) |
| | 2687 | | { |
| 0 | 2688 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2689 | | } |
| 8 | 2690 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 8 | 2691 | | cancellationToken.ThrowIfCancellationRequested(); |
| 8 | 2692 | | string _responseContent = null; |
| 8 | 2693 | | if ((int)_statusCode != 200 && (int)_statusCode != 207) |
| | 2694 | | { |
| 0 | 2695 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 2696 | | try |
| | 2697 | | { |
| 0 | 2698 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2699 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 2700 | | if (_errorBody != null) |
| | 2701 | | { |
| 0 | 2702 | | ex.Body = _errorBody; |
| | 2703 | | } |
| 0 | 2704 | | } |
| 0 | 2705 | | catch (JsonException) |
| | 2706 | | { |
| | 2707 | | // Ignore the exception |
| 0 | 2708 | | } |
| 0 | 2709 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2710 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2711 | | if (_shouldTrace) |
| | 2712 | | { |
| 0 | 2713 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2714 | | } |
| 0 | 2715 | | _httpRequest.Dispose(); |
| 0 | 2716 | | if (_httpResponse != null) |
| | 2717 | | { |
| 0 | 2718 | | _httpResponse.Dispose(); |
| | 2719 | | } |
| 0 | 2720 | | throw ex; |
| | 2721 | | } |
| | 2722 | | // Create Result |
| 8 | 2723 | | var _result = new HttpOperationResponse<ImageCreateSummary>(); |
| 8 | 2724 | | _result.Request = _httpRequest; |
| 8 | 2725 | | _result.Response = _httpResponse; |
| | 2726 | | // Deserialize Response |
| 8 | 2727 | | if ((int)_statusCode == 200) |
| | 2728 | | { |
| 8 | 2729 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2730 | | try |
| | 2731 | | { |
| 8 | 2732 | | _result.Body = SafeJsonConvert.DeserializeObject<ImageCreateSummary>(_responseContent, Deserializati |
| 8 | 2733 | | } |
| 0 | 2734 | | catch (JsonException ex) |
| | 2735 | | { |
| 0 | 2736 | | _httpRequest.Dispose(); |
| 0 | 2737 | | if (_httpResponse != null) |
| | 2738 | | { |
| 0 | 2739 | | _httpResponse.Dispose(); |
| | 2740 | | } |
| 0 | 2741 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2742 | | } |
| | 2743 | | } |
| | 2744 | | // Deserialize Response |
| 8 | 2745 | | if ((int)_statusCode == 207) |
| | 2746 | | { |
| 0 | 2747 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2748 | | try |
| | 2749 | | { |
| 0 | 2750 | | _result.Body = SafeJsonConvert.DeserializeObject<ImageCreateSummary>(_responseContent, Deserializati |
| 0 | 2751 | | } |
| 0 | 2752 | | catch (JsonException ex) |
| | 2753 | | { |
| 0 | 2754 | | _httpRequest.Dispose(); |
| 0 | 2755 | | if (_httpResponse != null) |
| | 2756 | | { |
| 0 | 2757 | | _httpResponse.Dispose(); |
| | 2758 | | } |
| 0 | 2759 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2760 | | } |
| | 2761 | | } |
| 8 | 2762 | | if (_shouldTrace) |
| | 2763 | | { |
| 0 | 2764 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2765 | | } |
| 8 | 2766 | | return _result; |
| 8 | 2767 | | } |
| | 2768 | |
|
| | 2769 | | /// <summary> |
| | 2770 | | /// Get images by id for a given project iteration. |
| | 2771 | | /// </summary> |
| | 2772 | | /// <remarks> |
| | 2773 | | /// This API will return a set of Images for the specified tags and optionally |
| | 2774 | | /// iteration. If no iteration is specified the |
| | 2775 | | /// current workspace is used. |
| | 2776 | | /// </remarks> |
| | 2777 | | /// <param name='projectId'> |
| | 2778 | | /// The project id. |
| | 2779 | | /// </param> |
| | 2780 | | /// <param name='imageIds'> |
| | 2781 | | /// The list of image ids to retrieve. Limited to 256. |
| | 2782 | | /// </param> |
| | 2783 | | /// <param name='iterationId'> |
| | 2784 | | /// The iteration id. Defaults to workspace. |
| | 2785 | | /// </param> |
| | 2786 | | /// <param name='customHeaders'> |
| | 2787 | | /// Headers that will be added to request. |
| | 2788 | | /// </param> |
| | 2789 | | /// <param name='cancellationToken'> |
| | 2790 | | /// The cancellation token. |
| | 2791 | | /// </param> |
| | 2792 | | /// <exception cref="CustomVisionErrorException"> |
| | 2793 | | /// Thrown when the operation returned an invalid status code |
| | 2794 | | /// </exception> |
| | 2795 | | /// <exception cref="SerializationException"> |
| | 2796 | | /// Thrown when unable to deserialize the response |
| | 2797 | | /// </exception> |
| | 2798 | | /// <exception cref="ValidationException"> |
| | 2799 | | /// Thrown when a required parameter is null |
| | 2800 | | /// </exception> |
| | 2801 | | /// <exception cref="System.ArgumentNullException"> |
| | 2802 | | /// Thrown when a required parameter is null |
| | 2803 | | /// </exception> |
| | 2804 | | /// <return> |
| | 2805 | | /// A response object containing the response body and response headers. |
| | 2806 | | /// </return> |
| | 2807 | | public async Task<HttpOperationResponse<IList<Image>>> GetImagesByIdsWithHttpMessagesAsync(System.Guid projectId |
| | 2808 | | { |
| 6 | 2809 | | if (Endpoint == null) |
| | 2810 | | { |
| 0 | 2811 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 2812 | | } |
| 6 | 2813 | | if (imageIds != null) |
| | 2814 | | { |
| 6 | 2815 | | if (imageIds.Count > 256) |
| | 2816 | | { |
| 0 | 2817 | | throw new ValidationException(ValidationRules.MaxItems, "imageIds", 256); |
| | 2818 | | } |
| 6 | 2819 | | if (imageIds.Count < 0) |
| | 2820 | | { |
| 0 | 2821 | | throw new ValidationException(ValidationRules.MinItems, "imageIds", 0); |
| | 2822 | | } |
| | 2823 | | } |
| | 2824 | | // Tracing |
| 6 | 2825 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 6 | 2826 | | string _invocationId = null; |
| 6 | 2827 | | if (_shouldTrace) |
| | 2828 | | { |
| 0 | 2829 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 2830 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 2831 | | tracingParameters.Add("projectId", projectId); |
| 0 | 2832 | | tracingParameters.Add("imageIds", imageIds); |
| 0 | 2833 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 2834 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 2835 | | ServiceClientTracing.Enter(_invocationId, this, "GetImagesByIds", tracingParameters); |
| | 2836 | | } |
| | 2837 | | // Construct URL |
| 6 | 2838 | | var _baseUrl = BaseUri; |
| 6 | 2839 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/id"; |
| 6 | 2840 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 6 | 2841 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 6 | 2842 | | List<string> _queryParameters = new List<string>(); |
| 6 | 2843 | | if (imageIds != null) |
| | 2844 | | { |
| 6 | 2845 | | _queryParameters.Add(string.Format("imageIds={0}", System.Uri.EscapeDataString(string.Join(",", imageIds |
| | 2846 | | } |
| 6 | 2847 | | if (iterationId != null) |
| | 2848 | | { |
| 0 | 2849 | | _queryParameters.Add(string.Format("iterationId={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serial |
| | 2850 | | } |
| 6 | 2851 | | if (_queryParameters.Count > 0) |
| | 2852 | | { |
| 6 | 2853 | | _url += "?" + string.Join("&", _queryParameters); |
| | 2854 | | } |
| | 2855 | | // Create HTTP transport objects |
| 6 | 2856 | | var _httpRequest = new HttpRequestMessage(); |
| 6 | 2857 | | HttpResponseMessage _httpResponse = null; |
| 6 | 2858 | | _httpRequest.Method = new HttpMethod("GET"); |
| 6 | 2859 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 2860 | | // Set Headers |
| | 2861 | |
|
| | 2862 | |
|
| 6 | 2863 | | if (customHeaders != null) |
| | 2864 | | { |
| 0 | 2865 | | foreach(var _header in customHeaders) |
| | 2866 | | { |
| 0 | 2867 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 2868 | | { |
| 0 | 2869 | | _httpRequest.Headers.Remove(_header.Key); |
| | 2870 | | } |
| 0 | 2871 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 2872 | | } |
| | 2873 | | } |
| | 2874 | |
|
| | 2875 | | // Serialize Request |
| 6 | 2876 | | string _requestContent = null; |
| | 2877 | | // Set Credentials |
| 6 | 2878 | | if (Credentials != null) |
| | 2879 | | { |
| 6 | 2880 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 2881 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 2882 | | } |
| | 2883 | | // Send Request |
| 6 | 2884 | | if (_shouldTrace) |
| | 2885 | | { |
| 0 | 2886 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 2887 | | } |
| 6 | 2888 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 2889 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 6 | 2890 | | if (_shouldTrace) |
| | 2891 | | { |
| 0 | 2892 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 2893 | | } |
| 6 | 2894 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 6 | 2895 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 2896 | | string _responseContent = null; |
| 6 | 2897 | | if ((int)_statusCode != 200) |
| | 2898 | | { |
| 0 | 2899 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 2900 | | try |
| | 2901 | | { |
| 0 | 2902 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 2903 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 2904 | | if (_errorBody != null) |
| | 2905 | | { |
| 0 | 2906 | | ex.Body = _errorBody; |
| | 2907 | | } |
| 0 | 2908 | | } |
| 0 | 2909 | | catch (JsonException) |
| | 2910 | | { |
| | 2911 | | // Ignore the exception |
| 0 | 2912 | | } |
| 0 | 2913 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 2914 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 2915 | | if (_shouldTrace) |
| | 2916 | | { |
| 0 | 2917 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 2918 | | } |
| 0 | 2919 | | _httpRequest.Dispose(); |
| 0 | 2920 | | if (_httpResponse != null) |
| | 2921 | | { |
| 0 | 2922 | | _httpResponse.Dispose(); |
| | 2923 | | } |
| 0 | 2924 | | throw ex; |
| | 2925 | | } |
| | 2926 | | // Create Result |
| 6 | 2927 | | var _result = new HttpOperationResponse<IList<Image>>(); |
| 6 | 2928 | | _result.Request = _httpRequest; |
| 6 | 2929 | | _result.Response = _httpResponse; |
| | 2930 | | // Deserialize Response |
| 6 | 2931 | | if ((int)_statusCode == 200) |
| | 2932 | | { |
| 6 | 2933 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 2934 | | try |
| | 2935 | | { |
| 6 | 2936 | | _result.Body = SafeJsonConvert.DeserializeObject<IList<Image>>(_responseContent, DeserializationSett |
| 6 | 2937 | | } |
| 0 | 2938 | | catch (JsonException ex) |
| | 2939 | | { |
| 0 | 2940 | | _httpRequest.Dispose(); |
| 0 | 2941 | | if (_httpResponse != null) |
| | 2942 | | { |
| 0 | 2943 | | _httpResponse.Dispose(); |
| | 2944 | | } |
| 0 | 2945 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 2946 | | } |
| | 2947 | | } |
| 6 | 2948 | | if (_shouldTrace) |
| | 2949 | | { |
| 0 | 2950 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 2951 | | } |
| 6 | 2952 | | return _result; |
| 6 | 2953 | | } |
| | 2954 | |
|
| | 2955 | | /// <summary> |
| | 2956 | | /// Update metadata of images. |
| | 2957 | | /// </summary> |
| | 2958 | | /// <remarks> |
| | 2959 | | /// This API accepts a batch of image Ids, and metadata, to update images. |
| | 2960 | | /// There is a limit of 64 images. |
| | 2961 | | /// </remarks> |
| | 2962 | | /// <param name='projectId'> |
| | 2963 | | /// The project id. |
| | 2964 | | /// </param> |
| | 2965 | | /// <param name='imageIds'> |
| | 2966 | | /// The list of image ids to update. Limited to 64. |
| | 2967 | | /// </param> |
| | 2968 | | /// <param name='metadata'> |
| | 2969 | | /// The metadata to be updated to the specified images. Limited to 50 key-value |
| | 2970 | | /// pairs per image. The length of key is limited to 256. The length of value |
| | 2971 | | /// is limited to 512. |
| | 2972 | | /// </param> |
| | 2973 | | /// <param name='customHeaders'> |
| | 2974 | | /// Headers that will be added to request. |
| | 2975 | | /// </param> |
| | 2976 | | /// <param name='cancellationToken'> |
| | 2977 | | /// The cancellation token. |
| | 2978 | | /// </param> |
| | 2979 | | /// <exception cref="CustomVisionErrorException"> |
| | 2980 | | /// Thrown when the operation returned an invalid status code |
| | 2981 | | /// </exception> |
| | 2982 | | /// <exception cref="SerializationException"> |
| | 2983 | | /// Thrown when unable to deserialize the response |
| | 2984 | | /// </exception> |
| | 2985 | | /// <exception cref="ValidationException"> |
| | 2986 | | /// Thrown when a required parameter is null |
| | 2987 | | /// </exception> |
| | 2988 | | /// <exception cref="System.ArgumentNullException"> |
| | 2989 | | /// Thrown when a required parameter is null |
| | 2990 | | /// </exception> |
| | 2991 | | /// <return> |
| | 2992 | | /// A response object containing the response body and response headers. |
| | 2993 | | /// </return> |
| | 2994 | | public async Task<HttpOperationResponse<ImageMetadataUpdateSummary>> UpdateImageMetadataWithHttpMessagesAsync(Sy |
| | 2995 | | { |
| 2 | 2996 | | if (Endpoint == null) |
| | 2997 | | { |
| 0 | 2998 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 2999 | | } |
| 2 | 3000 | | if (imageIds == null) |
| | 3001 | | { |
| 0 | 3002 | | throw new ValidationException(ValidationRules.CannotBeNull, "imageIds"); |
| | 3003 | | } |
| 2 | 3004 | | if (imageIds != null) |
| | 3005 | | { |
| 2 | 3006 | | if (imageIds.Count > 256) |
| | 3007 | | { |
| 0 | 3008 | | throw new ValidationException(ValidationRules.MaxItems, "imageIds", 256); |
| | 3009 | | } |
| 2 | 3010 | | if (imageIds.Count < 0) |
| | 3011 | | { |
| 0 | 3012 | | throw new ValidationException(ValidationRules.MinItems, "imageIds", 0); |
| | 3013 | | } |
| | 3014 | | } |
| 2 | 3015 | | if (metadata == null) |
| | 3016 | | { |
| 0 | 3017 | | throw new ValidationException(ValidationRules.CannotBeNull, "metadata"); |
| | 3018 | | } |
| | 3019 | | // Tracing |
| 2 | 3020 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 3021 | | string _invocationId = null; |
| 2 | 3022 | | if (_shouldTrace) |
| | 3023 | | { |
| 0 | 3024 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3025 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3026 | | tracingParameters.Add("projectId", projectId); |
| 0 | 3027 | | tracingParameters.Add("imageIds", imageIds); |
| 0 | 3028 | | tracingParameters.Add("metadata", metadata); |
| 0 | 3029 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3030 | | ServiceClientTracing.Enter(_invocationId, this, "UpdateImageMetadata", tracingParameters); |
| | 3031 | | } |
| | 3032 | | // Construct URL |
| 2 | 3033 | | var _baseUrl = BaseUri; |
| 2 | 3034 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/metadata"; |
| 2 | 3035 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 3036 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 3037 | | List<string> _queryParameters = new List<string>(); |
| 2 | 3038 | | if (imageIds != null) |
| | 3039 | | { |
| 2 | 3040 | | _queryParameters.Add(string.Format("imageIds={0}", System.Uri.EscapeDataString(string.Join(",", imageIds |
| | 3041 | | } |
| 2 | 3042 | | if (_queryParameters.Count > 0) |
| | 3043 | | { |
| 2 | 3044 | | _url += "?" + string.Join("&", _queryParameters); |
| | 3045 | | } |
| | 3046 | | // Create HTTP transport objects |
| 2 | 3047 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 3048 | | HttpResponseMessage _httpResponse = null; |
| 2 | 3049 | | _httpRequest.Method = new HttpMethod("POST"); |
| 2 | 3050 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3051 | | // Set Headers |
| | 3052 | |
|
| | 3053 | |
|
| 2 | 3054 | | if (customHeaders != null) |
| | 3055 | | { |
| 0 | 3056 | | foreach(var _header in customHeaders) |
| | 3057 | | { |
| 0 | 3058 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3059 | | { |
| 0 | 3060 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3061 | | } |
| 0 | 3062 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3063 | | } |
| | 3064 | | } |
| | 3065 | |
|
| | 3066 | | // Serialize Request |
| 2 | 3067 | | string _requestContent = null; |
| 2 | 3068 | | if(metadata != null) |
| | 3069 | | { |
| 2 | 3070 | | _requestContent = SafeJsonConvert.SerializeObject(metadata, SerializationSettings); |
| 2 | 3071 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 2 | 3072 | | _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); |
| | 3073 | | } |
| | 3074 | | // Set Credentials |
| 2 | 3075 | | if (Credentials != null) |
| | 3076 | | { |
| 2 | 3077 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3078 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3079 | | } |
| | 3080 | | // Send Request |
| 2 | 3081 | | if (_shouldTrace) |
| | 3082 | | { |
| 0 | 3083 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3084 | | } |
| 2 | 3085 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3086 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 3087 | | if (_shouldTrace) |
| | 3088 | | { |
| 0 | 3089 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3090 | | } |
| 2 | 3091 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 3092 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3093 | | string _responseContent = null; |
| 2 | 3094 | | if ((int)_statusCode != 200 && (int)_statusCode != 207) |
| | 3095 | | { |
| 0 | 3096 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 3097 | | try |
| | 3098 | | { |
| 0 | 3099 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3100 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 3101 | | if (_errorBody != null) |
| | 3102 | | { |
| 0 | 3103 | | ex.Body = _errorBody; |
| | 3104 | | } |
| 0 | 3105 | | } |
| 0 | 3106 | | catch (JsonException) |
| | 3107 | | { |
| | 3108 | | // Ignore the exception |
| 0 | 3109 | | } |
| 0 | 3110 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3111 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3112 | | if (_shouldTrace) |
| | 3113 | | { |
| 0 | 3114 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3115 | | } |
| 0 | 3116 | | _httpRequest.Dispose(); |
| 0 | 3117 | | if (_httpResponse != null) |
| | 3118 | | { |
| 0 | 3119 | | _httpResponse.Dispose(); |
| | 3120 | | } |
| 0 | 3121 | | throw ex; |
| | 3122 | | } |
| | 3123 | | // Create Result |
| 2 | 3124 | | var _result = new HttpOperationResponse<ImageMetadataUpdateSummary>(); |
| 2 | 3125 | | _result.Request = _httpRequest; |
| 2 | 3126 | | _result.Response = _httpResponse; |
| | 3127 | | // Deserialize Response |
| 2 | 3128 | | if ((int)_statusCode == 200) |
| | 3129 | | { |
| 2 | 3130 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3131 | | try |
| | 3132 | | { |
| 2 | 3133 | | _result.Body = SafeJsonConvert.DeserializeObject<ImageMetadataUpdateSummary>(_responseContent, Deser |
| 2 | 3134 | | } |
| 0 | 3135 | | catch (JsonException ex) |
| | 3136 | | { |
| 0 | 3137 | | _httpRequest.Dispose(); |
| 0 | 3138 | | if (_httpResponse != null) |
| | 3139 | | { |
| 0 | 3140 | | _httpResponse.Dispose(); |
| | 3141 | | } |
| 0 | 3142 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3143 | | } |
| | 3144 | | } |
| | 3145 | | // Deserialize Response |
| 2 | 3146 | | if ((int)_statusCode == 207) |
| | 3147 | | { |
| 0 | 3148 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3149 | | try |
| | 3150 | | { |
| 0 | 3151 | | _result.Body = SafeJsonConvert.DeserializeObject<ImageMetadataUpdateSummary>(_responseContent, Deser |
| 0 | 3152 | | } |
| 0 | 3153 | | catch (JsonException ex) |
| | 3154 | | { |
| 0 | 3155 | | _httpRequest.Dispose(); |
| 0 | 3156 | | if (_httpResponse != null) |
| | 3157 | | { |
| 0 | 3158 | | _httpResponse.Dispose(); |
| | 3159 | | } |
| 0 | 3160 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3161 | | } |
| | 3162 | | } |
| 2 | 3163 | | if (_shouldTrace) |
| | 3164 | | { |
| 0 | 3165 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3166 | | } |
| 2 | 3167 | | return _result; |
| 2 | 3168 | | } |
| | 3169 | |
|
| | 3170 | | /// <summary> |
| | 3171 | | /// Add the specified predicted images to the set of training images. |
| | 3172 | | /// </summary> |
| | 3173 | | /// <remarks> |
| | 3174 | | /// This API creates a batch of images from predicted images specified. There |
| | 3175 | | /// is a limit of 64 images and 20 tags. |
| | 3176 | | /// If all images are successful created, 200(OK) status code will be returned. |
| | 3177 | | /// Otherwise, 207 (Multi-Status) status code will be returned and detail |
| | 3178 | | /// status for each image will be listed in the response payload. |
| | 3179 | | /// </remarks> |
| | 3180 | | /// <param name='projectId'> |
| | 3181 | | /// The project id. |
| | 3182 | | /// </param> |
| | 3183 | | /// <param name='batch'> |
| | 3184 | | /// Image, tag ids, and metadata. Limited to 64 images and 20 tags per batch. |
| | 3185 | | /// </param> |
| | 3186 | | /// <param name='customHeaders'> |
| | 3187 | | /// Headers that will be added to request. |
| | 3188 | | /// </param> |
| | 3189 | | /// <param name='cancellationToken'> |
| | 3190 | | /// The cancellation token. |
| | 3191 | | /// </param> |
| | 3192 | | /// <exception cref="CustomVisionErrorException"> |
| | 3193 | | /// Thrown when the operation returned an invalid status code |
| | 3194 | | /// </exception> |
| | 3195 | | /// <exception cref="SerializationException"> |
| | 3196 | | /// Thrown when unable to deserialize the response |
| | 3197 | | /// </exception> |
| | 3198 | | /// <exception cref="ValidationException"> |
| | 3199 | | /// Thrown when a required parameter is null |
| | 3200 | | /// </exception> |
| | 3201 | | /// <exception cref="System.ArgumentNullException"> |
| | 3202 | | /// Thrown when a required parameter is null |
| | 3203 | | /// </exception> |
| | 3204 | | /// <return> |
| | 3205 | | /// A response object containing the response body and response headers. |
| | 3206 | | /// </return> |
| | 3207 | | public async Task<HttpOperationResponse<ImageCreateSummary>> CreateImagesFromPredictionsWithHttpMessagesAsync(Sy |
| | 3208 | | { |
| 2 | 3209 | | if (Endpoint == null) |
| | 3210 | | { |
| 0 | 3211 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 3212 | | } |
| 2 | 3213 | | if (batch == null) |
| | 3214 | | { |
| 0 | 3215 | | throw new ValidationException(ValidationRules.CannotBeNull, "batch"); |
| | 3216 | | } |
| | 3217 | | // Tracing |
| 2 | 3218 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 3219 | | string _invocationId = null; |
| 2 | 3220 | | if (_shouldTrace) |
| | 3221 | | { |
| 0 | 3222 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3223 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3224 | | tracingParameters.Add("projectId", projectId); |
| 0 | 3225 | | tracingParameters.Add("batch", batch); |
| 0 | 3226 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3227 | | ServiceClientTracing.Enter(_invocationId, this, "CreateImagesFromPredictions", tracingParameters); |
| | 3228 | | } |
| | 3229 | | // Construct URL |
| 2 | 3230 | | var _baseUrl = BaseUri; |
| 2 | 3231 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/predictions"; |
| 2 | 3232 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 3233 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| | 3234 | | // Create HTTP transport objects |
| 2 | 3235 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 3236 | | HttpResponseMessage _httpResponse = null; |
| 2 | 3237 | | _httpRequest.Method = new HttpMethod("POST"); |
| 2 | 3238 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3239 | | // Set Headers |
| | 3240 | |
|
| | 3241 | |
|
| 2 | 3242 | | if (customHeaders != null) |
| | 3243 | | { |
| 0 | 3244 | | foreach(var _header in customHeaders) |
| | 3245 | | { |
| 0 | 3246 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3247 | | { |
| 0 | 3248 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3249 | | } |
| 0 | 3250 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3251 | | } |
| | 3252 | | } |
| | 3253 | |
|
| | 3254 | | // Serialize Request |
| 2 | 3255 | | string _requestContent = null; |
| 2 | 3256 | | if(batch != null) |
| | 3257 | | { |
| 2 | 3258 | | _requestContent = SafeJsonConvert.SerializeObject(batch, SerializationSettings); |
| 2 | 3259 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 2 | 3260 | | _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); |
| | 3261 | | } |
| | 3262 | | // Set Credentials |
| 2 | 3263 | | if (Credentials != null) |
| | 3264 | | { |
| 2 | 3265 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3266 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3267 | | } |
| | 3268 | | // Send Request |
| 2 | 3269 | | if (_shouldTrace) |
| | 3270 | | { |
| 0 | 3271 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3272 | | } |
| 2 | 3273 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3274 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 3275 | | if (_shouldTrace) |
| | 3276 | | { |
| 0 | 3277 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3278 | | } |
| 2 | 3279 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 3280 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3281 | | string _responseContent = null; |
| 2 | 3282 | | if ((int)_statusCode != 200 && (int)_statusCode != 207) |
| | 3283 | | { |
| 0 | 3284 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 3285 | | try |
| | 3286 | | { |
| 0 | 3287 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3288 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 3289 | | if (_errorBody != null) |
| | 3290 | | { |
| 0 | 3291 | | ex.Body = _errorBody; |
| | 3292 | | } |
| 0 | 3293 | | } |
| 0 | 3294 | | catch (JsonException) |
| | 3295 | | { |
| | 3296 | | // Ignore the exception |
| 0 | 3297 | | } |
| 0 | 3298 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3299 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3300 | | if (_shouldTrace) |
| | 3301 | | { |
| 0 | 3302 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3303 | | } |
| 0 | 3304 | | _httpRequest.Dispose(); |
| 0 | 3305 | | if (_httpResponse != null) |
| | 3306 | | { |
| 0 | 3307 | | _httpResponse.Dispose(); |
| | 3308 | | } |
| 0 | 3309 | | throw ex; |
| | 3310 | | } |
| | 3311 | | // Create Result |
| 2 | 3312 | | var _result = new HttpOperationResponse<ImageCreateSummary>(); |
| 2 | 3313 | | _result.Request = _httpRequest; |
| 2 | 3314 | | _result.Response = _httpResponse; |
| | 3315 | | // Deserialize Response |
| 2 | 3316 | | if ((int)_statusCode == 200) |
| | 3317 | | { |
| 2 | 3318 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3319 | | try |
| | 3320 | | { |
| 2 | 3321 | | _result.Body = SafeJsonConvert.DeserializeObject<ImageCreateSummary>(_responseContent, Deserializati |
| 2 | 3322 | | } |
| 0 | 3323 | | catch (JsonException ex) |
| | 3324 | | { |
| 0 | 3325 | | _httpRequest.Dispose(); |
| 0 | 3326 | | if (_httpResponse != null) |
| | 3327 | | { |
| 0 | 3328 | | _httpResponse.Dispose(); |
| | 3329 | | } |
| 0 | 3330 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3331 | | } |
| | 3332 | | } |
| | 3333 | | // Deserialize Response |
| 2 | 3334 | | if ((int)_statusCode == 207) |
| | 3335 | | { |
| 0 | 3336 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3337 | | try |
| | 3338 | | { |
| 0 | 3339 | | _result.Body = SafeJsonConvert.DeserializeObject<ImageCreateSummary>(_responseContent, Deserializati |
| 0 | 3340 | | } |
| 0 | 3341 | | catch (JsonException ex) |
| | 3342 | | { |
| 0 | 3343 | | _httpRequest.Dispose(); |
| 0 | 3344 | | if (_httpResponse != null) |
| | 3345 | | { |
| 0 | 3346 | | _httpResponse.Dispose(); |
| | 3347 | | } |
| 0 | 3348 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3349 | | } |
| | 3350 | | } |
| 2 | 3351 | | if (_shouldTrace) |
| | 3352 | | { |
| 0 | 3353 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3354 | | } |
| 2 | 3355 | | return _result; |
| 2 | 3356 | | } |
| | 3357 | |
|
| | 3358 | | /// <summary> |
| | 3359 | | /// Create a set of image regions. |
| | 3360 | | /// </summary> |
| | 3361 | | /// <remarks> |
| | 3362 | | /// This API accepts a batch of image regions, and optionally tags, to update |
| | 3363 | | /// existing images with region information. |
| | 3364 | | /// There is a limit of 64 entries in the batch. |
| | 3365 | | /// If all regions are successful created, 200(OK) status code will be |
| | 3366 | | /// returned. |
| | 3367 | | /// Otherwise, 207 (Multi-Status) status code will be returned and detail |
| | 3368 | | /// status for each region will be listed in the response payload. |
| | 3369 | | /// </remarks> |
| | 3370 | | /// <param name='projectId'> |
| | 3371 | | /// The project id. |
| | 3372 | | /// </param> |
| | 3373 | | /// <param name='batch'> |
| | 3374 | | /// Batch of image regions which include a tag and bounding box. Limited to 64. |
| | 3375 | | /// </param> |
| | 3376 | | /// <param name='customHeaders'> |
| | 3377 | | /// Headers that will be added to request. |
| | 3378 | | /// </param> |
| | 3379 | | /// <param name='cancellationToken'> |
| | 3380 | | /// The cancellation token. |
| | 3381 | | /// </param> |
| | 3382 | | /// <exception cref="CustomVisionErrorException"> |
| | 3383 | | /// Thrown when the operation returned an invalid status code |
| | 3384 | | /// </exception> |
| | 3385 | | /// <exception cref="SerializationException"> |
| | 3386 | | /// Thrown when unable to deserialize the response |
| | 3387 | | /// </exception> |
| | 3388 | | /// <exception cref="ValidationException"> |
| | 3389 | | /// Thrown when a required parameter is null |
| | 3390 | | /// </exception> |
| | 3391 | | /// <exception cref="System.ArgumentNullException"> |
| | 3392 | | /// Thrown when a required parameter is null |
| | 3393 | | /// </exception> |
| | 3394 | | /// <return> |
| | 3395 | | /// A response object containing the response body and response headers. |
| | 3396 | | /// </return> |
| | 3397 | | public async Task<HttpOperationResponse<ImageRegionCreateSummary>> CreateImageRegionsWithHttpMessagesAsync(Syste |
| | 3398 | | { |
| 2 | 3399 | | if (Endpoint == null) |
| | 3400 | | { |
| 0 | 3401 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 3402 | | } |
| 2 | 3403 | | if (batch == null) |
| | 3404 | | { |
| 0 | 3405 | | throw new ValidationException(ValidationRules.CannotBeNull, "batch"); |
| | 3406 | | } |
| | 3407 | | // Tracing |
| 2 | 3408 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 3409 | | string _invocationId = null; |
| 2 | 3410 | | if (_shouldTrace) |
| | 3411 | | { |
| 0 | 3412 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3413 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3414 | | tracingParameters.Add("projectId", projectId); |
| 0 | 3415 | | tracingParameters.Add("batch", batch); |
| 0 | 3416 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3417 | | ServiceClientTracing.Enter(_invocationId, this, "CreateImageRegions", tracingParameters); |
| | 3418 | | } |
| | 3419 | | // Construct URL |
| 2 | 3420 | | var _baseUrl = BaseUri; |
| 2 | 3421 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/regions"; |
| 2 | 3422 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 3423 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| | 3424 | | // Create HTTP transport objects |
| 2 | 3425 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 3426 | | HttpResponseMessage _httpResponse = null; |
| 2 | 3427 | | _httpRequest.Method = new HttpMethod("POST"); |
| 2 | 3428 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3429 | | // Set Headers |
| | 3430 | |
|
| | 3431 | |
|
| 2 | 3432 | | if (customHeaders != null) |
| | 3433 | | { |
| 0 | 3434 | | foreach(var _header in customHeaders) |
| | 3435 | | { |
| 0 | 3436 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3437 | | { |
| 0 | 3438 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3439 | | } |
| 0 | 3440 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3441 | | } |
| | 3442 | | } |
| | 3443 | |
|
| | 3444 | | // Serialize Request |
| 2 | 3445 | | string _requestContent = null; |
| 2 | 3446 | | if(batch != null) |
| | 3447 | | { |
| 2 | 3448 | | _requestContent = SafeJsonConvert.SerializeObject(batch, SerializationSettings); |
| 2 | 3449 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 2 | 3450 | | _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); |
| | 3451 | | } |
| | 3452 | | // Set Credentials |
| 2 | 3453 | | if (Credentials != null) |
| | 3454 | | { |
| 2 | 3455 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3456 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3457 | | } |
| | 3458 | | // Send Request |
| 2 | 3459 | | if (_shouldTrace) |
| | 3460 | | { |
| 0 | 3461 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3462 | | } |
| 2 | 3463 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3464 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 3465 | | if (_shouldTrace) |
| | 3466 | | { |
| 0 | 3467 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3468 | | } |
| 2 | 3469 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 3470 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3471 | | string _responseContent = null; |
| 2 | 3472 | | if ((int)_statusCode != 200 && (int)_statusCode != 207) |
| | 3473 | | { |
| 0 | 3474 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 3475 | | try |
| | 3476 | | { |
| 0 | 3477 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3478 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 3479 | | if (_errorBody != null) |
| | 3480 | | { |
| 0 | 3481 | | ex.Body = _errorBody; |
| | 3482 | | } |
| 0 | 3483 | | } |
| 0 | 3484 | | catch (JsonException) |
| | 3485 | | { |
| | 3486 | | // Ignore the exception |
| 0 | 3487 | | } |
| 0 | 3488 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3489 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3490 | | if (_shouldTrace) |
| | 3491 | | { |
| 0 | 3492 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3493 | | } |
| 0 | 3494 | | _httpRequest.Dispose(); |
| 0 | 3495 | | if (_httpResponse != null) |
| | 3496 | | { |
| 0 | 3497 | | _httpResponse.Dispose(); |
| | 3498 | | } |
| 0 | 3499 | | throw ex; |
| | 3500 | | } |
| | 3501 | | // Create Result |
| 2 | 3502 | | var _result = new HttpOperationResponse<ImageRegionCreateSummary>(); |
| 2 | 3503 | | _result.Request = _httpRequest; |
| 2 | 3504 | | _result.Response = _httpResponse; |
| | 3505 | | // Deserialize Response |
| 2 | 3506 | | if ((int)_statusCode == 200) |
| | 3507 | | { |
| 2 | 3508 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3509 | | try |
| | 3510 | | { |
| 2 | 3511 | | _result.Body = SafeJsonConvert.DeserializeObject<ImageRegionCreateSummary>(_responseContent, Deseria |
| 2 | 3512 | | } |
| 0 | 3513 | | catch (JsonException ex) |
| | 3514 | | { |
| 0 | 3515 | | _httpRequest.Dispose(); |
| 0 | 3516 | | if (_httpResponse != null) |
| | 3517 | | { |
| 0 | 3518 | | _httpResponse.Dispose(); |
| | 3519 | | } |
| 0 | 3520 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3521 | | } |
| | 3522 | | } |
| | 3523 | | // Deserialize Response |
| 2 | 3524 | | if ((int)_statusCode == 207) |
| | 3525 | | { |
| 0 | 3526 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3527 | | try |
| | 3528 | | { |
| 0 | 3529 | | _result.Body = SafeJsonConvert.DeserializeObject<ImageRegionCreateSummary>(_responseContent, Deseria |
| 0 | 3530 | | } |
| 0 | 3531 | | catch (JsonException ex) |
| | 3532 | | { |
| 0 | 3533 | | _httpRequest.Dispose(); |
| 0 | 3534 | | if (_httpResponse != null) |
| | 3535 | | { |
| 0 | 3536 | | _httpResponse.Dispose(); |
| | 3537 | | } |
| 0 | 3538 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3539 | | } |
| | 3540 | | } |
| 2 | 3541 | | if (_shouldTrace) |
| | 3542 | | { |
| 0 | 3543 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3544 | | } |
| 2 | 3545 | | return _result; |
| 2 | 3546 | | } |
| | 3547 | |
|
| | 3548 | | /// <summary> |
| | 3549 | | /// Delete a set of image regions. |
| | 3550 | | /// </summary> |
| | 3551 | | /// <param name='projectId'> |
| | 3552 | | /// The project id. |
| | 3553 | | /// </param> |
| | 3554 | | /// <param name='regionIds'> |
| | 3555 | | /// Regions to delete. Limited to 64. |
| | 3556 | | /// </param> |
| | 3557 | | /// <param name='customHeaders'> |
| | 3558 | | /// Headers that will be added to request. |
| | 3559 | | /// </param> |
| | 3560 | | /// <param name='cancellationToken'> |
| | 3561 | | /// The cancellation token. |
| | 3562 | | /// </param> |
| | 3563 | | /// <exception cref="CustomVisionErrorException"> |
| | 3564 | | /// Thrown when the operation returned an invalid status code |
| | 3565 | | /// </exception> |
| | 3566 | | /// <exception cref="ValidationException"> |
| | 3567 | | /// Thrown when a required parameter is null |
| | 3568 | | /// </exception> |
| | 3569 | | /// <exception cref="System.ArgumentNullException"> |
| | 3570 | | /// Thrown when a required parameter is null |
| | 3571 | | /// </exception> |
| | 3572 | | /// <return> |
| | 3573 | | /// A response object containing the response body and response headers. |
| | 3574 | | /// </return> |
| | 3575 | | public async Task<HttpOperationResponse> DeleteImageRegionsWithHttpMessagesAsync(System.Guid projectId, IList<Sy |
| | 3576 | | { |
| 2 | 3577 | | if (Endpoint == null) |
| | 3578 | | { |
| 0 | 3579 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 3580 | | } |
| 2 | 3581 | | if (regionIds == null) |
| | 3582 | | { |
| 0 | 3583 | | throw new ValidationException(ValidationRules.CannotBeNull, "regionIds"); |
| | 3584 | | } |
| 2 | 3585 | | if (regionIds != null) |
| | 3586 | | { |
| 2 | 3587 | | if (regionIds.Count > 64) |
| | 3588 | | { |
| 0 | 3589 | | throw new ValidationException(ValidationRules.MaxItems, "regionIds", 64); |
| | 3590 | | } |
| 2 | 3591 | | if (regionIds.Count < 0) |
| | 3592 | | { |
| 0 | 3593 | | throw new ValidationException(ValidationRules.MinItems, "regionIds", 0); |
| | 3594 | | } |
| | 3595 | | } |
| | 3596 | | // Tracing |
| 2 | 3597 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 3598 | | string _invocationId = null; |
| 2 | 3599 | | if (_shouldTrace) |
| | 3600 | | { |
| 0 | 3601 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3602 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3603 | | tracingParameters.Add("projectId", projectId); |
| 0 | 3604 | | tracingParameters.Add("regionIds", regionIds); |
| 0 | 3605 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3606 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteImageRegions", tracingParameters); |
| | 3607 | | } |
| | 3608 | | // Construct URL |
| 2 | 3609 | | var _baseUrl = BaseUri; |
| 2 | 3610 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/regions"; |
| 2 | 3611 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 3612 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 3613 | | List<string> _queryParameters = new List<string>(); |
| 2 | 3614 | | if (regionIds != null) |
| | 3615 | | { |
| 2 | 3616 | | _queryParameters.Add(string.Format("regionIds={0}", System.Uri.EscapeDataString(string.Join(",", regionI |
| | 3617 | | } |
| 2 | 3618 | | if (_queryParameters.Count > 0) |
| | 3619 | | { |
| 2 | 3620 | | _url += "?" + string.Join("&", _queryParameters); |
| | 3621 | | } |
| | 3622 | | // Create HTTP transport objects |
| 2 | 3623 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 3624 | | HttpResponseMessage _httpResponse = null; |
| 2 | 3625 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 2 | 3626 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3627 | | // Set Headers |
| | 3628 | |
|
| | 3629 | |
|
| 2 | 3630 | | if (customHeaders != null) |
| | 3631 | | { |
| 0 | 3632 | | foreach(var _header in customHeaders) |
| | 3633 | | { |
| 0 | 3634 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3635 | | { |
| 0 | 3636 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3637 | | } |
| 0 | 3638 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3639 | | } |
| | 3640 | | } |
| | 3641 | |
|
| | 3642 | | // Serialize Request |
| 2 | 3643 | | string _requestContent = null; |
| | 3644 | | // Set Credentials |
| 2 | 3645 | | if (Credentials != null) |
| | 3646 | | { |
| 2 | 3647 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3648 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3649 | | } |
| | 3650 | | // Send Request |
| 2 | 3651 | | if (_shouldTrace) |
| | 3652 | | { |
| 0 | 3653 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3654 | | } |
| 2 | 3655 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3656 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 3657 | | if (_shouldTrace) |
| | 3658 | | { |
| 0 | 3659 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3660 | | } |
| 2 | 3661 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 3662 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3663 | | string _responseContent = null; |
| 2 | 3664 | | if ((int)_statusCode != 204) |
| | 3665 | | { |
| 0 | 3666 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 3667 | | try |
| | 3668 | | { |
| 0 | 3669 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3670 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 3671 | | if (_errorBody != null) |
| | 3672 | | { |
| 0 | 3673 | | ex.Body = _errorBody; |
| | 3674 | | } |
| 0 | 3675 | | } |
| 0 | 3676 | | catch (JsonException) |
| | 3677 | | { |
| | 3678 | | // Ignore the exception |
| 0 | 3679 | | } |
| 0 | 3680 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3681 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3682 | | if (_shouldTrace) |
| | 3683 | | { |
| 0 | 3684 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3685 | | } |
| 0 | 3686 | | _httpRequest.Dispose(); |
| 0 | 3687 | | if (_httpResponse != null) |
| | 3688 | | { |
| 0 | 3689 | | _httpResponse.Dispose(); |
| | 3690 | | } |
| 0 | 3691 | | throw ex; |
| | 3692 | | } |
| | 3693 | | // Create Result |
| 2 | 3694 | | var _result = new HttpOperationResponse(); |
| 2 | 3695 | | _result.Request = _httpRequest; |
| 2 | 3696 | | _result.Response = _httpResponse; |
| 2 | 3697 | | if (_shouldTrace) |
| | 3698 | | { |
| 0 | 3699 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3700 | | } |
| 2 | 3701 | | return _result; |
| 2 | 3702 | | } |
| | 3703 | |
|
| | 3704 | | /// <summary> |
| | 3705 | | /// Get untagged images whose suggested tags match given tags. Returns empty |
| | 3706 | | /// array if no images are found. |
| | 3707 | | /// </summary> |
| | 3708 | | /// <remarks> |
| | 3709 | | /// This API will fetch untagged images filtered by suggested tags Ids. It |
| | 3710 | | /// returns an empty array if no images are found. |
| | 3711 | | /// </remarks> |
| | 3712 | | /// <param name='projectId'> |
| | 3713 | | /// The project id. |
| | 3714 | | /// </param> |
| | 3715 | | /// <param name='iterationId'> |
| | 3716 | | /// IterationId to use for the suggested tags and regions. |
| | 3717 | | /// </param> |
| | 3718 | | /// <param name='query'> |
| | 3719 | | /// Contains properties we need to query suggested images. |
| | 3720 | | /// </param> |
| | 3721 | | /// <param name='customHeaders'> |
| | 3722 | | /// Headers that will be added to request. |
| | 3723 | | /// </param> |
| | 3724 | | /// <param name='cancellationToken'> |
| | 3725 | | /// The cancellation token. |
| | 3726 | | /// </param> |
| | 3727 | | /// <exception cref="CustomVisionErrorException"> |
| | 3728 | | /// Thrown when the operation returned an invalid status code |
| | 3729 | | /// </exception> |
| | 3730 | | /// <exception cref="SerializationException"> |
| | 3731 | | /// Thrown when unable to deserialize the response |
| | 3732 | | /// </exception> |
| | 3733 | | /// <exception cref="ValidationException"> |
| | 3734 | | /// Thrown when a required parameter is null |
| | 3735 | | /// </exception> |
| | 3736 | | /// <exception cref="System.ArgumentNullException"> |
| | 3737 | | /// Thrown when a required parameter is null |
| | 3738 | | /// </exception> |
| | 3739 | | /// <return> |
| | 3740 | | /// A response object containing the response body and response headers. |
| | 3741 | | /// </return> |
| | 3742 | | public async Task<HttpOperationResponse<SuggestedTagAndRegionQuery>> QuerySuggestedImagesWithHttpMessagesAsync(S |
| | 3743 | | { |
| 2 | 3744 | | if (Endpoint == null) |
| | 3745 | | { |
| 0 | 3746 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 3747 | | } |
| 2 | 3748 | | if (query == null) |
| | 3749 | | { |
| 0 | 3750 | | throw new ValidationException(ValidationRules.CannotBeNull, "query"); |
| | 3751 | | } |
| | 3752 | | // Tracing |
| 2 | 3753 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 3754 | | string _invocationId = null; |
| 2 | 3755 | | if (_shouldTrace) |
| | 3756 | | { |
| 0 | 3757 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3758 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3759 | | tracingParameters.Add("projectId", projectId); |
| 0 | 3760 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 3761 | | tracingParameters.Add("query", query); |
| 0 | 3762 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3763 | | ServiceClientTracing.Enter(_invocationId, this, "QuerySuggestedImages", tracingParameters); |
| | 3764 | | } |
| | 3765 | | // Construct URL |
| 2 | 3766 | | var _baseUrl = BaseUri; |
| 2 | 3767 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/suggested"; |
| 2 | 3768 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 3769 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 3770 | | List<string> _queryParameters = new List<string>(); |
| 2 | 3771 | | _queryParameters.Add(string.Format("iterationId={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| 2 | 3772 | | if (_queryParameters.Count > 0) |
| | 3773 | | { |
| 2 | 3774 | | _url += "?" + string.Join("&", _queryParameters); |
| | 3775 | | } |
| | 3776 | | // Create HTTP transport objects |
| 2 | 3777 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 3778 | | HttpResponseMessage _httpResponse = null; |
| 2 | 3779 | | _httpRequest.Method = new HttpMethod("POST"); |
| 2 | 3780 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3781 | | // Set Headers |
| | 3782 | |
|
| | 3783 | |
|
| 2 | 3784 | | if (customHeaders != null) |
| | 3785 | | { |
| 0 | 3786 | | foreach(var _header in customHeaders) |
| | 3787 | | { |
| 0 | 3788 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3789 | | { |
| 0 | 3790 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3791 | | } |
| 0 | 3792 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3793 | | } |
| | 3794 | | } |
| | 3795 | |
|
| | 3796 | | // Serialize Request |
| 2 | 3797 | | string _requestContent = null; |
| 2 | 3798 | | if(query != null) |
| | 3799 | | { |
| 2 | 3800 | | _requestContent = SafeJsonConvert.SerializeObject(query, SerializationSettings); |
| 2 | 3801 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 2 | 3802 | | _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); |
| | 3803 | | } |
| | 3804 | | // Set Credentials |
| 2 | 3805 | | if (Credentials != null) |
| | 3806 | | { |
| 2 | 3807 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3808 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3809 | | } |
| | 3810 | | // Send Request |
| 2 | 3811 | | if (_shouldTrace) |
| | 3812 | | { |
| 0 | 3813 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3814 | | } |
| 2 | 3815 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3816 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 3817 | | if (_shouldTrace) |
| | 3818 | | { |
| 0 | 3819 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3820 | | } |
| 2 | 3821 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 3822 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 3823 | | string _responseContent = null; |
| 2 | 3824 | | if ((int)_statusCode != 200) |
| | 3825 | | { |
| 0 | 3826 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 3827 | | try |
| | 3828 | | { |
| 0 | 3829 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 3830 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 3831 | | if (_errorBody != null) |
| | 3832 | | { |
| 0 | 3833 | | ex.Body = _errorBody; |
| | 3834 | | } |
| 0 | 3835 | | } |
| 0 | 3836 | | catch (JsonException) |
| | 3837 | | { |
| | 3838 | | // Ignore the exception |
| 0 | 3839 | | } |
| 0 | 3840 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 3841 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 3842 | | if (_shouldTrace) |
| | 3843 | | { |
| 0 | 3844 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 3845 | | } |
| 0 | 3846 | | _httpRequest.Dispose(); |
| 0 | 3847 | | if (_httpResponse != null) |
| | 3848 | | { |
| 0 | 3849 | | _httpResponse.Dispose(); |
| | 3850 | | } |
| 0 | 3851 | | throw ex; |
| | 3852 | | } |
| | 3853 | | // Create Result |
| 2 | 3854 | | var _result = new HttpOperationResponse<SuggestedTagAndRegionQuery>(); |
| 2 | 3855 | | _result.Request = _httpRequest; |
| 2 | 3856 | | _result.Response = _httpResponse; |
| | 3857 | | // Deserialize Response |
| 2 | 3858 | | if ((int)_statusCode == 200) |
| | 3859 | | { |
| 2 | 3860 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 3861 | | try |
| | 3862 | | { |
| 2 | 3863 | | _result.Body = SafeJsonConvert.DeserializeObject<SuggestedTagAndRegionQuery>(_responseContent, Deser |
| 2 | 3864 | | } |
| 0 | 3865 | | catch (JsonException ex) |
| | 3866 | | { |
| 0 | 3867 | | _httpRequest.Dispose(); |
| 0 | 3868 | | if (_httpResponse != null) |
| | 3869 | | { |
| 0 | 3870 | | _httpResponse.Dispose(); |
| | 3871 | | } |
| 0 | 3872 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 3873 | | } |
| | 3874 | | } |
| 2 | 3875 | | if (_shouldTrace) |
| | 3876 | | { |
| 0 | 3877 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 3878 | | } |
| 2 | 3879 | | return _result; |
| 2 | 3880 | | } |
| | 3881 | |
|
| | 3882 | | /// <summary> |
| | 3883 | | /// Get count of images whose suggested tags match given tags and their |
| | 3884 | | /// probabilities are greater than or equal to the given threshold. Returns |
| | 3885 | | /// count as 0 if none found. |
| | 3886 | | /// </summary> |
| | 3887 | | /// <remarks> |
| | 3888 | | /// This API takes in tagIds to get count of untagged images per suggested tags |
| | 3889 | | /// for a given threshold. |
| | 3890 | | /// </remarks> |
| | 3891 | | /// <param name='projectId'> |
| | 3892 | | /// The project id. |
| | 3893 | | /// </param> |
| | 3894 | | /// <param name='iterationId'> |
| | 3895 | | /// IterationId to use for the suggested tags and regions. |
| | 3896 | | /// </param> |
| | 3897 | | /// <param name='query'> |
| | 3898 | | /// Model that contains tagIds, threshold and projectType to query by. |
| | 3899 | | /// </param> |
| | 3900 | | /// <param name='customHeaders'> |
| | 3901 | | /// Headers that will be added to request. |
| | 3902 | | /// </param> |
| | 3903 | | /// <param name='cancellationToken'> |
| | 3904 | | /// The cancellation token. |
| | 3905 | | /// </param> |
| | 3906 | | /// <exception cref="CustomVisionErrorException"> |
| | 3907 | | /// Thrown when the operation returned an invalid status code |
| | 3908 | | /// </exception> |
| | 3909 | | /// <exception cref="SerializationException"> |
| | 3910 | | /// Thrown when unable to deserialize the response |
| | 3911 | | /// </exception> |
| | 3912 | | /// <exception cref="ValidationException"> |
| | 3913 | | /// Thrown when a required parameter is null |
| | 3914 | | /// </exception> |
| | 3915 | | /// <exception cref="System.ArgumentNullException"> |
| | 3916 | | /// Thrown when a required parameter is null |
| | 3917 | | /// </exception> |
| | 3918 | | /// <return> |
| | 3919 | | /// A response object containing the response body and response headers. |
| | 3920 | | /// </return> |
| | 3921 | | public async Task<HttpOperationResponse<IDictionary<string, int?>>> QuerySuggestedImageCountWithHttpMessagesAsyn |
| | 3922 | | { |
| 6 | 3923 | | if (Endpoint == null) |
| | 3924 | | { |
| 0 | 3925 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 3926 | | } |
| 6 | 3927 | | if (query == null) |
| | 3928 | | { |
| 0 | 3929 | | throw new ValidationException(ValidationRules.CannotBeNull, "query"); |
| | 3930 | | } |
| | 3931 | | // Tracing |
| 6 | 3932 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 6 | 3933 | | string _invocationId = null; |
| 6 | 3934 | | if (_shouldTrace) |
| | 3935 | | { |
| 0 | 3936 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 3937 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 3938 | | tracingParameters.Add("projectId", projectId); |
| 0 | 3939 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 3940 | | tracingParameters.Add("query", query); |
| 0 | 3941 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 3942 | | ServiceClientTracing.Enter(_invocationId, this, "QuerySuggestedImageCount", tracingParameters); |
| | 3943 | | } |
| | 3944 | | // Construct URL |
| 6 | 3945 | | var _baseUrl = BaseUri; |
| 6 | 3946 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/suggested/count"; |
| 6 | 3947 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 6 | 3948 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 6 | 3949 | | List<string> _queryParameters = new List<string>(); |
| 6 | 3950 | | _queryParameters.Add(string.Format("iterationId={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| 6 | 3951 | | if (_queryParameters.Count > 0) |
| | 3952 | | { |
| 6 | 3953 | | _url += "?" + string.Join("&", _queryParameters); |
| | 3954 | | } |
| | 3955 | | // Create HTTP transport objects |
| 6 | 3956 | | var _httpRequest = new HttpRequestMessage(); |
| 6 | 3957 | | HttpResponseMessage _httpResponse = null; |
| 6 | 3958 | | _httpRequest.Method = new HttpMethod("POST"); |
| 6 | 3959 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 3960 | | // Set Headers |
| | 3961 | |
|
| | 3962 | |
|
| 6 | 3963 | | if (customHeaders != null) |
| | 3964 | | { |
| 0 | 3965 | | foreach(var _header in customHeaders) |
| | 3966 | | { |
| 0 | 3967 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 3968 | | { |
| 0 | 3969 | | _httpRequest.Headers.Remove(_header.Key); |
| | 3970 | | } |
| 0 | 3971 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 3972 | | } |
| | 3973 | | } |
| | 3974 | |
|
| | 3975 | | // Serialize Request |
| 6 | 3976 | | string _requestContent = null; |
| 6 | 3977 | | if(query != null) |
| | 3978 | | { |
| 6 | 3979 | | _requestContent = SafeJsonConvert.SerializeObject(query, SerializationSettings); |
| 6 | 3980 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 6 | 3981 | | _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); |
| | 3982 | | } |
| | 3983 | | // Set Credentials |
| 6 | 3984 | | if (Credentials != null) |
| | 3985 | | { |
| 6 | 3986 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 3987 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 3988 | | } |
| | 3989 | | // Send Request |
| 6 | 3990 | | if (_shouldTrace) |
| | 3991 | | { |
| 0 | 3992 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 3993 | | } |
| 6 | 3994 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 3995 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 6 | 3996 | | if (_shouldTrace) |
| | 3997 | | { |
| 0 | 3998 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 3999 | | } |
| 6 | 4000 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 6 | 4001 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 4002 | | string _responseContent = null; |
| 6 | 4003 | | if ((int)_statusCode != 200) |
| | 4004 | | { |
| 0 | 4005 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 4006 | | try |
| | 4007 | | { |
| 0 | 4008 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 4009 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 4010 | | if (_errorBody != null) |
| | 4011 | | { |
| 0 | 4012 | | ex.Body = _errorBody; |
| | 4013 | | } |
| 0 | 4014 | | } |
| 0 | 4015 | | catch (JsonException) |
| | 4016 | | { |
| | 4017 | | // Ignore the exception |
| 0 | 4018 | | } |
| 0 | 4019 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 4020 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 4021 | | if (_shouldTrace) |
| | 4022 | | { |
| 0 | 4023 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 4024 | | } |
| 0 | 4025 | | _httpRequest.Dispose(); |
| 0 | 4026 | | if (_httpResponse != null) |
| | 4027 | | { |
| 0 | 4028 | | _httpResponse.Dispose(); |
| | 4029 | | } |
| 0 | 4030 | | throw ex; |
| | 4031 | | } |
| | 4032 | | // Create Result |
| 6 | 4033 | | var _result = new HttpOperationResponse<IDictionary<string, int?>>(); |
| 6 | 4034 | | _result.Request = _httpRequest; |
| 6 | 4035 | | _result.Response = _httpResponse; |
| | 4036 | | // Deserialize Response |
| 6 | 4037 | | if ((int)_statusCode == 200) |
| | 4038 | | { |
| 6 | 4039 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 4040 | | try |
| | 4041 | | { |
| 6 | 4042 | | _result.Body = SafeJsonConvert.DeserializeObject<IDictionary<string, int?>>(_responseContent, Deseri |
| 6 | 4043 | | } |
| 0 | 4044 | | catch (JsonException ex) |
| | 4045 | | { |
| 0 | 4046 | | _httpRequest.Dispose(); |
| 0 | 4047 | | if (_httpResponse != null) |
| | 4048 | | { |
| 0 | 4049 | | _httpResponse.Dispose(); |
| | 4050 | | } |
| 0 | 4051 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 4052 | | } |
| | 4053 | | } |
| 6 | 4054 | | if (_shouldTrace) |
| | 4055 | | { |
| 0 | 4056 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 4057 | | } |
| 6 | 4058 | | return _result; |
| 6 | 4059 | | } |
| | 4060 | |
|
| | 4061 | | /// <summary> |
| | 4062 | | /// Get tagged images for a given project iteration. |
| | 4063 | | /// </summary> |
| | 4064 | | /// <remarks> |
| | 4065 | | /// This API supports batching and range selection. By default it will only |
| | 4066 | | /// return first 50 images matching images. |
| | 4067 | | /// Use the {take} and {skip} parameters to control how many images to return |
| | 4068 | | /// in a given batch. |
| | 4069 | | /// The filtering is on an and/or relationship. For example, if the provided |
| | 4070 | | /// tag ids are for the "Dog" and |
| | 4071 | | /// "Cat" tags, then only images tagged with Dog and/or Cat will be returned |
| | 4072 | | /// </remarks> |
| | 4073 | | /// <param name='projectId'> |
| | 4074 | | /// The project id. |
| | 4075 | | /// </param> |
| | 4076 | | /// <param name='iterationId'> |
| | 4077 | | /// The iteration id. Defaults to workspace. |
| | 4078 | | /// </param> |
| | 4079 | | /// <param name='tagIds'> |
| | 4080 | | /// A list of tags ids to filter the images. Defaults to all tagged images when |
| | 4081 | | /// null. Limited to 20. |
| | 4082 | | /// </param> |
| | 4083 | | /// <param name='orderBy'> |
| | 4084 | | /// The ordering. Defaults to newest. Possible values include: 'Newest', |
| | 4085 | | /// 'Oldest' |
| | 4086 | | /// </param> |
| | 4087 | | /// <param name='take'> |
| | 4088 | | /// Maximum number of images to return. Defaults to 50, limited to 256. |
| | 4089 | | /// </param> |
| | 4090 | | /// <param name='skip'> |
| | 4091 | | /// Number of images to skip before beginning the image batch. Defaults to 0. |
| | 4092 | | /// </param> |
| | 4093 | | /// <param name='customHeaders'> |
| | 4094 | | /// Headers that will be added to request. |
| | 4095 | | /// </param> |
| | 4096 | | /// <param name='cancellationToken'> |
| | 4097 | | /// The cancellation token. |
| | 4098 | | /// </param> |
| | 4099 | | /// <exception cref="CustomVisionErrorException"> |
| | 4100 | | /// Thrown when the operation returned an invalid status code |
| | 4101 | | /// </exception> |
| | 4102 | | /// <exception cref="SerializationException"> |
| | 4103 | | /// Thrown when unable to deserialize the response |
| | 4104 | | /// </exception> |
| | 4105 | | /// <exception cref="ValidationException"> |
| | 4106 | | /// Thrown when a required parameter is null |
| | 4107 | | /// </exception> |
| | 4108 | | /// <exception cref="System.ArgumentNullException"> |
| | 4109 | | /// Thrown when a required parameter is null |
| | 4110 | | /// </exception> |
| | 4111 | | /// <return> |
| | 4112 | | /// A response object containing the response body and response headers. |
| | 4113 | | /// </return> |
| | 4114 | | public async Task<HttpOperationResponse<IList<Image>>> GetTaggedImagesWithHttpMessagesAsync(System.Guid projectI |
| | 4115 | | { |
| 12 | 4116 | | if (Endpoint == null) |
| | 4117 | | { |
| 0 | 4118 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 4119 | | } |
| 12 | 4120 | | if (tagIds != null) |
| | 4121 | | { |
| 4 | 4122 | | if (tagIds.Count > 20) |
| | 4123 | | { |
| 0 | 4124 | | throw new ValidationException(ValidationRules.MaxItems, "tagIds", 20); |
| | 4125 | | } |
| 4 | 4126 | | if (tagIds.Count < 0) |
| | 4127 | | { |
| 0 | 4128 | | throw new ValidationException(ValidationRules.MinItems, "tagIds", 0); |
| | 4129 | | } |
| | 4130 | | } |
| 12 | 4131 | | if (take > 256) |
| | 4132 | | { |
| 0 | 4133 | | throw new ValidationException(ValidationRules.InclusiveMaximum, "take", 256); |
| | 4134 | | } |
| 12 | 4135 | | if (take < 0) |
| | 4136 | | { |
| 0 | 4137 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "take", 0); |
| | 4138 | | } |
| | 4139 | | // Tracing |
| 12 | 4140 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 12 | 4141 | | string _invocationId = null; |
| 12 | 4142 | | if (_shouldTrace) |
| | 4143 | | { |
| 0 | 4144 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 4145 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 4146 | | tracingParameters.Add("projectId", projectId); |
| 0 | 4147 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 4148 | | tracingParameters.Add("tagIds", tagIds); |
| 0 | 4149 | | tracingParameters.Add("orderBy", orderBy); |
| 0 | 4150 | | tracingParameters.Add("take", take); |
| 0 | 4151 | | tracingParameters.Add("skip", skip); |
| 0 | 4152 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 4153 | | ServiceClientTracing.Enter(_invocationId, this, "GetTaggedImages", tracingParameters); |
| | 4154 | | } |
| | 4155 | | // Construct URL |
| 12 | 4156 | | var _baseUrl = BaseUri; |
| 12 | 4157 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/tagged"; |
| 12 | 4158 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 12 | 4159 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 12 | 4160 | | List<string> _queryParameters = new List<string>(); |
| 12 | 4161 | | if (iterationId != null) |
| | 4162 | | { |
| 0 | 4163 | | _queryParameters.Add(string.Format("iterationId={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serial |
| | 4164 | | } |
| 12 | 4165 | | if (tagIds != null) |
| | 4166 | | { |
| 4 | 4167 | | _queryParameters.Add(string.Format("tagIds={0}", System.Uri.EscapeDataString(string.Join(",", tagIds)))) |
| | 4168 | | } |
| 12 | 4169 | | if (orderBy != null) |
| | 4170 | | { |
| 0 | 4171 | | _queryParameters.Add(string.Format("orderBy={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 4172 | | } |
| 12 | 4173 | | if (take != null) |
| | 4174 | | { |
| 12 | 4175 | | _queryParameters.Add(string.Format("take={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObje |
| | 4176 | | } |
| 12 | 4177 | | if (skip != null) |
| | 4178 | | { |
| 12 | 4179 | | _queryParameters.Add(string.Format("skip={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObje |
| | 4180 | | } |
| 12 | 4181 | | if (_queryParameters.Count > 0) |
| | 4182 | | { |
| 12 | 4183 | | _url += "?" + string.Join("&", _queryParameters); |
| | 4184 | | } |
| | 4185 | | // Create HTTP transport objects |
| 12 | 4186 | | var _httpRequest = new HttpRequestMessage(); |
| 12 | 4187 | | HttpResponseMessage _httpResponse = null; |
| 12 | 4188 | | _httpRequest.Method = new HttpMethod("GET"); |
| 12 | 4189 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 4190 | | // Set Headers |
| | 4191 | |
|
| | 4192 | |
|
| 12 | 4193 | | if (customHeaders != null) |
| | 4194 | | { |
| 0 | 4195 | | foreach(var _header in customHeaders) |
| | 4196 | | { |
| 0 | 4197 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 4198 | | { |
| 0 | 4199 | | _httpRequest.Headers.Remove(_header.Key); |
| | 4200 | | } |
| 0 | 4201 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 4202 | | } |
| | 4203 | | } |
| | 4204 | |
|
| | 4205 | | // Serialize Request |
| 12 | 4206 | | string _requestContent = null; |
| | 4207 | | // Set Credentials |
| 12 | 4208 | | if (Credentials != null) |
| | 4209 | | { |
| 12 | 4210 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 4211 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 4212 | | } |
| | 4213 | | // Send Request |
| 12 | 4214 | | if (_shouldTrace) |
| | 4215 | | { |
| 0 | 4216 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 4217 | | } |
| 12 | 4218 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 4219 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 12 | 4220 | | if (_shouldTrace) |
| | 4221 | | { |
| 0 | 4222 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 4223 | | } |
| 12 | 4224 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 12 | 4225 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 4226 | | string _responseContent = null; |
| 12 | 4227 | | if ((int)_statusCode != 200) |
| | 4228 | | { |
| 0 | 4229 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 4230 | | try |
| | 4231 | | { |
| 0 | 4232 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 4233 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 4234 | | if (_errorBody != null) |
| | 4235 | | { |
| 0 | 4236 | | ex.Body = _errorBody; |
| | 4237 | | } |
| 0 | 4238 | | } |
| 0 | 4239 | | catch (JsonException) |
| | 4240 | | { |
| | 4241 | | // Ignore the exception |
| 0 | 4242 | | } |
| 0 | 4243 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 4244 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 4245 | | if (_shouldTrace) |
| | 4246 | | { |
| 0 | 4247 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 4248 | | } |
| 0 | 4249 | | _httpRequest.Dispose(); |
| 0 | 4250 | | if (_httpResponse != null) |
| | 4251 | | { |
| 0 | 4252 | | _httpResponse.Dispose(); |
| | 4253 | | } |
| 0 | 4254 | | throw ex; |
| | 4255 | | } |
| | 4256 | | // Create Result |
| 12 | 4257 | | var _result = new HttpOperationResponse<IList<Image>>(); |
| 12 | 4258 | | _result.Request = _httpRequest; |
| 12 | 4259 | | _result.Response = _httpResponse; |
| | 4260 | | // Deserialize Response |
| 12 | 4261 | | if ((int)_statusCode == 200) |
| | 4262 | | { |
| 12 | 4263 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 4264 | | try |
| | 4265 | | { |
| 12 | 4266 | | _result.Body = SafeJsonConvert.DeserializeObject<IList<Image>>(_responseContent, DeserializationSett |
| 12 | 4267 | | } |
| 0 | 4268 | | catch (JsonException ex) |
| | 4269 | | { |
| 0 | 4270 | | _httpRequest.Dispose(); |
| 0 | 4271 | | if (_httpResponse != null) |
| | 4272 | | { |
| 0 | 4273 | | _httpResponse.Dispose(); |
| | 4274 | | } |
| 0 | 4275 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 4276 | | } |
| | 4277 | | } |
| 12 | 4278 | | if (_shouldTrace) |
| | 4279 | | { |
| 0 | 4280 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 4281 | | } |
| 12 | 4282 | | return _result; |
| 12 | 4283 | | } |
| | 4284 | |
|
| | 4285 | | /// <summary> |
| | 4286 | | /// Gets the number of images tagged with the provided {tagIds}. |
| | 4287 | | /// </summary> |
| | 4288 | | /// <remarks> |
| | 4289 | | /// The filtering is on an and/or relationship. For example, if the provided |
| | 4290 | | /// tag ids are for the "Dog" and |
| | 4291 | | /// "Cat" tags, then only images tagged with Dog and/or Cat will be returned |
| | 4292 | | /// </remarks> |
| | 4293 | | /// <param name='projectId'> |
| | 4294 | | /// The project id. |
| | 4295 | | /// </param> |
| | 4296 | | /// <param name='iterationId'> |
| | 4297 | | /// The iteration id. Defaults to workspace. |
| | 4298 | | /// </param> |
| | 4299 | | /// <param name='tagIds'> |
| | 4300 | | /// A list of tags ids to filter the images to count. Defaults to all tags when |
| | 4301 | | /// null. |
| | 4302 | | /// </param> |
| | 4303 | | /// <param name='customHeaders'> |
| | 4304 | | /// Headers that will be added to request. |
| | 4305 | | /// </param> |
| | 4306 | | /// <param name='cancellationToken'> |
| | 4307 | | /// The cancellation token. |
| | 4308 | | /// </param> |
| | 4309 | | /// <exception cref="CustomVisionErrorException"> |
| | 4310 | | /// Thrown when the operation returned an invalid status code |
| | 4311 | | /// </exception> |
| | 4312 | | /// <exception cref="SerializationException"> |
| | 4313 | | /// Thrown when unable to deserialize the response |
| | 4314 | | /// </exception> |
| | 4315 | | /// <exception cref="ValidationException"> |
| | 4316 | | /// Thrown when a required parameter is null |
| | 4317 | | /// </exception> |
| | 4318 | | /// <exception cref="System.ArgumentNullException"> |
| | 4319 | | /// Thrown when a required parameter is null |
| | 4320 | | /// </exception> |
| | 4321 | | /// <return> |
| | 4322 | | /// A response object containing the response body and response headers. |
| | 4323 | | /// </return> |
| | 4324 | | public async Task<HttpOperationResponse<int?>> GetTaggedImageCountWithHttpMessagesAsync(System.Guid projectId, S |
| | 4325 | | { |
| 6 | 4326 | | if (Endpoint == null) |
| | 4327 | | { |
| 0 | 4328 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 4329 | | } |
| | 4330 | | // Tracing |
| 6 | 4331 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 6 | 4332 | | string _invocationId = null; |
| 6 | 4333 | | if (_shouldTrace) |
| | 4334 | | { |
| 0 | 4335 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 4336 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 4337 | | tracingParameters.Add("projectId", projectId); |
| 0 | 4338 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 4339 | | tracingParameters.Add("tagIds", tagIds); |
| 0 | 4340 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 4341 | | ServiceClientTracing.Enter(_invocationId, this, "GetTaggedImageCount", tracingParameters); |
| | 4342 | | } |
| | 4343 | | // Construct URL |
| 6 | 4344 | | var _baseUrl = BaseUri; |
| 6 | 4345 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/tagged/count"; |
| 6 | 4346 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 6 | 4347 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 6 | 4348 | | List<string> _queryParameters = new List<string>(); |
| 6 | 4349 | | if (iterationId != null) |
| | 4350 | | { |
| 0 | 4351 | | _queryParameters.Add(string.Format("iterationId={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serial |
| | 4352 | | } |
| 6 | 4353 | | if (tagIds != null) |
| | 4354 | | { |
| 0 | 4355 | | _queryParameters.Add(string.Format("tagIds={0}", System.Uri.EscapeDataString(string.Join(",", tagIds)))) |
| | 4356 | | } |
| 6 | 4357 | | if (_queryParameters.Count > 0) |
| | 4358 | | { |
| 0 | 4359 | | _url += "?" + string.Join("&", _queryParameters); |
| | 4360 | | } |
| | 4361 | | // Create HTTP transport objects |
| 6 | 4362 | | var _httpRequest = new HttpRequestMessage(); |
| 6 | 4363 | | HttpResponseMessage _httpResponse = null; |
| 6 | 4364 | | _httpRequest.Method = new HttpMethod("GET"); |
| 6 | 4365 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 4366 | | // Set Headers |
| | 4367 | |
|
| | 4368 | |
|
| 6 | 4369 | | if (customHeaders != null) |
| | 4370 | | { |
| 0 | 4371 | | foreach(var _header in customHeaders) |
| | 4372 | | { |
| 0 | 4373 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 4374 | | { |
| 0 | 4375 | | _httpRequest.Headers.Remove(_header.Key); |
| | 4376 | | } |
| 0 | 4377 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 4378 | | } |
| | 4379 | | } |
| | 4380 | |
|
| | 4381 | | // Serialize Request |
| 6 | 4382 | | string _requestContent = null; |
| | 4383 | | // Set Credentials |
| 6 | 4384 | | if (Credentials != null) |
| | 4385 | | { |
| 6 | 4386 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 4387 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 4388 | | } |
| | 4389 | | // Send Request |
| 6 | 4390 | | if (_shouldTrace) |
| | 4391 | | { |
| 0 | 4392 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 4393 | | } |
| 6 | 4394 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 4395 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 6 | 4396 | | if (_shouldTrace) |
| | 4397 | | { |
| 0 | 4398 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 4399 | | } |
| 6 | 4400 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 6 | 4401 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 4402 | | string _responseContent = null; |
| 6 | 4403 | | if ((int)_statusCode != 200) |
| | 4404 | | { |
| 0 | 4405 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 4406 | | try |
| | 4407 | | { |
| 0 | 4408 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 4409 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 4410 | | if (_errorBody != null) |
| | 4411 | | { |
| 0 | 4412 | | ex.Body = _errorBody; |
| | 4413 | | } |
| 0 | 4414 | | } |
| 0 | 4415 | | catch (JsonException) |
| | 4416 | | { |
| | 4417 | | // Ignore the exception |
| 0 | 4418 | | } |
| 0 | 4419 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 4420 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 4421 | | if (_shouldTrace) |
| | 4422 | | { |
| 0 | 4423 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 4424 | | } |
| 0 | 4425 | | _httpRequest.Dispose(); |
| 0 | 4426 | | if (_httpResponse != null) |
| | 4427 | | { |
| 0 | 4428 | | _httpResponse.Dispose(); |
| | 4429 | | } |
| 0 | 4430 | | throw ex; |
| | 4431 | | } |
| | 4432 | | // Create Result |
| 6 | 4433 | | var _result = new HttpOperationResponse<int?>(); |
| 6 | 4434 | | _result.Request = _httpRequest; |
| 6 | 4435 | | _result.Response = _httpResponse; |
| | 4436 | | // Deserialize Response |
| 6 | 4437 | | if ((int)_statusCode == 200) |
| | 4438 | | { |
| 6 | 4439 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 4440 | | try |
| | 4441 | | { |
| 6 | 4442 | | _result.Body = SafeJsonConvert.DeserializeObject<int?>(_responseContent, DeserializationSettings); |
| 6 | 4443 | | } |
| 0 | 4444 | | catch (JsonException ex) |
| | 4445 | | { |
| 0 | 4446 | | _httpRequest.Dispose(); |
| 0 | 4447 | | if (_httpResponse != null) |
| | 4448 | | { |
| 0 | 4449 | | _httpResponse.Dispose(); |
| | 4450 | | } |
| 0 | 4451 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 4452 | | } |
| | 4453 | | } |
| 6 | 4454 | | if (_shouldTrace) |
| | 4455 | | { |
| 0 | 4456 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 4457 | | } |
| 6 | 4458 | | return _result; |
| 6 | 4459 | | } |
| | 4460 | |
|
| | 4461 | | /// <summary> |
| | 4462 | | /// Associate a set of images with a set of tags. |
| | 4463 | | /// </summary> |
| | 4464 | | /// <param name='projectId'> |
| | 4465 | | /// The project id. |
| | 4466 | | /// </param> |
| | 4467 | | /// <param name='batch'> |
| | 4468 | | /// Batch of image tags. Limited to 128 tags per batch. |
| | 4469 | | /// </param> |
| | 4470 | | /// <param name='customHeaders'> |
| | 4471 | | /// Headers that will be added to request. |
| | 4472 | | /// </param> |
| | 4473 | | /// <param name='cancellationToken'> |
| | 4474 | | /// The cancellation token. |
| | 4475 | | /// </param> |
| | 4476 | | /// <exception cref="CustomVisionErrorException"> |
| | 4477 | | /// Thrown when the operation returned an invalid status code |
| | 4478 | | /// </exception> |
| | 4479 | | /// <exception cref="SerializationException"> |
| | 4480 | | /// Thrown when unable to deserialize the response |
| | 4481 | | /// </exception> |
| | 4482 | | /// <exception cref="ValidationException"> |
| | 4483 | | /// Thrown when a required parameter is null |
| | 4484 | | /// </exception> |
| | 4485 | | /// <exception cref="System.ArgumentNullException"> |
| | 4486 | | /// Thrown when a required parameter is null |
| | 4487 | | /// </exception> |
| | 4488 | | /// <return> |
| | 4489 | | /// A response object containing the response body and response headers. |
| | 4490 | | /// </return> |
| | 4491 | | public async Task<HttpOperationResponse<ImageTagCreateSummary>> CreateImageTagsWithHttpMessagesAsync(System.Guid |
| | 4492 | | { |
| 2 | 4493 | | if (Endpoint == null) |
| | 4494 | | { |
| 0 | 4495 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 4496 | | } |
| 2 | 4497 | | if (batch == null) |
| | 4498 | | { |
| 0 | 4499 | | throw new ValidationException(ValidationRules.CannotBeNull, "batch"); |
| | 4500 | | } |
| | 4501 | | // Tracing |
| 2 | 4502 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 4503 | | string _invocationId = null; |
| 2 | 4504 | | if (_shouldTrace) |
| | 4505 | | { |
| 0 | 4506 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 4507 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 4508 | | tracingParameters.Add("projectId", projectId); |
| 0 | 4509 | | tracingParameters.Add("batch", batch); |
| 0 | 4510 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 4511 | | ServiceClientTracing.Enter(_invocationId, this, "CreateImageTags", tracingParameters); |
| | 4512 | | } |
| | 4513 | | // Construct URL |
| 2 | 4514 | | var _baseUrl = BaseUri; |
| 2 | 4515 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/tags"; |
| 2 | 4516 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 4517 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| | 4518 | | // Create HTTP transport objects |
| 2 | 4519 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 4520 | | HttpResponseMessage _httpResponse = null; |
| 2 | 4521 | | _httpRequest.Method = new HttpMethod("POST"); |
| 2 | 4522 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 4523 | | // Set Headers |
| | 4524 | |
|
| | 4525 | |
|
| 2 | 4526 | | if (customHeaders != null) |
| | 4527 | | { |
| 0 | 4528 | | foreach(var _header in customHeaders) |
| | 4529 | | { |
| 0 | 4530 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 4531 | | { |
| 0 | 4532 | | _httpRequest.Headers.Remove(_header.Key); |
| | 4533 | | } |
| 0 | 4534 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 4535 | | } |
| | 4536 | | } |
| | 4537 | |
|
| | 4538 | | // Serialize Request |
| 2 | 4539 | | string _requestContent = null; |
| 2 | 4540 | | if(batch != null) |
| | 4541 | | { |
| 2 | 4542 | | _requestContent = SafeJsonConvert.SerializeObject(batch, SerializationSettings); |
| 2 | 4543 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 2 | 4544 | | _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); |
| | 4545 | | } |
| | 4546 | | // Set Credentials |
| 2 | 4547 | | if (Credentials != null) |
| | 4548 | | { |
| 2 | 4549 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 4550 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 4551 | | } |
| | 4552 | | // Send Request |
| 2 | 4553 | | if (_shouldTrace) |
| | 4554 | | { |
| 0 | 4555 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 4556 | | } |
| 2 | 4557 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 4558 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 4559 | | if (_shouldTrace) |
| | 4560 | | { |
| 0 | 4561 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 4562 | | } |
| 2 | 4563 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 4564 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 4565 | | string _responseContent = null; |
| 2 | 4566 | | if ((int)_statusCode != 200) |
| | 4567 | | { |
| 0 | 4568 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 4569 | | try |
| | 4570 | | { |
| 0 | 4571 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 4572 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 4573 | | if (_errorBody != null) |
| | 4574 | | { |
| 0 | 4575 | | ex.Body = _errorBody; |
| | 4576 | | } |
| 0 | 4577 | | } |
| 0 | 4578 | | catch (JsonException) |
| | 4579 | | { |
| | 4580 | | // Ignore the exception |
| 0 | 4581 | | } |
| 0 | 4582 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 4583 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 4584 | | if (_shouldTrace) |
| | 4585 | | { |
| 0 | 4586 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 4587 | | } |
| 0 | 4588 | | _httpRequest.Dispose(); |
| 0 | 4589 | | if (_httpResponse != null) |
| | 4590 | | { |
| 0 | 4591 | | _httpResponse.Dispose(); |
| | 4592 | | } |
| 0 | 4593 | | throw ex; |
| | 4594 | | } |
| | 4595 | | // Create Result |
| 2 | 4596 | | var _result = new HttpOperationResponse<ImageTagCreateSummary>(); |
| 2 | 4597 | | _result.Request = _httpRequest; |
| 2 | 4598 | | _result.Response = _httpResponse; |
| | 4599 | | // Deserialize Response |
| 2 | 4600 | | if ((int)_statusCode == 200) |
| | 4601 | | { |
| 2 | 4602 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 4603 | | try |
| | 4604 | | { |
| 2 | 4605 | | _result.Body = SafeJsonConvert.DeserializeObject<ImageTagCreateSummary>(_responseContent, Deserializ |
| 2 | 4606 | | } |
| 0 | 4607 | | catch (JsonException ex) |
| | 4608 | | { |
| 0 | 4609 | | _httpRequest.Dispose(); |
| 0 | 4610 | | if (_httpResponse != null) |
| | 4611 | | { |
| 0 | 4612 | | _httpResponse.Dispose(); |
| | 4613 | | } |
| 0 | 4614 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 4615 | | } |
| | 4616 | | } |
| 2 | 4617 | | if (_shouldTrace) |
| | 4618 | | { |
| 0 | 4619 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 4620 | | } |
| 2 | 4621 | | return _result; |
| 2 | 4622 | | } |
| | 4623 | |
|
| | 4624 | | /// <summary> |
| | 4625 | | /// Remove a set of tags from a set of images. |
| | 4626 | | /// </summary> |
| | 4627 | | /// <param name='projectId'> |
| | 4628 | | /// The project id. |
| | 4629 | | /// </param> |
| | 4630 | | /// <param name='imageIds'> |
| | 4631 | | /// Image ids. Limited to 64 images. |
| | 4632 | | /// </param> |
| | 4633 | | /// <param name='tagIds'> |
| | 4634 | | /// Tags to be deleted from the specified images. Limited to 20 tags. |
| | 4635 | | /// </param> |
| | 4636 | | /// <param name='customHeaders'> |
| | 4637 | | /// Headers that will be added to request. |
| | 4638 | | /// </param> |
| | 4639 | | /// <param name='cancellationToken'> |
| | 4640 | | /// The cancellation token. |
| | 4641 | | /// </param> |
| | 4642 | | /// <exception cref="CustomVisionErrorException"> |
| | 4643 | | /// Thrown when the operation returned an invalid status code |
| | 4644 | | /// </exception> |
| | 4645 | | /// <exception cref="ValidationException"> |
| | 4646 | | /// Thrown when a required parameter is null |
| | 4647 | | /// </exception> |
| | 4648 | | /// <exception cref="System.ArgumentNullException"> |
| | 4649 | | /// Thrown when a required parameter is null |
| | 4650 | | /// </exception> |
| | 4651 | | /// <return> |
| | 4652 | | /// A response object containing the response body and response headers. |
| | 4653 | | /// </return> |
| | 4654 | | public async Task<HttpOperationResponse> DeleteImageTagsWithHttpMessagesAsync(System.Guid projectId, IList<Syste |
| | 4655 | | { |
| 2 | 4656 | | if (Endpoint == null) |
| | 4657 | | { |
| 0 | 4658 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 4659 | | } |
| 2 | 4660 | | if (imageIds == null) |
| | 4661 | | { |
| 0 | 4662 | | throw new ValidationException(ValidationRules.CannotBeNull, "imageIds"); |
| | 4663 | | } |
| 2 | 4664 | | if (imageIds != null) |
| | 4665 | | { |
| 2 | 4666 | | if (imageIds.Count > 64) |
| | 4667 | | { |
| 0 | 4668 | | throw new ValidationException(ValidationRules.MaxItems, "imageIds", 64); |
| | 4669 | | } |
| 2 | 4670 | | if (imageIds.Count < 0) |
| | 4671 | | { |
| 0 | 4672 | | throw new ValidationException(ValidationRules.MinItems, "imageIds", 0); |
| | 4673 | | } |
| | 4674 | | } |
| 2 | 4675 | | if (tagIds == null) |
| | 4676 | | { |
| 0 | 4677 | | throw new ValidationException(ValidationRules.CannotBeNull, "tagIds"); |
| | 4678 | | } |
| 2 | 4679 | | if (tagIds != null) |
| | 4680 | | { |
| 2 | 4681 | | if (tagIds.Count > 20) |
| | 4682 | | { |
| 0 | 4683 | | throw new ValidationException(ValidationRules.MaxItems, "tagIds", 20); |
| | 4684 | | } |
| 2 | 4685 | | if (tagIds.Count < 0) |
| | 4686 | | { |
| 0 | 4687 | | throw new ValidationException(ValidationRules.MinItems, "tagIds", 0); |
| | 4688 | | } |
| | 4689 | | } |
| | 4690 | | // Tracing |
| 2 | 4691 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 4692 | | string _invocationId = null; |
| 2 | 4693 | | if (_shouldTrace) |
| | 4694 | | { |
| 0 | 4695 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 4696 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 4697 | | tracingParameters.Add("projectId", projectId); |
| 0 | 4698 | | tracingParameters.Add("imageIds", imageIds); |
| 0 | 4699 | | tracingParameters.Add("tagIds", tagIds); |
| 0 | 4700 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 4701 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteImageTags", tracingParameters); |
| | 4702 | | } |
| | 4703 | | // Construct URL |
| 2 | 4704 | | var _baseUrl = BaseUri; |
| 2 | 4705 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/tags"; |
| 2 | 4706 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 4707 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 4708 | | List<string> _queryParameters = new List<string>(); |
| 2 | 4709 | | if (imageIds != null) |
| | 4710 | | { |
| 2 | 4711 | | _queryParameters.Add(string.Format("imageIds={0}", System.Uri.EscapeDataString(string.Join(",", imageIds |
| | 4712 | | } |
| 2 | 4713 | | if (tagIds != null) |
| | 4714 | | { |
| 2 | 4715 | | _queryParameters.Add(string.Format("tagIds={0}", System.Uri.EscapeDataString(string.Join(",", tagIds)))) |
| | 4716 | | } |
| 2 | 4717 | | if (_queryParameters.Count > 0) |
| | 4718 | | { |
| 2 | 4719 | | _url += "?" + string.Join("&", _queryParameters); |
| | 4720 | | } |
| | 4721 | | // Create HTTP transport objects |
| 2 | 4722 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 4723 | | HttpResponseMessage _httpResponse = null; |
| 2 | 4724 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 2 | 4725 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 4726 | | // Set Headers |
| | 4727 | |
|
| | 4728 | |
|
| 2 | 4729 | | if (customHeaders != null) |
| | 4730 | | { |
| 0 | 4731 | | foreach(var _header in customHeaders) |
| | 4732 | | { |
| 0 | 4733 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 4734 | | { |
| 0 | 4735 | | _httpRequest.Headers.Remove(_header.Key); |
| | 4736 | | } |
| 0 | 4737 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 4738 | | } |
| | 4739 | | } |
| | 4740 | |
|
| | 4741 | | // Serialize Request |
| 2 | 4742 | | string _requestContent = null; |
| | 4743 | | // Set Credentials |
| 2 | 4744 | | if (Credentials != null) |
| | 4745 | | { |
| 2 | 4746 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 4747 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 4748 | | } |
| | 4749 | | // Send Request |
| 2 | 4750 | | if (_shouldTrace) |
| | 4751 | | { |
| 0 | 4752 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 4753 | | } |
| 2 | 4754 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 4755 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 4756 | | if (_shouldTrace) |
| | 4757 | | { |
| 0 | 4758 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 4759 | | } |
| 2 | 4760 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 4761 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 4762 | | string _responseContent = null; |
| 2 | 4763 | | if ((int)_statusCode != 204) |
| | 4764 | | { |
| 0 | 4765 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 4766 | | try |
| | 4767 | | { |
| 0 | 4768 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 4769 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 4770 | | if (_errorBody != null) |
| | 4771 | | { |
| 0 | 4772 | | ex.Body = _errorBody; |
| | 4773 | | } |
| 0 | 4774 | | } |
| 0 | 4775 | | catch (JsonException) |
| | 4776 | | { |
| | 4777 | | // Ignore the exception |
| 0 | 4778 | | } |
| 0 | 4779 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 4780 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 4781 | | if (_shouldTrace) |
| | 4782 | | { |
| 0 | 4783 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 4784 | | } |
| 0 | 4785 | | _httpRequest.Dispose(); |
| 0 | 4786 | | if (_httpResponse != null) |
| | 4787 | | { |
| 0 | 4788 | | _httpResponse.Dispose(); |
| | 4789 | | } |
| 0 | 4790 | | throw ex; |
| | 4791 | | } |
| | 4792 | | // Create Result |
| 2 | 4793 | | var _result = new HttpOperationResponse(); |
| 2 | 4794 | | _result.Request = _httpRequest; |
| 2 | 4795 | | _result.Response = _httpResponse; |
| 2 | 4796 | | if (_shouldTrace) |
| | 4797 | | { |
| 0 | 4798 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 4799 | | } |
| 2 | 4800 | | return _result; |
| 2 | 4801 | | } |
| | 4802 | |
|
| | 4803 | | /// <summary> |
| | 4804 | | /// Get untagged images for a given project iteration. |
| | 4805 | | /// </summary> |
| | 4806 | | /// <remarks> |
| | 4807 | | /// This API supports batching and range selection. By default it will only |
| | 4808 | | /// return first 50 images matching images. |
| | 4809 | | /// Use the {take} and {skip} parameters to control how many images to return |
| | 4810 | | /// in a given batch. |
| | 4811 | | /// </remarks> |
| | 4812 | | /// <param name='projectId'> |
| | 4813 | | /// The project id. |
| | 4814 | | /// </param> |
| | 4815 | | /// <param name='iterationId'> |
| | 4816 | | /// The iteration id. Defaults to workspace. |
| | 4817 | | /// </param> |
| | 4818 | | /// <param name='orderBy'> |
| | 4819 | | /// The ordering. Defaults to newest. Possible values include: 'Newest', |
| | 4820 | | /// 'Oldest' |
| | 4821 | | /// </param> |
| | 4822 | | /// <param name='take'> |
| | 4823 | | /// Maximum number of images to return. Defaults to 50, limited to 256. |
| | 4824 | | /// </param> |
| | 4825 | | /// <param name='skip'> |
| | 4826 | | /// Number of images to skip before beginning the image batch. Defaults to 0. |
| | 4827 | | /// </param> |
| | 4828 | | /// <param name='customHeaders'> |
| | 4829 | | /// Headers that will be added to request. |
| | 4830 | | /// </param> |
| | 4831 | | /// <param name='cancellationToken'> |
| | 4832 | | /// The cancellation token. |
| | 4833 | | /// </param> |
| | 4834 | | /// <exception cref="CustomVisionErrorException"> |
| | 4835 | | /// Thrown when the operation returned an invalid status code |
| | 4836 | | /// </exception> |
| | 4837 | | /// <exception cref="SerializationException"> |
| | 4838 | | /// Thrown when unable to deserialize the response |
| | 4839 | | /// </exception> |
| | 4840 | | /// <exception cref="ValidationException"> |
| | 4841 | | /// Thrown when a required parameter is null |
| | 4842 | | /// </exception> |
| | 4843 | | /// <exception cref="System.ArgumentNullException"> |
| | 4844 | | /// Thrown when a required parameter is null |
| | 4845 | | /// </exception> |
| | 4846 | | /// <return> |
| | 4847 | | /// A response object containing the response body and response headers. |
| | 4848 | | /// </return> |
| | 4849 | | public async Task<HttpOperationResponse<IList<Image>>> GetUntaggedImagesWithHttpMessagesAsync(System.Guid projec |
| | 4850 | | { |
| 6 | 4851 | | if (Endpoint == null) |
| | 4852 | | { |
| 0 | 4853 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 4854 | | } |
| 6 | 4855 | | if (take > 256) |
| | 4856 | | { |
| 0 | 4857 | | throw new ValidationException(ValidationRules.InclusiveMaximum, "take", 256); |
| | 4858 | | } |
| 6 | 4859 | | if (take < 0) |
| | 4860 | | { |
| 0 | 4861 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "take", 0); |
| | 4862 | | } |
| | 4863 | | // Tracing |
| 6 | 4864 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 6 | 4865 | | string _invocationId = null; |
| 6 | 4866 | | if (_shouldTrace) |
| | 4867 | | { |
| 0 | 4868 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 4869 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 4870 | | tracingParameters.Add("projectId", projectId); |
| 0 | 4871 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 4872 | | tracingParameters.Add("orderBy", orderBy); |
| 0 | 4873 | | tracingParameters.Add("take", take); |
| 0 | 4874 | | tracingParameters.Add("skip", skip); |
| 0 | 4875 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 4876 | | ServiceClientTracing.Enter(_invocationId, this, "GetUntaggedImages", tracingParameters); |
| | 4877 | | } |
| | 4878 | | // Construct URL |
| 6 | 4879 | | var _baseUrl = BaseUri; |
| 6 | 4880 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/untagged"; |
| 6 | 4881 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 6 | 4882 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 6 | 4883 | | List<string> _queryParameters = new List<string>(); |
| 6 | 4884 | | if (iterationId != null) |
| | 4885 | | { |
| 0 | 4886 | | _queryParameters.Add(string.Format("iterationId={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serial |
| | 4887 | | } |
| 6 | 4888 | | if (orderBy != null) |
| | 4889 | | { |
| 0 | 4890 | | _queryParameters.Add(string.Format("orderBy={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 4891 | | } |
| 6 | 4892 | | if (take != null) |
| | 4893 | | { |
| 6 | 4894 | | _queryParameters.Add(string.Format("take={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObje |
| | 4895 | | } |
| 6 | 4896 | | if (skip != null) |
| | 4897 | | { |
| 6 | 4898 | | _queryParameters.Add(string.Format("skip={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObje |
| | 4899 | | } |
| 6 | 4900 | | if (_queryParameters.Count > 0) |
| | 4901 | | { |
| 6 | 4902 | | _url += "?" + string.Join("&", _queryParameters); |
| | 4903 | | } |
| | 4904 | | // Create HTTP transport objects |
| 6 | 4905 | | var _httpRequest = new HttpRequestMessage(); |
| 6 | 4906 | | HttpResponseMessage _httpResponse = null; |
| 6 | 4907 | | _httpRequest.Method = new HttpMethod("GET"); |
| 6 | 4908 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 4909 | | // Set Headers |
| | 4910 | |
|
| | 4911 | |
|
| 6 | 4912 | | if (customHeaders != null) |
| | 4913 | | { |
| 0 | 4914 | | foreach(var _header in customHeaders) |
| | 4915 | | { |
| 0 | 4916 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 4917 | | { |
| 0 | 4918 | | _httpRequest.Headers.Remove(_header.Key); |
| | 4919 | | } |
| 0 | 4920 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 4921 | | } |
| | 4922 | | } |
| | 4923 | |
|
| | 4924 | | // Serialize Request |
| 6 | 4925 | | string _requestContent = null; |
| | 4926 | | // Set Credentials |
| 6 | 4927 | | if (Credentials != null) |
| | 4928 | | { |
| 6 | 4929 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 4930 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 4931 | | } |
| | 4932 | | // Send Request |
| 6 | 4933 | | if (_shouldTrace) |
| | 4934 | | { |
| 0 | 4935 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 4936 | | } |
| 6 | 4937 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 4938 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 6 | 4939 | | if (_shouldTrace) |
| | 4940 | | { |
| 0 | 4941 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 4942 | | } |
| 6 | 4943 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 6 | 4944 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 4945 | | string _responseContent = null; |
| 6 | 4946 | | if ((int)_statusCode != 200) |
| | 4947 | | { |
| 0 | 4948 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 4949 | | try |
| | 4950 | | { |
| 0 | 4951 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 4952 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 4953 | | if (_errorBody != null) |
| | 4954 | | { |
| 0 | 4955 | | ex.Body = _errorBody; |
| | 4956 | | } |
| 0 | 4957 | | } |
| 0 | 4958 | | catch (JsonException) |
| | 4959 | | { |
| | 4960 | | // Ignore the exception |
| 0 | 4961 | | } |
| 0 | 4962 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 4963 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 4964 | | if (_shouldTrace) |
| | 4965 | | { |
| 0 | 4966 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 4967 | | } |
| 0 | 4968 | | _httpRequest.Dispose(); |
| 0 | 4969 | | if (_httpResponse != null) |
| | 4970 | | { |
| 0 | 4971 | | _httpResponse.Dispose(); |
| | 4972 | | } |
| 0 | 4973 | | throw ex; |
| | 4974 | | } |
| | 4975 | | // Create Result |
| 6 | 4976 | | var _result = new HttpOperationResponse<IList<Image>>(); |
| 6 | 4977 | | _result.Request = _httpRequest; |
| 6 | 4978 | | _result.Response = _httpResponse; |
| | 4979 | | // Deserialize Response |
| 6 | 4980 | | if ((int)_statusCode == 200) |
| | 4981 | | { |
| 6 | 4982 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 4983 | | try |
| | 4984 | | { |
| 6 | 4985 | | _result.Body = SafeJsonConvert.DeserializeObject<IList<Image>>(_responseContent, DeserializationSett |
| 6 | 4986 | | } |
| 0 | 4987 | | catch (JsonException ex) |
| | 4988 | | { |
| 0 | 4989 | | _httpRequest.Dispose(); |
| 0 | 4990 | | if (_httpResponse != null) |
| | 4991 | | { |
| 0 | 4992 | | _httpResponse.Dispose(); |
| | 4993 | | } |
| 0 | 4994 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 4995 | | } |
| | 4996 | | } |
| 6 | 4997 | | if (_shouldTrace) |
| | 4998 | | { |
| 0 | 4999 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 5000 | | } |
| 6 | 5001 | | return _result; |
| 6 | 5002 | | } |
| | 5003 | |
|
| | 5004 | | /// <summary> |
| | 5005 | | /// Gets the number of untagged images. |
| | 5006 | | /// </summary> |
| | 5007 | | /// <remarks> |
| | 5008 | | /// This API returns the images which have no tags for a given project and |
| | 5009 | | /// optionally an iteration. If no iteration is specified the |
| | 5010 | | /// current workspace is used. |
| | 5011 | | /// </remarks> |
| | 5012 | | /// <param name='projectId'> |
| | 5013 | | /// The project id. |
| | 5014 | | /// </param> |
| | 5015 | | /// <param name='iterationId'> |
| | 5016 | | /// The iteration id. Defaults to workspace. |
| | 5017 | | /// </param> |
| | 5018 | | /// <param name='customHeaders'> |
| | 5019 | | /// Headers that will be added to request. |
| | 5020 | | /// </param> |
| | 5021 | | /// <param name='cancellationToken'> |
| | 5022 | | /// The cancellation token. |
| | 5023 | | /// </param> |
| | 5024 | | /// <exception cref="CustomVisionErrorException"> |
| | 5025 | | /// Thrown when the operation returned an invalid status code |
| | 5026 | | /// </exception> |
| | 5027 | | /// <exception cref="SerializationException"> |
| | 5028 | | /// Thrown when unable to deserialize the response |
| | 5029 | | /// </exception> |
| | 5030 | | /// <exception cref="ValidationException"> |
| | 5031 | | /// Thrown when a required parameter is null |
| | 5032 | | /// </exception> |
| | 5033 | | /// <exception cref="System.ArgumentNullException"> |
| | 5034 | | /// Thrown when a required parameter is null |
| | 5035 | | /// </exception> |
| | 5036 | | /// <return> |
| | 5037 | | /// A response object containing the response body and response headers. |
| | 5038 | | /// </return> |
| | 5039 | | public async Task<HttpOperationResponse<int?>> GetUntaggedImageCountWithHttpMessagesAsync(System.Guid projectId, |
| | 5040 | | { |
| 2 | 5041 | | if (Endpoint == null) |
| | 5042 | | { |
| 0 | 5043 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 5044 | | } |
| | 5045 | | // Tracing |
| 2 | 5046 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 5047 | | string _invocationId = null; |
| 2 | 5048 | | if (_shouldTrace) |
| | 5049 | | { |
| 0 | 5050 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 5051 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 5052 | | tracingParameters.Add("projectId", projectId); |
| 0 | 5053 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 5054 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 5055 | | ServiceClientTracing.Enter(_invocationId, this, "GetUntaggedImageCount", tracingParameters); |
| | 5056 | | } |
| | 5057 | | // Construct URL |
| 2 | 5058 | | var _baseUrl = BaseUri; |
| 2 | 5059 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/untagged/count"; |
| 2 | 5060 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 5061 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 5062 | | List<string> _queryParameters = new List<string>(); |
| 2 | 5063 | | if (iterationId != null) |
| | 5064 | | { |
| 0 | 5065 | | _queryParameters.Add(string.Format("iterationId={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serial |
| | 5066 | | } |
| 2 | 5067 | | if (_queryParameters.Count > 0) |
| | 5068 | | { |
| 0 | 5069 | | _url += "?" + string.Join("&", _queryParameters); |
| | 5070 | | } |
| | 5071 | | // Create HTTP transport objects |
| 2 | 5072 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 5073 | | HttpResponseMessage _httpResponse = null; |
| 2 | 5074 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 5075 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 5076 | | // Set Headers |
| | 5077 | |
|
| | 5078 | |
|
| 2 | 5079 | | if (customHeaders != null) |
| | 5080 | | { |
| 0 | 5081 | | foreach(var _header in customHeaders) |
| | 5082 | | { |
| 0 | 5083 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 5084 | | { |
| 0 | 5085 | | _httpRequest.Headers.Remove(_header.Key); |
| | 5086 | | } |
| 0 | 5087 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 5088 | | } |
| | 5089 | | } |
| | 5090 | |
|
| | 5091 | | // Serialize Request |
| 2 | 5092 | | string _requestContent = null; |
| | 5093 | | // Set Credentials |
| 2 | 5094 | | if (Credentials != null) |
| | 5095 | | { |
| 2 | 5096 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 5097 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 5098 | | } |
| | 5099 | | // Send Request |
| 2 | 5100 | | if (_shouldTrace) |
| | 5101 | | { |
| 0 | 5102 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 5103 | | } |
| 2 | 5104 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 5105 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 5106 | | if (_shouldTrace) |
| | 5107 | | { |
| 0 | 5108 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 5109 | | } |
| 2 | 5110 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 5111 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 5112 | | string _responseContent = null; |
| 2 | 5113 | | if ((int)_statusCode != 200) |
| | 5114 | | { |
| 0 | 5115 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 5116 | | try |
| | 5117 | | { |
| 0 | 5118 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 5119 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 5120 | | if (_errorBody != null) |
| | 5121 | | { |
| 0 | 5122 | | ex.Body = _errorBody; |
| | 5123 | | } |
| 0 | 5124 | | } |
| 0 | 5125 | | catch (JsonException) |
| | 5126 | | { |
| | 5127 | | // Ignore the exception |
| 0 | 5128 | | } |
| 0 | 5129 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 5130 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 5131 | | if (_shouldTrace) |
| | 5132 | | { |
| 0 | 5133 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 5134 | | } |
| 0 | 5135 | | _httpRequest.Dispose(); |
| 0 | 5136 | | if (_httpResponse != null) |
| | 5137 | | { |
| 0 | 5138 | | _httpResponse.Dispose(); |
| | 5139 | | } |
| 0 | 5140 | | throw ex; |
| | 5141 | | } |
| | 5142 | | // Create Result |
| 2 | 5143 | | var _result = new HttpOperationResponse<int?>(); |
| 2 | 5144 | | _result.Request = _httpRequest; |
| 2 | 5145 | | _result.Response = _httpResponse; |
| | 5146 | | // Deserialize Response |
| 2 | 5147 | | if ((int)_statusCode == 200) |
| | 5148 | | { |
| 2 | 5149 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 5150 | | try |
| | 5151 | | { |
| 2 | 5152 | | _result.Body = SafeJsonConvert.DeserializeObject<int?>(_responseContent, DeserializationSettings); |
| 2 | 5153 | | } |
| 0 | 5154 | | catch (JsonException ex) |
| | 5155 | | { |
| 0 | 5156 | | _httpRequest.Dispose(); |
| 0 | 5157 | | if (_httpResponse != null) |
| | 5158 | | { |
| 0 | 5159 | | _httpResponse.Dispose(); |
| | 5160 | | } |
| 0 | 5161 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 5162 | | } |
| | 5163 | | } |
| 2 | 5164 | | if (_shouldTrace) |
| | 5165 | | { |
| 0 | 5166 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 5167 | | } |
| 2 | 5168 | | return _result; |
| 2 | 5169 | | } |
| | 5170 | |
|
| | 5171 | | /// <summary> |
| | 5172 | | /// Add the provided images urls to the set of training images. |
| | 5173 | | /// </summary> |
| | 5174 | | /// <remarks> |
| | 5175 | | /// This API accepts a batch of urls, and optionally tags, to create images. |
| | 5176 | | /// There is a limit of 64 images and 20 tags. |
| | 5177 | | /// If all images are successful created, 200(OK) status code will be returned. |
| | 5178 | | /// Otherwise, 207 (Multi-Status) status code will be returned and detail |
| | 5179 | | /// status for each image will be listed in the response payload. |
| | 5180 | | /// </remarks> |
| | 5181 | | /// <param name='projectId'> |
| | 5182 | | /// The project id. |
| | 5183 | | /// </param> |
| | 5184 | | /// <param name='batch'> |
| | 5185 | | /// Image urls, tag ids, and metadata. Limited to 64 images and 20 tags per |
| | 5186 | | /// batch. |
| | 5187 | | /// </param> |
| | 5188 | | /// <param name='customHeaders'> |
| | 5189 | | /// Headers that will be added to request. |
| | 5190 | | /// </param> |
| | 5191 | | /// <param name='cancellationToken'> |
| | 5192 | | /// The cancellation token. |
| | 5193 | | /// </param> |
| | 5194 | | /// <exception cref="CustomVisionErrorException"> |
| | 5195 | | /// Thrown when the operation returned an invalid status code |
| | 5196 | | /// </exception> |
| | 5197 | | /// <exception cref="SerializationException"> |
| | 5198 | | /// Thrown when unable to deserialize the response |
| | 5199 | | /// </exception> |
| | 5200 | | /// <exception cref="ValidationException"> |
| | 5201 | | /// Thrown when a required parameter is null |
| | 5202 | | /// </exception> |
| | 5203 | | /// <exception cref="System.ArgumentNullException"> |
| | 5204 | | /// Thrown when a required parameter is null |
| | 5205 | | /// </exception> |
| | 5206 | | /// <return> |
| | 5207 | | /// A response object containing the response body and response headers. |
| | 5208 | | /// </return> |
| | 5209 | | public async Task<HttpOperationResponse<ImageCreateSummary>> CreateImagesFromUrlsWithHttpMessagesAsync(System.Gu |
| | 5210 | | { |
| 4 | 5211 | | if (Endpoint == null) |
| | 5212 | | { |
| 0 | 5213 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 5214 | | } |
| 4 | 5215 | | if (batch == null) |
| | 5216 | | { |
| 0 | 5217 | | throw new ValidationException(ValidationRules.CannotBeNull, "batch"); |
| | 5218 | | } |
| | 5219 | | // Tracing |
| 4 | 5220 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 5221 | | string _invocationId = null; |
| 4 | 5222 | | if (_shouldTrace) |
| | 5223 | | { |
| 0 | 5224 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 5225 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 5226 | | tracingParameters.Add("projectId", projectId); |
| 0 | 5227 | | tracingParameters.Add("batch", batch); |
| 0 | 5228 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 5229 | | ServiceClientTracing.Enter(_invocationId, this, "CreateImagesFromUrls", tracingParameters); |
| | 5230 | | } |
| | 5231 | | // Construct URL |
| 4 | 5232 | | var _baseUrl = BaseUri; |
| 4 | 5233 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/images/urls"; |
| 4 | 5234 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 4 | 5235 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| | 5236 | | // Create HTTP transport objects |
| 4 | 5237 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 5238 | | HttpResponseMessage _httpResponse = null; |
| 4 | 5239 | | _httpRequest.Method = new HttpMethod("POST"); |
| 4 | 5240 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 5241 | | // Set Headers |
| | 5242 | |
|
| | 5243 | |
|
| 4 | 5244 | | if (customHeaders != null) |
| | 5245 | | { |
| 0 | 5246 | | foreach(var _header in customHeaders) |
| | 5247 | | { |
| 0 | 5248 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 5249 | | { |
| 0 | 5250 | | _httpRequest.Headers.Remove(_header.Key); |
| | 5251 | | } |
| 0 | 5252 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 5253 | | } |
| | 5254 | | } |
| | 5255 | |
|
| | 5256 | | // Serialize Request |
| 4 | 5257 | | string _requestContent = null; |
| 4 | 5258 | | if(batch != null) |
| | 5259 | | { |
| 4 | 5260 | | _requestContent = SafeJsonConvert.SerializeObject(batch, SerializationSettings); |
| 4 | 5261 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 4 | 5262 | | _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); |
| | 5263 | | } |
| | 5264 | | // Set Credentials |
| 4 | 5265 | | if (Credentials != null) |
| | 5266 | | { |
| 4 | 5267 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 5268 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 5269 | | } |
| | 5270 | | // Send Request |
| 4 | 5271 | | if (_shouldTrace) |
| | 5272 | | { |
| 0 | 5273 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 5274 | | } |
| 4 | 5275 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 5276 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 5277 | | if (_shouldTrace) |
| | 5278 | | { |
| 0 | 5279 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 5280 | | } |
| 4 | 5281 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 5282 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 5283 | | string _responseContent = null; |
| 4 | 5284 | | if ((int)_statusCode != 200 && (int)_statusCode != 207) |
| | 5285 | | { |
| 0 | 5286 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 5287 | | try |
| | 5288 | | { |
| 0 | 5289 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 5290 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 5291 | | if (_errorBody != null) |
| | 5292 | | { |
| 0 | 5293 | | ex.Body = _errorBody; |
| | 5294 | | } |
| 0 | 5295 | | } |
| 0 | 5296 | | catch (JsonException) |
| | 5297 | | { |
| | 5298 | | // Ignore the exception |
| 0 | 5299 | | } |
| 0 | 5300 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 5301 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 5302 | | if (_shouldTrace) |
| | 5303 | | { |
| 0 | 5304 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 5305 | | } |
| 0 | 5306 | | _httpRequest.Dispose(); |
| 0 | 5307 | | if (_httpResponse != null) |
| | 5308 | | { |
| 0 | 5309 | | _httpResponse.Dispose(); |
| | 5310 | | } |
| 0 | 5311 | | throw ex; |
| | 5312 | | } |
| | 5313 | | // Create Result |
| 4 | 5314 | | var _result = new HttpOperationResponse<ImageCreateSummary>(); |
| 4 | 5315 | | _result.Request = _httpRequest; |
| 4 | 5316 | | _result.Response = _httpResponse; |
| | 5317 | | // Deserialize Response |
| 4 | 5318 | | if ((int)_statusCode == 200) |
| | 5319 | | { |
| 4 | 5320 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 5321 | | try |
| | 5322 | | { |
| 4 | 5323 | | _result.Body = SafeJsonConvert.DeserializeObject<ImageCreateSummary>(_responseContent, Deserializati |
| 4 | 5324 | | } |
| 0 | 5325 | | catch (JsonException ex) |
| | 5326 | | { |
| 0 | 5327 | | _httpRequest.Dispose(); |
| 0 | 5328 | | if (_httpResponse != null) |
| | 5329 | | { |
| 0 | 5330 | | _httpResponse.Dispose(); |
| | 5331 | | } |
| 0 | 5332 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 5333 | | } |
| | 5334 | | } |
| | 5335 | | // Deserialize Response |
| 4 | 5336 | | if ((int)_statusCode == 207) |
| | 5337 | | { |
| 0 | 5338 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 5339 | | try |
| | 5340 | | { |
| 0 | 5341 | | _result.Body = SafeJsonConvert.DeserializeObject<ImageCreateSummary>(_responseContent, Deserializati |
| 0 | 5342 | | } |
| 0 | 5343 | | catch (JsonException ex) |
| | 5344 | | { |
| 0 | 5345 | | _httpRequest.Dispose(); |
| 0 | 5346 | | if (_httpResponse != null) |
| | 5347 | | { |
| 0 | 5348 | | _httpResponse.Dispose(); |
| | 5349 | | } |
| 0 | 5350 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 5351 | | } |
| | 5352 | | } |
| 4 | 5353 | | if (_shouldTrace) |
| | 5354 | | { |
| 0 | 5355 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 5356 | | } |
| 4 | 5357 | | return _result; |
| 4 | 5358 | | } |
| | 5359 | |
|
| | 5360 | | /// <summary> |
| | 5361 | | /// Get iterations for the project. |
| | 5362 | | /// </summary> |
| | 5363 | | /// <param name='projectId'> |
| | 5364 | | /// The project id. |
| | 5365 | | /// </param> |
| | 5366 | | /// <param name='customHeaders'> |
| | 5367 | | /// Headers that will be added to request. |
| | 5368 | | /// </param> |
| | 5369 | | /// <param name='cancellationToken'> |
| | 5370 | | /// The cancellation token. |
| | 5371 | | /// </param> |
| | 5372 | | /// <exception cref="CustomVisionErrorException"> |
| | 5373 | | /// Thrown when the operation returned an invalid status code |
| | 5374 | | /// </exception> |
| | 5375 | | /// <exception cref="SerializationException"> |
| | 5376 | | /// Thrown when unable to deserialize the response |
| | 5377 | | /// </exception> |
| | 5378 | | /// <exception cref="ValidationException"> |
| | 5379 | | /// Thrown when a required parameter is null |
| | 5380 | | /// </exception> |
| | 5381 | | /// <exception cref="System.ArgumentNullException"> |
| | 5382 | | /// Thrown when a required parameter is null |
| | 5383 | | /// </exception> |
| | 5384 | | /// <return> |
| | 5385 | | /// A response object containing the response body and response headers. |
| | 5386 | | /// </return> |
| | 5387 | | public async Task<HttpOperationResponse<IList<Iteration>>> GetIterationsWithHttpMessagesAsync(System.Guid projec |
| | 5388 | | { |
| 12 | 5389 | | if (Endpoint == null) |
| | 5390 | | { |
| 0 | 5391 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 5392 | | } |
| | 5393 | | // Tracing |
| 12 | 5394 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 12 | 5395 | | string _invocationId = null; |
| 12 | 5396 | | if (_shouldTrace) |
| | 5397 | | { |
| 0 | 5398 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 5399 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 5400 | | tracingParameters.Add("projectId", projectId); |
| 0 | 5401 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 5402 | | ServiceClientTracing.Enter(_invocationId, this, "GetIterations", tracingParameters); |
| | 5403 | | } |
| | 5404 | | // Construct URL |
| 12 | 5405 | | var _baseUrl = BaseUri; |
| 12 | 5406 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/iterations"; |
| 12 | 5407 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 12 | 5408 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| | 5409 | | // Create HTTP transport objects |
| 12 | 5410 | | var _httpRequest = new HttpRequestMessage(); |
| 12 | 5411 | | HttpResponseMessage _httpResponse = null; |
| 12 | 5412 | | _httpRequest.Method = new HttpMethod("GET"); |
| 12 | 5413 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 5414 | | // Set Headers |
| | 5415 | |
|
| | 5416 | |
|
| 12 | 5417 | | if (customHeaders != null) |
| | 5418 | | { |
| 0 | 5419 | | foreach(var _header in customHeaders) |
| | 5420 | | { |
| 0 | 5421 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 5422 | | { |
| 0 | 5423 | | _httpRequest.Headers.Remove(_header.Key); |
| | 5424 | | } |
| 0 | 5425 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 5426 | | } |
| | 5427 | | } |
| | 5428 | |
|
| | 5429 | | // Serialize Request |
| 12 | 5430 | | string _requestContent = null; |
| | 5431 | | // Set Credentials |
| 12 | 5432 | | if (Credentials != null) |
| | 5433 | | { |
| 12 | 5434 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 5435 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 5436 | | } |
| | 5437 | | // Send Request |
| 12 | 5438 | | if (_shouldTrace) |
| | 5439 | | { |
| 0 | 5440 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 5441 | | } |
| 12 | 5442 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 5443 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 12 | 5444 | | if (_shouldTrace) |
| | 5445 | | { |
| 0 | 5446 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 5447 | | } |
| 12 | 5448 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 12 | 5449 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 5450 | | string _responseContent = null; |
| 12 | 5451 | | if ((int)_statusCode != 200) |
| | 5452 | | { |
| 0 | 5453 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 5454 | | try |
| | 5455 | | { |
| 0 | 5456 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 5457 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 5458 | | if (_errorBody != null) |
| | 5459 | | { |
| 0 | 5460 | | ex.Body = _errorBody; |
| | 5461 | | } |
| 0 | 5462 | | } |
| 0 | 5463 | | catch (JsonException) |
| | 5464 | | { |
| | 5465 | | // Ignore the exception |
| 0 | 5466 | | } |
| 0 | 5467 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 5468 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 5469 | | if (_shouldTrace) |
| | 5470 | | { |
| 0 | 5471 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 5472 | | } |
| 0 | 5473 | | _httpRequest.Dispose(); |
| 0 | 5474 | | if (_httpResponse != null) |
| | 5475 | | { |
| 0 | 5476 | | _httpResponse.Dispose(); |
| | 5477 | | } |
| 0 | 5478 | | throw ex; |
| | 5479 | | } |
| | 5480 | | // Create Result |
| 12 | 5481 | | var _result = new HttpOperationResponse<IList<Iteration>>(); |
| 12 | 5482 | | _result.Request = _httpRequest; |
| 12 | 5483 | | _result.Response = _httpResponse; |
| | 5484 | | // Deserialize Response |
| 12 | 5485 | | if ((int)_statusCode == 200) |
| | 5486 | | { |
| 12 | 5487 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 5488 | | try |
| | 5489 | | { |
| 12 | 5490 | | _result.Body = SafeJsonConvert.DeserializeObject<IList<Iteration>>(_responseContent, Deserialization |
| 12 | 5491 | | } |
| 0 | 5492 | | catch (JsonException ex) |
| | 5493 | | { |
| 0 | 5494 | | _httpRequest.Dispose(); |
| 0 | 5495 | | if (_httpResponse != null) |
| | 5496 | | { |
| 0 | 5497 | | _httpResponse.Dispose(); |
| | 5498 | | } |
| 0 | 5499 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 5500 | | } |
| | 5501 | | } |
| 12 | 5502 | | if (_shouldTrace) |
| | 5503 | | { |
| 0 | 5504 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 5505 | | } |
| 12 | 5506 | | return _result; |
| 12 | 5507 | | } |
| | 5508 | |
|
| | 5509 | | /// <summary> |
| | 5510 | | /// Get a specific iteration. |
| | 5511 | | /// </summary> |
| | 5512 | | /// <param name='projectId'> |
| | 5513 | | /// The id of the project the iteration belongs to. |
| | 5514 | | /// </param> |
| | 5515 | | /// <param name='iterationId'> |
| | 5516 | | /// The id of the iteration to get. |
| | 5517 | | /// </param> |
| | 5518 | | /// <param name='customHeaders'> |
| | 5519 | | /// Headers that will be added to request. |
| | 5520 | | /// </param> |
| | 5521 | | /// <param name='cancellationToken'> |
| | 5522 | | /// The cancellation token. |
| | 5523 | | /// </param> |
| | 5524 | | /// <exception cref="CustomVisionErrorException"> |
| | 5525 | | /// Thrown when the operation returned an invalid status code |
| | 5526 | | /// </exception> |
| | 5527 | | /// <exception cref="SerializationException"> |
| | 5528 | | /// Thrown when unable to deserialize the response |
| | 5529 | | /// </exception> |
| | 5530 | | /// <exception cref="ValidationException"> |
| | 5531 | | /// Thrown when a required parameter is null |
| | 5532 | | /// </exception> |
| | 5533 | | /// <exception cref="System.ArgumentNullException"> |
| | 5534 | | /// Thrown when a required parameter is null |
| | 5535 | | /// </exception> |
| | 5536 | | /// <return> |
| | 5537 | | /// A response object containing the response body and response headers. |
| | 5538 | | /// </return> |
| | 5539 | | public async Task<HttpOperationResponse<Iteration>> GetIterationWithHttpMessagesAsync(System.Guid projectId, Sys |
| | 5540 | | { |
| 32 | 5541 | | if (Endpoint == null) |
| | 5542 | | { |
| 0 | 5543 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 5544 | | } |
| | 5545 | | // Tracing |
| 32 | 5546 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 32 | 5547 | | string _invocationId = null; |
| 32 | 5548 | | if (_shouldTrace) |
| | 5549 | | { |
| 0 | 5550 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 5551 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 5552 | | tracingParameters.Add("projectId", projectId); |
| 0 | 5553 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 5554 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 5555 | | ServiceClientTracing.Enter(_invocationId, this, "GetIteration", tracingParameters); |
| | 5556 | | } |
| | 5557 | | // Construct URL |
| 32 | 5558 | | var _baseUrl = BaseUri; |
| 32 | 5559 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/iterations/{iterationId}"; |
| 32 | 5560 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 32 | 5561 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 32 | 5562 | | _url = _url.Replace("{iterationId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(iterationId |
| | 5563 | | // Create HTTP transport objects |
| 32 | 5564 | | var _httpRequest = new HttpRequestMessage(); |
| 32 | 5565 | | HttpResponseMessage _httpResponse = null; |
| 32 | 5566 | | _httpRequest.Method = new HttpMethod("GET"); |
| 32 | 5567 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 5568 | | // Set Headers |
| | 5569 | |
|
| | 5570 | |
|
| 32 | 5571 | | if (customHeaders != null) |
| | 5572 | | { |
| 0 | 5573 | | foreach(var _header in customHeaders) |
| | 5574 | | { |
| 0 | 5575 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 5576 | | { |
| 0 | 5577 | | _httpRequest.Headers.Remove(_header.Key); |
| | 5578 | | } |
| 0 | 5579 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 5580 | | } |
| | 5581 | | } |
| | 5582 | |
|
| | 5583 | | // Serialize Request |
| 32 | 5584 | | string _requestContent = null; |
| | 5585 | | // Set Credentials |
| 32 | 5586 | | if (Credentials != null) |
| | 5587 | | { |
| 32 | 5588 | | cancellationToken.ThrowIfCancellationRequested(); |
| 32 | 5589 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 5590 | | } |
| | 5591 | | // Send Request |
| 32 | 5592 | | if (_shouldTrace) |
| | 5593 | | { |
| 0 | 5594 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 5595 | | } |
| 32 | 5596 | | cancellationToken.ThrowIfCancellationRequested(); |
| 32 | 5597 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 32 | 5598 | | if (_shouldTrace) |
| | 5599 | | { |
| 0 | 5600 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 5601 | | } |
| 32 | 5602 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 32 | 5603 | | cancellationToken.ThrowIfCancellationRequested(); |
| 32 | 5604 | | string _responseContent = null; |
| 32 | 5605 | | if ((int)_statusCode != 200) |
| | 5606 | | { |
| 0 | 5607 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 5608 | | try |
| | 5609 | | { |
| 0 | 5610 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 5611 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 5612 | | if (_errorBody != null) |
| | 5613 | | { |
| 0 | 5614 | | ex.Body = _errorBody; |
| | 5615 | | } |
| 0 | 5616 | | } |
| 0 | 5617 | | catch (JsonException) |
| | 5618 | | { |
| | 5619 | | // Ignore the exception |
| 0 | 5620 | | } |
| 0 | 5621 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 5622 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 5623 | | if (_shouldTrace) |
| | 5624 | | { |
| 0 | 5625 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 5626 | | } |
| 0 | 5627 | | _httpRequest.Dispose(); |
| 0 | 5628 | | if (_httpResponse != null) |
| | 5629 | | { |
| 0 | 5630 | | _httpResponse.Dispose(); |
| | 5631 | | } |
| 0 | 5632 | | throw ex; |
| | 5633 | | } |
| | 5634 | | // Create Result |
| 32 | 5635 | | var _result = new HttpOperationResponse<Iteration>(); |
| 32 | 5636 | | _result.Request = _httpRequest; |
| 32 | 5637 | | _result.Response = _httpResponse; |
| | 5638 | | // Deserialize Response |
| 32 | 5639 | | if ((int)_statusCode == 200) |
| | 5640 | | { |
| 32 | 5641 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 5642 | | try |
| | 5643 | | { |
| 32 | 5644 | | _result.Body = SafeJsonConvert.DeserializeObject<Iteration>(_responseContent, DeserializationSetting |
| 32 | 5645 | | } |
| 0 | 5646 | | catch (JsonException ex) |
| | 5647 | | { |
| 0 | 5648 | | _httpRequest.Dispose(); |
| 0 | 5649 | | if (_httpResponse != null) |
| | 5650 | | { |
| 0 | 5651 | | _httpResponse.Dispose(); |
| | 5652 | | } |
| 0 | 5653 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 5654 | | } |
| | 5655 | | } |
| 32 | 5656 | | if (_shouldTrace) |
| | 5657 | | { |
| 0 | 5658 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 5659 | | } |
| 32 | 5660 | | return _result; |
| 32 | 5661 | | } |
| | 5662 | |
|
| | 5663 | | /// <summary> |
| | 5664 | | /// Delete a specific iteration of a project. |
| | 5665 | | /// </summary> |
| | 5666 | | /// <param name='projectId'> |
| | 5667 | | /// The project id. |
| | 5668 | | /// </param> |
| | 5669 | | /// <param name='iterationId'> |
| | 5670 | | /// The iteration id. |
| | 5671 | | /// </param> |
| | 5672 | | /// <param name='customHeaders'> |
| | 5673 | | /// Headers that will be added to request. |
| | 5674 | | /// </param> |
| | 5675 | | /// <param name='cancellationToken'> |
| | 5676 | | /// The cancellation token. |
| | 5677 | | /// </param> |
| | 5678 | | /// <exception cref="CustomVisionErrorException"> |
| | 5679 | | /// Thrown when the operation returned an invalid status code |
| | 5680 | | /// </exception> |
| | 5681 | | /// <exception cref="ValidationException"> |
| | 5682 | | /// Thrown when a required parameter is null |
| | 5683 | | /// </exception> |
| | 5684 | | /// <exception cref="System.ArgumentNullException"> |
| | 5685 | | /// Thrown when a required parameter is null |
| | 5686 | | /// </exception> |
| | 5687 | | /// <return> |
| | 5688 | | /// A response object containing the response body and response headers. |
| | 5689 | | /// </return> |
| | 5690 | | public async Task<HttpOperationResponse> DeleteIterationWithHttpMessagesAsync(System.Guid projectId, System.Guid |
| | 5691 | | { |
| 2 | 5692 | | if (Endpoint == null) |
| | 5693 | | { |
| 0 | 5694 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 5695 | | } |
| | 5696 | | // Tracing |
| 2 | 5697 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 5698 | | string _invocationId = null; |
| 2 | 5699 | | if (_shouldTrace) |
| | 5700 | | { |
| 0 | 5701 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 5702 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 5703 | | tracingParameters.Add("projectId", projectId); |
| 0 | 5704 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 5705 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 5706 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteIteration", tracingParameters); |
| | 5707 | | } |
| | 5708 | | // Construct URL |
| 2 | 5709 | | var _baseUrl = BaseUri; |
| 2 | 5710 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/iterations/{iterationId}"; |
| 2 | 5711 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 5712 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 5713 | | _url = _url.Replace("{iterationId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(iterationId |
| | 5714 | | // Create HTTP transport objects |
| 2 | 5715 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 5716 | | HttpResponseMessage _httpResponse = null; |
| 2 | 5717 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 2 | 5718 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 5719 | | // Set Headers |
| | 5720 | |
|
| | 5721 | |
|
| 2 | 5722 | | if (customHeaders != null) |
| | 5723 | | { |
| 0 | 5724 | | foreach(var _header in customHeaders) |
| | 5725 | | { |
| 0 | 5726 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 5727 | | { |
| 0 | 5728 | | _httpRequest.Headers.Remove(_header.Key); |
| | 5729 | | } |
| 0 | 5730 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 5731 | | } |
| | 5732 | | } |
| | 5733 | |
|
| | 5734 | | // Serialize Request |
| 2 | 5735 | | string _requestContent = null; |
| | 5736 | | // Set Credentials |
| 2 | 5737 | | if (Credentials != null) |
| | 5738 | | { |
| 2 | 5739 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 5740 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 5741 | | } |
| | 5742 | | // Send Request |
| 2 | 5743 | | if (_shouldTrace) |
| | 5744 | | { |
| 0 | 5745 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 5746 | | } |
| 2 | 5747 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 5748 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 5749 | | if (_shouldTrace) |
| | 5750 | | { |
| 0 | 5751 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 5752 | | } |
| 2 | 5753 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 5754 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 5755 | | string _responseContent = null; |
| 2 | 5756 | | if ((int)_statusCode != 204) |
| | 5757 | | { |
| 0 | 5758 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 5759 | | try |
| | 5760 | | { |
| 0 | 5761 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 5762 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 5763 | | if (_errorBody != null) |
| | 5764 | | { |
| 0 | 5765 | | ex.Body = _errorBody; |
| | 5766 | | } |
| 0 | 5767 | | } |
| 0 | 5768 | | catch (JsonException) |
| | 5769 | | { |
| | 5770 | | // Ignore the exception |
| 0 | 5771 | | } |
| 0 | 5772 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 5773 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 5774 | | if (_shouldTrace) |
| | 5775 | | { |
| 0 | 5776 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 5777 | | } |
| 0 | 5778 | | _httpRequest.Dispose(); |
| 0 | 5779 | | if (_httpResponse != null) |
| | 5780 | | { |
| 0 | 5781 | | _httpResponse.Dispose(); |
| | 5782 | | } |
| 0 | 5783 | | throw ex; |
| | 5784 | | } |
| | 5785 | | // Create Result |
| 2 | 5786 | | var _result = new HttpOperationResponse(); |
| 2 | 5787 | | _result.Request = _httpRequest; |
| 2 | 5788 | | _result.Response = _httpResponse; |
| 2 | 5789 | | if (_shouldTrace) |
| | 5790 | | { |
| 0 | 5791 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 5792 | | } |
| 2 | 5793 | | return _result; |
| 2 | 5794 | | } |
| | 5795 | |
|
| | 5796 | | /// <summary> |
| | 5797 | | /// Update a specific iteration. |
| | 5798 | | /// </summary> |
| | 5799 | | /// <param name='projectId'> |
| | 5800 | | /// Project id. |
| | 5801 | | /// </param> |
| | 5802 | | /// <param name='iterationId'> |
| | 5803 | | /// Iteration id. |
| | 5804 | | /// </param> |
| | 5805 | | /// <param name='updatedIteration'> |
| | 5806 | | /// The updated iteration model. |
| | 5807 | | /// </param> |
| | 5808 | | /// <param name='customHeaders'> |
| | 5809 | | /// Headers that will be added to request. |
| | 5810 | | /// </param> |
| | 5811 | | /// <param name='cancellationToken'> |
| | 5812 | | /// The cancellation token. |
| | 5813 | | /// </param> |
| | 5814 | | /// <exception cref="CustomVisionErrorException"> |
| | 5815 | | /// Thrown when the operation returned an invalid status code |
| | 5816 | | /// </exception> |
| | 5817 | | /// <exception cref="SerializationException"> |
| | 5818 | | /// Thrown when unable to deserialize the response |
| | 5819 | | /// </exception> |
| | 5820 | | /// <exception cref="ValidationException"> |
| | 5821 | | /// Thrown when a required parameter is null |
| | 5822 | | /// </exception> |
| | 5823 | | /// <exception cref="System.ArgumentNullException"> |
| | 5824 | | /// Thrown when a required parameter is null |
| | 5825 | | /// </exception> |
| | 5826 | | /// <return> |
| | 5827 | | /// A response object containing the response body and response headers. |
| | 5828 | | /// </return> |
| | 5829 | | public async Task<HttpOperationResponse<Iteration>> UpdateIterationWithHttpMessagesAsync(System.Guid projectId, |
| | 5830 | | { |
| 2 | 5831 | | if (Endpoint == null) |
| | 5832 | | { |
| 0 | 5833 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 5834 | | } |
| 2 | 5835 | | if (updatedIteration == null) |
| | 5836 | | { |
| 0 | 5837 | | throw new ValidationException(ValidationRules.CannotBeNull, "updatedIteration"); |
| | 5838 | | } |
| | 5839 | | // Tracing |
| 2 | 5840 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 5841 | | string _invocationId = null; |
| 2 | 5842 | | if (_shouldTrace) |
| | 5843 | | { |
| 0 | 5844 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 5845 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 5846 | | tracingParameters.Add("projectId", projectId); |
| 0 | 5847 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 5848 | | tracingParameters.Add("updatedIteration", updatedIteration); |
| 0 | 5849 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 5850 | | ServiceClientTracing.Enter(_invocationId, this, "UpdateIteration", tracingParameters); |
| | 5851 | | } |
| | 5852 | | // Construct URL |
| 2 | 5853 | | var _baseUrl = BaseUri; |
| 2 | 5854 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/iterations/{iterationId}"; |
| 2 | 5855 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 5856 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 5857 | | _url = _url.Replace("{iterationId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(iterationId |
| | 5858 | | // Create HTTP transport objects |
| 2 | 5859 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 5860 | | HttpResponseMessage _httpResponse = null; |
| 2 | 5861 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 2 | 5862 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 5863 | | // Set Headers |
| | 5864 | |
|
| | 5865 | |
|
| 2 | 5866 | | if (customHeaders != null) |
| | 5867 | | { |
| 0 | 5868 | | foreach(var _header in customHeaders) |
| | 5869 | | { |
| 0 | 5870 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 5871 | | { |
| 0 | 5872 | | _httpRequest.Headers.Remove(_header.Key); |
| | 5873 | | } |
| 0 | 5874 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 5875 | | } |
| | 5876 | | } |
| | 5877 | |
|
| | 5878 | | // Serialize Request |
| 2 | 5879 | | string _requestContent = null; |
| 2 | 5880 | | if(updatedIteration != null) |
| | 5881 | | { |
| 2 | 5882 | | _requestContent = SafeJsonConvert.SerializeObject(updatedIteration, SerializationSettings); |
| 2 | 5883 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 2 | 5884 | | _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); |
| | 5885 | | } |
| | 5886 | | // Set Credentials |
| 2 | 5887 | | if (Credentials != null) |
| | 5888 | | { |
| 2 | 5889 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 5890 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 5891 | | } |
| | 5892 | | // Send Request |
| 2 | 5893 | | if (_shouldTrace) |
| | 5894 | | { |
| 0 | 5895 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 5896 | | } |
| 2 | 5897 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 5898 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 5899 | | if (_shouldTrace) |
| | 5900 | | { |
| 0 | 5901 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 5902 | | } |
| 2 | 5903 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 5904 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 5905 | | string _responseContent = null; |
| 2 | 5906 | | if ((int)_statusCode != 200) |
| | 5907 | | { |
| 0 | 5908 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 5909 | | try |
| | 5910 | | { |
| 0 | 5911 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 5912 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 5913 | | if (_errorBody != null) |
| | 5914 | | { |
| 0 | 5915 | | ex.Body = _errorBody; |
| | 5916 | | } |
| 0 | 5917 | | } |
| 0 | 5918 | | catch (JsonException) |
| | 5919 | | { |
| | 5920 | | // Ignore the exception |
| 0 | 5921 | | } |
| 0 | 5922 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 5923 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 5924 | | if (_shouldTrace) |
| | 5925 | | { |
| 0 | 5926 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 5927 | | } |
| 0 | 5928 | | _httpRequest.Dispose(); |
| 0 | 5929 | | if (_httpResponse != null) |
| | 5930 | | { |
| 0 | 5931 | | _httpResponse.Dispose(); |
| | 5932 | | } |
| 0 | 5933 | | throw ex; |
| | 5934 | | } |
| | 5935 | | // Create Result |
| 2 | 5936 | | var _result = new HttpOperationResponse<Iteration>(); |
| 2 | 5937 | | _result.Request = _httpRequest; |
| 2 | 5938 | | _result.Response = _httpResponse; |
| | 5939 | | // Deserialize Response |
| 2 | 5940 | | if ((int)_statusCode == 200) |
| | 5941 | | { |
| 2 | 5942 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 5943 | | try |
| | 5944 | | { |
| 2 | 5945 | | _result.Body = SafeJsonConvert.DeserializeObject<Iteration>(_responseContent, DeserializationSetting |
| 2 | 5946 | | } |
| 0 | 5947 | | catch (JsonException ex) |
| | 5948 | | { |
| 0 | 5949 | | _httpRequest.Dispose(); |
| 0 | 5950 | | if (_httpResponse != null) |
| | 5951 | | { |
| 0 | 5952 | | _httpResponse.Dispose(); |
| | 5953 | | } |
| 0 | 5954 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 5955 | | } |
| | 5956 | | } |
| 2 | 5957 | | if (_shouldTrace) |
| | 5958 | | { |
| 0 | 5959 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 5960 | | } |
| 2 | 5961 | | return _result; |
| 2 | 5962 | | } |
| | 5963 | |
|
| | 5964 | | /// <summary> |
| | 5965 | | /// Get the list of exports for a specific iteration. |
| | 5966 | | /// </summary> |
| | 5967 | | /// <param name='projectId'> |
| | 5968 | | /// The project id. |
| | 5969 | | /// </param> |
| | 5970 | | /// <param name='iterationId'> |
| | 5971 | | /// The iteration id. |
| | 5972 | | /// </param> |
| | 5973 | | /// <param name='customHeaders'> |
| | 5974 | | /// Headers that will be added to request. |
| | 5975 | | /// </param> |
| | 5976 | | /// <param name='cancellationToken'> |
| | 5977 | | /// The cancellation token. |
| | 5978 | | /// </param> |
| | 5979 | | /// <exception cref="CustomVisionErrorException"> |
| | 5980 | | /// Thrown when the operation returned an invalid status code |
| | 5981 | | /// </exception> |
| | 5982 | | /// <exception cref="SerializationException"> |
| | 5983 | | /// Thrown when unable to deserialize the response |
| | 5984 | | /// </exception> |
| | 5985 | | /// <exception cref="ValidationException"> |
| | 5986 | | /// Thrown when a required parameter is null |
| | 5987 | | /// </exception> |
| | 5988 | | /// <exception cref="System.ArgumentNullException"> |
| | 5989 | | /// Thrown when a required parameter is null |
| | 5990 | | /// </exception> |
| | 5991 | | /// <return> |
| | 5992 | | /// A response object containing the response body and response headers. |
| | 5993 | | /// </return> |
| | 5994 | | public async Task<HttpOperationResponse<IList<Export>>> GetExportsWithHttpMessagesAsync(System.Guid projectId, S |
| | 5995 | | { |
| 12 | 5996 | | if (Endpoint == null) |
| | 5997 | | { |
| 0 | 5998 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 5999 | | } |
| | 6000 | | // Tracing |
| 12 | 6001 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 12 | 6002 | | string _invocationId = null; |
| 12 | 6003 | | if (_shouldTrace) |
| | 6004 | | { |
| 0 | 6005 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 6006 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 6007 | | tracingParameters.Add("projectId", projectId); |
| 0 | 6008 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 6009 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 6010 | | ServiceClientTracing.Enter(_invocationId, this, "GetExports", tracingParameters); |
| | 6011 | | } |
| | 6012 | | // Construct URL |
| 12 | 6013 | | var _baseUrl = BaseUri; |
| 12 | 6014 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/iterations/{iterationId}/e |
| 12 | 6015 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 12 | 6016 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 12 | 6017 | | _url = _url.Replace("{iterationId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(iterationId |
| | 6018 | | // Create HTTP transport objects |
| 12 | 6019 | | var _httpRequest = new HttpRequestMessage(); |
| 12 | 6020 | | HttpResponseMessage _httpResponse = null; |
| 12 | 6021 | | _httpRequest.Method = new HttpMethod("GET"); |
| 12 | 6022 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 6023 | | // Set Headers |
| | 6024 | |
|
| | 6025 | |
|
| 12 | 6026 | | if (customHeaders != null) |
| | 6027 | | { |
| 0 | 6028 | | foreach(var _header in customHeaders) |
| | 6029 | | { |
| 0 | 6030 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 6031 | | { |
| 0 | 6032 | | _httpRequest.Headers.Remove(_header.Key); |
| | 6033 | | } |
| 0 | 6034 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 6035 | | } |
| | 6036 | | } |
| | 6037 | |
|
| | 6038 | | // Serialize Request |
| 12 | 6039 | | string _requestContent = null; |
| | 6040 | | // Set Credentials |
| 12 | 6041 | | if (Credentials != null) |
| | 6042 | | { |
| 12 | 6043 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 6044 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 6045 | | } |
| | 6046 | | // Send Request |
| 12 | 6047 | | if (_shouldTrace) |
| | 6048 | | { |
| 0 | 6049 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 6050 | | } |
| 12 | 6051 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 6052 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 12 | 6053 | | if (_shouldTrace) |
| | 6054 | | { |
| 0 | 6055 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 6056 | | } |
| 12 | 6057 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 12 | 6058 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 6059 | | string _responseContent = null; |
| 12 | 6060 | | if ((int)_statusCode != 200) |
| | 6061 | | { |
| 0 | 6062 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 6063 | | try |
| | 6064 | | { |
| 0 | 6065 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 6066 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 6067 | | if (_errorBody != null) |
| | 6068 | | { |
| 0 | 6069 | | ex.Body = _errorBody; |
| | 6070 | | } |
| 0 | 6071 | | } |
| 0 | 6072 | | catch (JsonException) |
| | 6073 | | { |
| | 6074 | | // Ignore the exception |
| 0 | 6075 | | } |
| 0 | 6076 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 6077 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 6078 | | if (_shouldTrace) |
| | 6079 | | { |
| 0 | 6080 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 6081 | | } |
| 0 | 6082 | | _httpRequest.Dispose(); |
| 0 | 6083 | | if (_httpResponse != null) |
| | 6084 | | { |
| 0 | 6085 | | _httpResponse.Dispose(); |
| | 6086 | | } |
| 0 | 6087 | | throw ex; |
| | 6088 | | } |
| | 6089 | | // Create Result |
| 12 | 6090 | | var _result = new HttpOperationResponse<IList<Export>>(); |
| 12 | 6091 | | _result.Request = _httpRequest; |
| 12 | 6092 | | _result.Response = _httpResponse; |
| | 6093 | | // Deserialize Response |
| 12 | 6094 | | if ((int)_statusCode == 200) |
| | 6095 | | { |
| 12 | 6096 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 6097 | | try |
| | 6098 | | { |
| 12 | 6099 | | _result.Body = SafeJsonConvert.DeserializeObject<IList<Export>>(_responseContent, DeserializationSet |
| 12 | 6100 | | } |
| 0 | 6101 | | catch (JsonException ex) |
| | 6102 | | { |
| 0 | 6103 | | _httpRequest.Dispose(); |
| 0 | 6104 | | if (_httpResponse != null) |
| | 6105 | | { |
| 0 | 6106 | | _httpResponse.Dispose(); |
| | 6107 | | } |
| 0 | 6108 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 6109 | | } |
| | 6110 | | } |
| 12 | 6111 | | if (_shouldTrace) |
| | 6112 | | { |
| 0 | 6113 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 6114 | | } |
| 12 | 6115 | | return _result; |
| 12 | 6116 | | } |
| | 6117 | |
|
| | 6118 | | /// <summary> |
| | 6119 | | /// Export a trained iteration. |
| | 6120 | | /// </summary> |
| | 6121 | | /// <param name='projectId'> |
| | 6122 | | /// The project id. |
| | 6123 | | /// </param> |
| | 6124 | | /// <param name='iterationId'> |
| | 6125 | | /// The iteration id. |
| | 6126 | | /// </param> |
| | 6127 | | /// <param name='platform'> |
| | 6128 | | /// The target platform. Possible values include: 'CoreML', 'TensorFlow', |
| | 6129 | | /// 'DockerFile', 'ONNX', 'VAIDK' |
| | 6130 | | /// </param> |
| | 6131 | | /// <param name='flavor'> |
| | 6132 | | /// The flavor of the target platform. Possible values include: 'Linux', |
| | 6133 | | /// 'Windows', 'ONNX10', 'ONNX12', 'ARM', 'TensorFlowNormal', 'TensorFlowLite' |
| | 6134 | | /// </param> |
| | 6135 | | /// <param name='customHeaders'> |
| | 6136 | | /// Headers that will be added to request. |
| | 6137 | | /// </param> |
| | 6138 | | /// <param name='cancellationToken'> |
| | 6139 | | /// The cancellation token. |
| | 6140 | | /// </param> |
| | 6141 | | /// <exception cref="CustomVisionErrorException"> |
| | 6142 | | /// Thrown when the operation returned an invalid status code |
| | 6143 | | /// </exception> |
| | 6144 | | /// <exception cref="SerializationException"> |
| | 6145 | | /// Thrown when unable to deserialize the response |
| | 6146 | | /// </exception> |
| | 6147 | | /// <exception cref="ValidationException"> |
| | 6148 | | /// Thrown when a required parameter is null |
| | 6149 | | /// </exception> |
| | 6150 | | /// <exception cref="System.ArgumentNullException"> |
| | 6151 | | /// Thrown when a required parameter is null |
| | 6152 | | /// </exception> |
| | 6153 | | /// <return> |
| | 6154 | | /// A response object containing the response body and response headers. |
| | 6155 | | /// </return> |
| | 6156 | | public async Task<HttpOperationResponse<Export>> ExportIterationWithHttpMessagesAsync(System.Guid projectId, Sys |
| | 6157 | | { |
| 2 | 6158 | | if (Endpoint == null) |
| | 6159 | | { |
| 0 | 6160 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 6161 | | } |
| 2 | 6162 | | if (platform == null) |
| | 6163 | | { |
| 0 | 6164 | | throw new ValidationException(ValidationRules.CannotBeNull, "platform"); |
| | 6165 | | } |
| | 6166 | | // Tracing |
| 2 | 6167 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 6168 | | string _invocationId = null; |
| 2 | 6169 | | if (_shouldTrace) |
| | 6170 | | { |
| 0 | 6171 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 6172 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 6173 | | tracingParameters.Add("projectId", projectId); |
| 0 | 6174 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 6175 | | tracingParameters.Add("platform", platform); |
| 0 | 6176 | | tracingParameters.Add("flavor", flavor); |
| 0 | 6177 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 6178 | | ServiceClientTracing.Enter(_invocationId, this, "ExportIteration", tracingParameters); |
| | 6179 | | } |
| | 6180 | | // Construct URL |
| 2 | 6181 | | var _baseUrl = BaseUri; |
| 2 | 6182 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/iterations/{iterationId}/e |
| 2 | 6183 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 6184 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 6185 | | _url = _url.Replace("{iterationId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(iterationId |
| 2 | 6186 | | List<string> _queryParameters = new List<string>(); |
| 2 | 6187 | | if (platform != null) |
| | 6188 | | { |
| 2 | 6189 | | _queryParameters.Add(string.Format("platform={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serialize |
| | 6190 | | } |
| 2 | 6191 | | if (flavor != null) |
| | 6192 | | { |
| 0 | 6193 | | _queryParameters.Add(string.Format("flavor={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeOb |
| | 6194 | | } |
| 2 | 6195 | | if (_queryParameters.Count > 0) |
| | 6196 | | { |
| 2 | 6197 | | _url += "?" + string.Join("&", _queryParameters); |
| | 6198 | | } |
| | 6199 | | // Create HTTP transport objects |
| 2 | 6200 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 6201 | | HttpResponseMessage _httpResponse = null; |
| 2 | 6202 | | _httpRequest.Method = new HttpMethod("POST"); |
| 2 | 6203 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 6204 | | // Set Headers |
| | 6205 | |
|
| | 6206 | |
|
| 2 | 6207 | | if (customHeaders != null) |
| | 6208 | | { |
| 0 | 6209 | | foreach(var _header in customHeaders) |
| | 6210 | | { |
| 0 | 6211 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 6212 | | { |
| 0 | 6213 | | _httpRequest.Headers.Remove(_header.Key); |
| | 6214 | | } |
| 0 | 6215 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 6216 | | } |
| | 6217 | | } |
| | 6218 | |
|
| | 6219 | | // Serialize Request |
| 2 | 6220 | | string _requestContent = null; |
| | 6221 | | // Set Credentials |
| 2 | 6222 | | if (Credentials != null) |
| | 6223 | | { |
| 2 | 6224 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 6225 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 6226 | | } |
| | 6227 | | // Send Request |
| 2 | 6228 | | if (_shouldTrace) |
| | 6229 | | { |
| 0 | 6230 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 6231 | | } |
| 2 | 6232 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 6233 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 6234 | | if (_shouldTrace) |
| | 6235 | | { |
| 0 | 6236 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 6237 | | } |
| 2 | 6238 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 6239 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 6240 | | string _responseContent = null; |
| 2 | 6241 | | if ((int)_statusCode != 200) |
| | 6242 | | { |
| 0 | 6243 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 6244 | | try |
| | 6245 | | { |
| 0 | 6246 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 6247 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 6248 | | if (_errorBody != null) |
| | 6249 | | { |
| 0 | 6250 | | ex.Body = _errorBody; |
| | 6251 | | } |
| 0 | 6252 | | } |
| 0 | 6253 | | catch (JsonException) |
| | 6254 | | { |
| | 6255 | | // Ignore the exception |
| 0 | 6256 | | } |
| 0 | 6257 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 6258 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 6259 | | if (_shouldTrace) |
| | 6260 | | { |
| 0 | 6261 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 6262 | | } |
| 0 | 6263 | | _httpRequest.Dispose(); |
| 0 | 6264 | | if (_httpResponse != null) |
| | 6265 | | { |
| 0 | 6266 | | _httpResponse.Dispose(); |
| | 6267 | | } |
| 0 | 6268 | | throw ex; |
| | 6269 | | } |
| | 6270 | | // Create Result |
| 2 | 6271 | | var _result = new HttpOperationResponse<Export>(); |
| 2 | 6272 | | _result.Request = _httpRequest; |
| 2 | 6273 | | _result.Response = _httpResponse; |
| | 6274 | | // Deserialize Response |
| 2 | 6275 | | if ((int)_statusCode == 200) |
| | 6276 | | { |
| 2 | 6277 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 6278 | | try |
| | 6279 | | { |
| 2 | 6280 | | _result.Body = SafeJsonConvert.DeserializeObject<Export>(_responseContent, DeserializationSettings); |
| 2 | 6281 | | } |
| 0 | 6282 | | catch (JsonException ex) |
| | 6283 | | { |
| 0 | 6284 | | _httpRequest.Dispose(); |
| 0 | 6285 | | if (_httpResponse != null) |
| | 6286 | | { |
| 0 | 6287 | | _httpResponse.Dispose(); |
| | 6288 | | } |
| 0 | 6289 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 6290 | | } |
| | 6291 | | } |
| 2 | 6292 | | if (_shouldTrace) |
| | 6293 | | { |
| 0 | 6294 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 6295 | | } |
| 2 | 6296 | | return _result; |
| 2 | 6297 | | } |
| | 6298 | |
|
| | 6299 | | /// <summary> |
| | 6300 | | /// Get detailed performance information about an iteration. |
| | 6301 | | /// </summary> |
| | 6302 | | /// <param name='projectId'> |
| | 6303 | | /// The id of the project the iteration belongs to. |
| | 6304 | | /// </param> |
| | 6305 | | /// <param name='iterationId'> |
| | 6306 | | /// The id of the iteration to get. |
| | 6307 | | /// </param> |
| | 6308 | | /// <param name='threshold'> |
| | 6309 | | /// The threshold used to determine true predictions. |
| | 6310 | | /// </param> |
| | 6311 | | /// <param name='overlapThreshold'> |
| | 6312 | | /// If applicable, the bounding box overlap threshold used to determine true |
| | 6313 | | /// predictions. |
| | 6314 | | /// </param> |
| | 6315 | | /// <param name='customHeaders'> |
| | 6316 | | /// Headers that will be added to request. |
| | 6317 | | /// </param> |
| | 6318 | | /// <param name='cancellationToken'> |
| | 6319 | | /// The cancellation token. |
| | 6320 | | /// </param> |
| | 6321 | | /// <exception cref="CustomVisionErrorException"> |
| | 6322 | | /// Thrown when the operation returned an invalid status code |
| | 6323 | | /// </exception> |
| | 6324 | | /// <exception cref="SerializationException"> |
| | 6325 | | /// Thrown when unable to deserialize the response |
| | 6326 | | /// </exception> |
| | 6327 | | /// <exception cref="ValidationException"> |
| | 6328 | | /// Thrown when a required parameter is null |
| | 6329 | | /// </exception> |
| | 6330 | | /// <exception cref="System.ArgumentNullException"> |
| | 6331 | | /// Thrown when a required parameter is null |
| | 6332 | | /// </exception> |
| | 6333 | | /// <return> |
| | 6334 | | /// A response object containing the response body and response headers. |
| | 6335 | | /// </return> |
| | 6336 | | public async Task<HttpOperationResponse<IterationPerformance>> GetIterationPerformanceWithHttpMessagesAsync(Syst |
| | 6337 | | { |
| 2 | 6338 | | if (Endpoint == null) |
| | 6339 | | { |
| 0 | 6340 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 6341 | | } |
| | 6342 | | // Tracing |
| 2 | 6343 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 6344 | | string _invocationId = null; |
| 2 | 6345 | | if (_shouldTrace) |
| | 6346 | | { |
| 0 | 6347 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 6348 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 6349 | | tracingParameters.Add("projectId", projectId); |
| 0 | 6350 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 6351 | | tracingParameters.Add("threshold", threshold); |
| 0 | 6352 | | tracingParameters.Add("overlapThreshold", overlapThreshold); |
| 0 | 6353 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 6354 | | ServiceClientTracing.Enter(_invocationId, this, "GetIterationPerformance", tracingParameters); |
| | 6355 | | } |
| | 6356 | | // Construct URL |
| 2 | 6357 | | var _baseUrl = BaseUri; |
| 2 | 6358 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/iterations/{iterationId}/p |
| 2 | 6359 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 6360 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 6361 | | _url = _url.Replace("{iterationId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(iterationId |
| 2 | 6362 | | List<string> _queryParameters = new List<string>(); |
| 2 | 6363 | | if (threshold != null) |
| | 6364 | | { |
| 2 | 6365 | | _queryParameters.Add(string.Format("threshold={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serializ |
| | 6366 | | } |
| 2 | 6367 | | if (overlapThreshold != null) |
| | 6368 | | { |
| 0 | 6369 | | _queryParameters.Add(string.Format("overlapThreshold={0}", System.Uri.EscapeDataString(SafeJsonConvert.S |
| | 6370 | | } |
| 2 | 6371 | | if (_queryParameters.Count > 0) |
| | 6372 | | { |
| 2 | 6373 | | _url += "?" + string.Join("&", _queryParameters); |
| | 6374 | | } |
| | 6375 | | // Create HTTP transport objects |
| 2 | 6376 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 6377 | | HttpResponseMessage _httpResponse = null; |
| 2 | 6378 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 6379 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 6380 | | // Set Headers |
| | 6381 | |
|
| | 6382 | |
|
| 2 | 6383 | | if (customHeaders != null) |
| | 6384 | | { |
| 0 | 6385 | | foreach(var _header in customHeaders) |
| | 6386 | | { |
| 0 | 6387 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 6388 | | { |
| 0 | 6389 | | _httpRequest.Headers.Remove(_header.Key); |
| | 6390 | | } |
| 0 | 6391 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 6392 | | } |
| | 6393 | | } |
| | 6394 | |
|
| | 6395 | | // Serialize Request |
| 2 | 6396 | | string _requestContent = null; |
| | 6397 | | // Set Credentials |
| 2 | 6398 | | if (Credentials != null) |
| | 6399 | | { |
| 2 | 6400 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 6401 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 6402 | | } |
| | 6403 | | // Send Request |
| 2 | 6404 | | if (_shouldTrace) |
| | 6405 | | { |
| 0 | 6406 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 6407 | | } |
| 2 | 6408 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 6409 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 6410 | | if (_shouldTrace) |
| | 6411 | | { |
| 0 | 6412 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 6413 | | } |
| 2 | 6414 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 6415 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 6416 | | string _responseContent = null; |
| 2 | 6417 | | if ((int)_statusCode != 200) |
| | 6418 | | { |
| 0 | 6419 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 6420 | | try |
| | 6421 | | { |
| 0 | 6422 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 6423 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 6424 | | if (_errorBody != null) |
| | 6425 | | { |
| 0 | 6426 | | ex.Body = _errorBody; |
| | 6427 | | } |
| 0 | 6428 | | } |
| 0 | 6429 | | catch (JsonException) |
| | 6430 | | { |
| | 6431 | | // Ignore the exception |
| 0 | 6432 | | } |
| 0 | 6433 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 6434 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 6435 | | if (_shouldTrace) |
| | 6436 | | { |
| 0 | 6437 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 6438 | | } |
| 0 | 6439 | | _httpRequest.Dispose(); |
| 0 | 6440 | | if (_httpResponse != null) |
| | 6441 | | { |
| 0 | 6442 | | _httpResponse.Dispose(); |
| | 6443 | | } |
| 0 | 6444 | | throw ex; |
| | 6445 | | } |
| | 6446 | | // Create Result |
| 2 | 6447 | | var _result = new HttpOperationResponse<IterationPerformance>(); |
| 2 | 6448 | | _result.Request = _httpRequest; |
| 2 | 6449 | | _result.Response = _httpResponse; |
| | 6450 | | // Deserialize Response |
| 2 | 6451 | | if ((int)_statusCode == 200) |
| | 6452 | | { |
| 2 | 6453 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 6454 | | try |
| | 6455 | | { |
| 2 | 6456 | | _result.Body = SafeJsonConvert.DeserializeObject<IterationPerformance>(_responseContent, Deserializa |
| 2 | 6457 | | } |
| 0 | 6458 | | catch (JsonException ex) |
| | 6459 | | { |
| 0 | 6460 | | _httpRequest.Dispose(); |
| 0 | 6461 | | if (_httpResponse != null) |
| | 6462 | | { |
| 0 | 6463 | | _httpResponse.Dispose(); |
| | 6464 | | } |
| 0 | 6465 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 6466 | | } |
| | 6467 | | } |
| 2 | 6468 | | if (_shouldTrace) |
| | 6469 | | { |
| 0 | 6470 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 6471 | | } |
| 2 | 6472 | | return _result; |
| 2 | 6473 | | } |
| | 6474 | |
|
| | 6475 | | /// <summary> |
| | 6476 | | /// Get image with its prediction for a given project iteration. |
| | 6477 | | /// </summary> |
| | 6478 | | /// <remarks> |
| | 6479 | | /// This API supports batching and range selection. By default it will only |
| | 6480 | | /// return first 50 images matching images. |
| | 6481 | | /// Use the {take} and {skip} parameters to control how many images to return |
| | 6482 | | /// in a given batch. |
| | 6483 | | /// The filtering is on an and/or relationship. For example, if the provided |
| | 6484 | | /// tag ids are for the "Dog" and |
| | 6485 | | /// "Cat" tags, then only images tagged with Dog and/or Cat will be returned |
| | 6486 | | /// </remarks> |
| | 6487 | | /// <param name='projectId'> |
| | 6488 | | /// The project id. |
| | 6489 | | /// </param> |
| | 6490 | | /// <param name='iterationId'> |
| | 6491 | | /// The iteration id. Defaults to workspace. |
| | 6492 | | /// </param> |
| | 6493 | | /// <param name='tagIds'> |
| | 6494 | | /// A list of tags ids to filter the images. Defaults to all tagged images when |
| | 6495 | | /// null. Limited to 20. |
| | 6496 | | /// </param> |
| | 6497 | | /// <param name='orderBy'> |
| | 6498 | | /// The ordering. Defaults to newest. Possible values include: 'Newest', |
| | 6499 | | /// 'Oldest' |
| | 6500 | | /// </param> |
| | 6501 | | /// <param name='take'> |
| | 6502 | | /// Maximum number of images to return. Defaults to 50, limited to 256. |
| | 6503 | | /// </param> |
| | 6504 | | /// <param name='skip'> |
| | 6505 | | /// Number of images to skip before beginning the image batch. Defaults to 0. |
| | 6506 | | /// </param> |
| | 6507 | | /// <param name='customHeaders'> |
| | 6508 | | /// Headers that will be added to request. |
| | 6509 | | /// </param> |
| | 6510 | | /// <param name='cancellationToken'> |
| | 6511 | | /// The cancellation token. |
| | 6512 | | /// </param> |
| | 6513 | | /// <exception cref="CustomVisionErrorException"> |
| | 6514 | | /// Thrown when the operation returned an invalid status code |
| | 6515 | | /// </exception> |
| | 6516 | | /// <exception cref="SerializationException"> |
| | 6517 | | /// Thrown when unable to deserialize the response |
| | 6518 | | /// </exception> |
| | 6519 | | /// <exception cref="ValidationException"> |
| | 6520 | | /// Thrown when a required parameter is null |
| | 6521 | | /// </exception> |
| | 6522 | | /// <exception cref="System.ArgumentNullException"> |
| | 6523 | | /// Thrown when a required parameter is null |
| | 6524 | | /// </exception> |
| | 6525 | | /// <return> |
| | 6526 | | /// A response object containing the response body and response headers. |
| | 6527 | | /// </return> |
| | 6528 | | public async Task<HttpOperationResponse<IList<ImagePerformance>>> GetImagePerformancesWithHttpMessagesAsync(Syst |
| | 6529 | | { |
| 0 | 6530 | | if (Endpoint == null) |
| | 6531 | | { |
| 0 | 6532 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 6533 | | } |
| 0 | 6534 | | if (tagIds != null) |
| | 6535 | | { |
| 0 | 6536 | | if (tagIds.Count > 20) |
| | 6537 | | { |
| 0 | 6538 | | throw new ValidationException(ValidationRules.MaxItems, "tagIds", 20); |
| | 6539 | | } |
| 0 | 6540 | | if (tagIds.Count < 0) |
| | 6541 | | { |
| 0 | 6542 | | throw new ValidationException(ValidationRules.MinItems, "tagIds", 0); |
| | 6543 | | } |
| | 6544 | | } |
| 0 | 6545 | | if (take > 256) |
| | 6546 | | { |
| 0 | 6547 | | throw new ValidationException(ValidationRules.InclusiveMaximum, "take", 256); |
| | 6548 | | } |
| 0 | 6549 | | if (take < 0) |
| | 6550 | | { |
| 0 | 6551 | | throw new ValidationException(ValidationRules.InclusiveMinimum, "take", 0); |
| | 6552 | | } |
| | 6553 | | // Tracing |
| 0 | 6554 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 0 | 6555 | | string _invocationId = null; |
| 0 | 6556 | | if (_shouldTrace) |
| | 6557 | | { |
| 0 | 6558 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 6559 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 6560 | | tracingParameters.Add("projectId", projectId); |
| 0 | 6561 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 6562 | | tracingParameters.Add("tagIds", tagIds); |
| 0 | 6563 | | tracingParameters.Add("orderBy", orderBy); |
| 0 | 6564 | | tracingParameters.Add("take", take); |
| 0 | 6565 | | tracingParameters.Add("skip", skip); |
| 0 | 6566 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 6567 | | ServiceClientTracing.Enter(_invocationId, this, "GetImagePerformances", tracingParameters); |
| | 6568 | | } |
| | 6569 | | // Construct URL |
| 0 | 6570 | | var _baseUrl = BaseUri; |
| 0 | 6571 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/iterations/{iterationId}/p |
| 0 | 6572 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 0 | 6573 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 0 | 6574 | | _url = _url.Replace("{iterationId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(iterationId |
| 0 | 6575 | | List<string> _queryParameters = new List<string>(); |
| 0 | 6576 | | if (tagIds != null) |
| | 6577 | | { |
| 0 | 6578 | | _queryParameters.Add(string.Format("tagIds={0}", System.Uri.EscapeDataString(string.Join(",", tagIds)))) |
| | 6579 | | } |
| 0 | 6580 | | if (orderBy != null) |
| | 6581 | | { |
| 0 | 6582 | | _queryParameters.Add(string.Format("orderBy={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| | 6583 | | } |
| 0 | 6584 | | if (take != null) |
| | 6585 | | { |
| 0 | 6586 | | _queryParameters.Add(string.Format("take={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObje |
| | 6587 | | } |
| 0 | 6588 | | if (skip != null) |
| | 6589 | | { |
| 0 | 6590 | | _queryParameters.Add(string.Format("skip={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObje |
| | 6591 | | } |
| 0 | 6592 | | if (_queryParameters.Count > 0) |
| | 6593 | | { |
| 0 | 6594 | | _url += "?" + string.Join("&", _queryParameters); |
| | 6595 | | } |
| | 6596 | | // Create HTTP transport objects |
| 0 | 6597 | | var _httpRequest = new HttpRequestMessage(); |
| 0 | 6598 | | HttpResponseMessage _httpResponse = null; |
| 0 | 6599 | | _httpRequest.Method = new HttpMethod("GET"); |
| 0 | 6600 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 6601 | | // Set Headers |
| | 6602 | |
|
| | 6603 | |
|
| 0 | 6604 | | if (customHeaders != null) |
| | 6605 | | { |
| 0 | 6606 | | foreach(var _header in customHeaders) |
| | 6607 | | { |
| 0 | 6608 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 6609 | | { |
| 0 | 6610 | | _httpRequest.Headers.Remove(_header.Key); |
| | 6611 | | } |
| 0 | 6612 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 6613 | | } |
| | 6614 | | } |
| | 6615 | |
|
| | 6616 | | // Serialize Request |
| 0 | 6617 | | string _requestContent = null; |
| | 6618 | | // Set Credentials |
| 0 | 6619 | | if (Credentials != null) |
| | 6620 | | { |
| 0 | 6621 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 6622 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 6623 | | } |
| | 6624 | | // Send Request |
| 0 | 6625 | | if (_shouldTrace) |
| | 6626 | | { |
| 0 | 6627 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 6628 | | } |
| 0 | 6629 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 6630 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 0 | 6631 | | if (_shouldTrace) |
| | 6632 | | { |
| 0 | 6633 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 6634 | | } |
| 0 | 6635 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 0 | 6636 | | cancellationToken.ThrowIfCancellationRequested(); |
| 0 | 6637 | | string _responseContent = null; |
| 0 | 6638 | | if ((int)_statusCode != 200) |
| | 6639 | | { |
| 0 | 6640 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 6641 | | try |
| | 6642 | | { |
| 0 | 6643 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 6644 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 6645 | | if (_errorBody != null) |
| | 6646 | | { |
| 0 | 6647 | | ex.Body = _errorBody; |
| | 6648 | | } |
| 0 | 6649 | | } |
| 0 | 6650 | | catch (JsonException) |
| | 6651 | | { |
| | 6652 | | // Ignore the exception |
| 0 | 6653 | | } |
| 0 | 6654 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 6655 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 6656 | | if (_shouldTrace) |
| | 6657 | | { |
| 0 | 6658 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 6659 | | } |
| 0 | 6660 | | _httpRequest.Dispose(); |
| 0 | 6661 | | if (_httpResponse != null) |
| | 6662 | | { |
| 0 | 6663 | | _httpResponse.Dispose(); |
| | 6664 | | } |
| 0 | 6665 | | throw ex; |
| | 6666 | | } |
| | 6667 | | // Create Result |
| 0 | 6668 | | var _result = new HttpOperationResponse<IList<ImagePerformance>>(); |
| 0 | 6669 | | _result.Request = _httpRequest; |
| 0 | 6670 | | _result.Response = _httpResponse; |
| | 6671 | | // Deserialize Response |
| 0 | 6672 | | if ((int)_statusCode == 200) |
| | 6673 | | { |
| 0 | 6674 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 6675 | | try |
| | 6676 | | { |
| 0 | 6677 | | _result.Body = SafeJsonConvert.DeserializeObject<IList<ImagePerformance>>(_responseContent, Deserial |
| 0 | 6678 | | } |
| 0 | 6679 | | catch (JsonException ex) |
| | 6680 | | { |
| 0 | 6681 | | _httpRequest.Dispose(); |
| 0 | 6682 | | if (_httpResponse != null) |
| | 6683 | | { |
| 0 | 6684 | | _httpResponse.Dispose(); |
| | 6685 | | } |
| 0 | 6686 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 6687 | | } |
| | 6688 | | } |
| 0 | 6689 | | if (_shouldTrace) |
| | 6690 | | { |
| 0 | 6691 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 6692 | | } |
| 0 | 6693 | | return _result; |
| 0 | 6694 | | } |
| | 6695 | |
|
| | 6696 | | /// <summary> |
| | 6697 | | /// Gets the number of images tagged with the provided {tagIds} that have |
| | 6698 | | /// prediction results from |
| | 6699 | | /// training for the provided iteration {iterationId}. |
| | 6700 | | /// </summary> |
| | 6701 | | /// <remarks> |
| | 6702 | | /// The filtering is on an and/or relationship. For example, if the provided |
| | 6703 | | /// tag ids are for the "Dog" and |
| | 6704 | | /// "Cat" tags, then only images tagged with Dog and/or Cat will be returned |
| | 6705 | | /// </remarks> |
| | 6706 | | /// <param name='projectId'> |
| | 6707 | | /// The project id. |
| | 6708 | | /// </param> |
| | 6709 | | /// <param name='iterationId'> |
| | 6710 | | /// The iteration id. Defaults to workspace. |
| | 6711 | | /// </param> |
| | 6712 | | /// <param name='tagIds'> |
| | 6713 | | /// A list of tags ids to filter the images to count. Defaults to all tags when |
| | 6714 | | /// null. |
| | 6715 | | /// </param> |
| | 6716 | | /// <param name='customHeaders'> |
| | 6717 | | /// Headers that will be added to request. |
| | 6718 | | /// </param> |
| | 6719 | | /// <param name='cancellationToken'> |
| | 6720 | | /// The cancellation token. |
| | 6721 | | /// </param> |
| | 6722 | | /// <exception cref="CustomVisionErrorException"> |
| | 6723 | | /// Thrown when the operation returned an invalid status code |
| | 6724 | | /// </exception> |
| | 6725 | | /// <exception cref="SerializationException"> |
| | 6726 | | /// Thrown when unable to deserialize the response |
| | 6727 | | /// </exception> |
| | 6728 | | /// <exception cref="ValidationException"> |
| | 6729 | | /// Thrown when a required parameter is null |
| | 6730 | | /// </exception> |
| | 6731 | | /// <exception cref="System.ArgumentNullException"> |
| | 6732 | | /// Thrown when a required parameter is null |
| | 6733 | | /// </exception> |
| | 6734 | | /// <return> |
| | 6735 | | /// A response object containing the response body and response headers. |
| | 6736 | | /// </return> |
| | 6737 | | public async Task<HttpOperationResponse<int?>> GetImagePerformanceCountWithHttpMessagesAsync(System.Guid project |
| | 6738 | | { |
| 2 | 6739 | | if (Endpoint == null) |
| | 6740 | | { |
| 0 | 6741 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 6742 | | } |
| | 6743 | | // Tracing |
| 2 | 6744 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 6745 | | string _invocationId = null; |
| 2 | 6746 | | if (_shouldTrace) |
| | 6747 | | { |
| 0 | 6748 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 6749 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 6750 | | tracingParameters.Add("projectId", projectId); |
| 0 | 6751 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 6752 | | tracingParameters.Add("tagIds", tagIds); |
| 0 | 6753 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 6754 | | ServiceClientTracing.Enter(_invocationId, this, "GetImagePerformanceCount", tracingParameters); |
| | 6755 | | } |
| | 6756 | | // Construct URL |
| 2 | 6757 | | var _baseUrl = BaseUri; |
| 2 | 6758 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/iterations/{iterationId}/p |
| 2 | 6759 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 6760 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 6761 | | _url = _url.Replace("{iterationId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(iterationId |
| 2 | 6762 | | List<string> _queryParameters = new List<string>(); |
| 2 | 6763 | | if (tagIds != null) |
| | 6764 | | { |
| 0 | 6765 | | _queryParameters.Add(string.Format("tagIds={0}", System.Uri.EscapeDataString(string.Join(",", tagIds)))) |
| | 6766 | | } |
| 2 | 6767 | | if (_queryParameters.Count > 0) |
| | 6768 | | { |
| 0 | 6769 | | _url += "?" + string.Join("&", _queryParameters); |
| | 6770 | | } |
| | 6771 | | // Create HTTP transport objects |
| 2 | 6772 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 6773 | | HttpResponseMessage _httpResponse = null; |
| 2 | 6774 | | _httpRequest.Method = new HttpMethod("GET"); |
| 2 | 6775 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 6776 | | // Set Headers |
| | 6777 | |
|
| | 6778 | |
|
| 2 | 6779 | | if (customHeaders != null) |
| | 6780 | | { |
| 0 | 6781 | | foreach(var _header in customHeaders) |
| | 6782 | | { |
| 0 | 6783 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 6784 | | { |
| 0 | 6785 | | _httpRequest.Headers.Remove(_header.Key); |
| | 6786 | | } |
| 0 | 6787 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 6788 | | } |
| | 6789 | | } |
| | 6790 | |
|
| | 6791 | | // Serialize Request |
| 2 | 6792 | | string _requestContent = null; |
| | 6793 | | // Set Credentials |
| 2 | 6794 | | if (Credentials != null) |
| | 6795 | | { |
| 2 | 6796 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 6797 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 6798 | | } |
| | 6799 | | // Send Request |
| 2 | 6800 | | if (_shouldTrace) |
| | 6801 | | { |
| 0 | 6802 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 6803 | | } |
| 2 | 6804 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 6805 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 6806 | | if (_shouldTrace) |
| | 6807 | | { |
| 0 | 6808 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 6809 | | } |
| 2 | 6810 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 6811 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 6812 | | string _responseContent = null; |
| 2 | 6813 | | if ((int)_statusCode != 200) |
| | 6814 | | { |
| 0 | 6815 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 6816 | | try |
| | 6817 | | { |
| 0 | 6818 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 6819 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 6820 | | if (_errorBody != null) |
| | 6821 | | { |
| 0 | 6822 | | ex.Body = _errorBody; |
| | 6823 | | } |
| 0 | 6824 | | } |
| 0 | 6825 | | catch (JsonException) |
| | 6826 | | { |
| | 6827 | | // Ignore the exception |
| 0 | 6828 | | } |
| 0 | 6829 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 6830 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 6831 | | if (_shouldTrace) |
| | 6832 | | { |
| 0 | 6833 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 6834 | | } |
| 0 | 6835 | | _httpRequest.Dispose(); |
| 0 | 6836 | | if (_httpResponse != null) |
| | 6837 | | { |
| 0 | 6838 | | _httpResponse.Dispose(); |
| | 6839 | | } |
| 0 | 6840 | | throw ex; |
| | 6841 | | } |
| | 6842 | | // Create Result |
| 2 | 6843 | | var _result = new HttpOperationResponse<int?>(); |
| 2 | 6844 | | _result.Request = _httpRequest; |
| 2 | 6845 | | _result.Response = _httpResponse; |
| | 6846 | | // Deserialize Response |
| 2 | 6847 | | if ((int)_statusCode == 200) |
| | 6848 | | { |
| 2 | 6849 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 6850 | | try |
| | 6851 | | { |
| 2 | 6852 | | _result.Body = SafeJsonConvert.DeserializeObject<int?>(_responseContent, DeserializationSettings); |
| 2 | 6853 | | } |
| 0 | 6854 | | catch (JsonException ex) |
| | 6855 | | { |
| 0 | 6856 | | _httpRequest.Dispose(); |
| 0 | 6857 | | if (_httpResponse != null) |
| | 6858 | | { |
| 0 | 6859 | | _httpResponse.Dispose(); |
| | 6860 | | } |
| 0 | 6861 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 6862 | | } |
| | 6863 | | } |
| 2 | 6864 | | if (_shouldTrace) |
| | 6865 | | { |
| 0 | 6866 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 6867 | | } |
| 2 | 6868 | | return _result; |
| 2 | 6869 | | } |
| | 6870 | |
|
| | 6871 | | /// <summary> |
| | 6872 | | /// Publish a specific iteration. |
| | 6873 | | /// </summary> |
| | 6874 | | /// <param name='projectId'> |
| | 6875 | | /// The project id. |
| | 6876 | | /// </param> |
| | 6877 | | /// <param name='iterationId'> |
| | 6878 | | /// The iteration id. |
| | 6879 | | /// </param> |
| | 6880 | | /// <param name='publishName'> |
| | 6881 | | /// The name to give the published iteration. |
| | 6882 | | /// </param> |
| | 6883 | | /// <param name='predictionId'> |
| | 6884 | | /// The id of the prediction resource to publish to. |
| | 6885 | | /// </param> |
| | 6886 | | /// <param name='overwrite'> |
| | 6887 | | /// Whether to overwrite the published model with the given name (default: |
| | 6888 | | /// false). |
| | 6889 | | /// </param> |
| | 6890 | | /// <param name='customHeaders'> |
| | 6891 | | /// Headers that will be added to request. |
| | 6892 | | /// </param> |
| | 6893 | | /// <param name='cancellationToken'> |
| | 6894 | | /// The cancellation token. |
| | 6895 | | /// </param> |
| | 6896 | | /// <exception cref="CustomVisionErrorException"> |
| | 6897 | | /// Thrown when the operation returned an invalid status code |
| | 6898 | | /// </exception> |
| | 6899 | | /// <exception cref="SerializationException"> |
| | 6900 | | /// Thrown when unable to deserialize the response |
| | 6901 | | /// </exception> |
| | 6902 | | /// <exception cref="ValidationException"> |
| | 6903 | | /// Thrown when a required parameter is null |
| | 6904 | | /// </exception> |
| | 6905 | | /// <exception cref="System.ArgumentNullException"> |
| | 6906 | | /// Thrown when a required parameter is null |
| | 6907 | | /// </exception> |
| | 6908 | | /// <return> |
| | 6909 | | /// A response object containing the response body and response headers. |
| | 6910 | | /// </return> |
| | 6911 | | public async Task<HttpOperationResponse<bool?>> PublishIterationWithHttpMessagesAsync(System.Guid projectId, Sys |
| | 6912 | | { |
| 2 | 6913 | | if (Endpoint == null) |
| | 6914 | | { |
| 0 | 6915 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 6916 | | } |
| 2 | 6917 | | if (publishName == null) |
| | 6918 | | { |
| 0 | 6919 | | throw new ValidationException(ValidationRules.CannotBeNull, "publishName"); |
| | 6920 | | } |
| 2 | 6921 | | if (predictionId == null) |
| | 6922 | | { |
| 0 | 6923 | | throw new ValidationException(ValidationRules.CannotBeNull, "predictionId"); |
| | 6924 | | } |
| | 6925 | | // Tracing |
| 2 | 6926 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 6927 | | string _invocationId = null; |
| 2 | 6928 | | if (_shouldTrace) |
| | 6929 | | { |
| 0 | 6930 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 6931 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 6932 | | tracingParameters.Add("projectId", projectId); |
| 0 | 6933 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 6934 | | tracingParameters.Add("publishName", publishName); |
| 0 | 6935 | | tracingParameters.Add("predictionId", predictionId); |
| 0 | 6936 | | tracingParameters.Add("overwrite", overwrite); |
| 0 | 6937 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 6938 | | ServiceClientTracing.Enter(_invocationId, this, "PublishIteration", tracingParameters); |
| | 6939 | | } |
| | 6940 | | // Construct URL |
| 2 | 6941 | | var _baseUrl = BaseUri; |
| 2 | 6942 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/iterations/{iterationId}/p |
| 2 | 6943 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 6944 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 6945 | | _url = _url.Replace("{iterationId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(iterationId |
| 2 | 6946 | | List<string> _queryParameters = new List<string>(); |
| 2 | 6947 | | if (publishName != null) |
| | 6948 | | { |
| 2 | 6949 | | _queryParameters.Add(string.Format("publishName={0}", System.Uri.EscapeDataString(publishName))); |
| | 6950 | | } |
| 2 | 6951 | | if (predictionId != null) |
| | 6952 | | { |
| 2 | 6953 | | _queryParameters.Add(string.Format("predictionId={0}", System.Uri.EscapeDataString(predictionId))); |
| | 6954 | | } |
| 2 | 6955 | | if (overwrite != null) |
| | 6956 | | { |
| 0 | 6957 | | _queryParameters.Add(string.Format("overwrite={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serializ |
| | 6958 | | } |
| 2 | 6959 | | if (_queryParameters.Count > 0) |
| | 6960 | | { |
| 2 | 6961 | | _url += "?" + string.Join("&", _queryParameters); |
| | 6962 | | } |
| | 6963 | | // Create HTTP transport objects |
| 2 | 6964 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 6965 | | HttpResponseMessage _httpResponse = null; |
| 2 | 6966 | | _httpRequest.Method = new HttpMethod("POST"); |
| 2 | 6967 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 6968 | | // Set Headers |
| | 6969 | |
|
| | 6970 | |
|
| 2 | 6971 | | if (customHeaders != null) |
| | 6972 | | { |
| 0 | 6973 | | foreach(var _header in customHeaders) |
| | 6974 | | { |
| 0 | 6975 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 6976 | | { |
| 0 | 6977 | | _httpRequest.Headers.Remove(_header.Key); |
| | 6978 | | } |
| 0 | 6979 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 6980 | | } |
| | 6981 | | } |
| | 6982 | |
|
| | 6983 | | // Serialize Request |
| 2 | 6984 | | string _requestContent = null; |
| | 6985 | | // Set Credentials |
| 2 | 6986 | | if (Credentials != null) |
| | 6987 | | { |
| 2 | 6988 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 6989 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 6990 | | } |
| | 6991 | | // Send Request |
| 2 | 6992 | | if (_shouldTrace) |
| | 6993 | | { |
| 0 | 6994 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 6995 | | } |
| 2 | 6996 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 6997 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 6998 | | if (_shouldTrace) |
| | 6999 | | { |
| 0 | 7000 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 7001 | | } |
| 2 | 7002 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 7003 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 7004 | | string _responseContent = null; |
| 2 | 7005 | | if ((int)_statusCode != 200) |
| | 7006 | | { |
| 0 | 7007 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 7008 | | try |
| | 7009 | | { |
| 0 | 7010 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 7011 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 7012 | | if (_errorBody != null) |
| | 7013 | | { |
| 0 | 7014 | | ex.Body = _errorBody; |
| | 7015 | | } |
| 0 | 7016 | | } |
| 0 | 7017 | | catch (JsonException) |
| | 7018 | | { |
| | 7019 | | // Ignore the exception |
| 0 | 7020 | | } |
| 0 | 7021 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 7022 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 7023 | | if (_shouldTrace) |
| | 7024 | | { |
| 0 | 7025 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 7026 | | } |
| 0 | 7027 | | _httpRequest.Dispose(); |
| 0 | 7028 | | if (_httpResponse != null) |
| | 7029 | | { |
| 0 | 7030 | | _httpResponse.Dispose(); |
| | 7031 | | } |
| 0 | 7032 | | throw ex; |
| | 7033 | | } |
| | 7034 | | // Create Result |
| 2 | 7035 | | var _result = new HttpOperationResponse<bool?>(); |
| 2 | 7036 | | _result.Request = _httpRequest; |
| 2 | 7037 | | _result.Response = _httpResponse; |
| | 7038 | | // Deserialize Response |
| 2 | 7039 | | if ((int)_statusCode == 200) |
| | 7040 | | { |
| 2 | 7041 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 7042 | | try |
| | 7043 | | { |
| 2 | 7044 | | _result.Body = SafeJsonConvert.DeserializeObject<bool?>(_responseContent, DeserializationSettings); |
| 2 | 7045 | | } |
| 0 | 7046 | | catch (JsonException ex) |
| | 7047 | | { |
| 0 | 7048 | | _httpRequest.Dispose(); |
| 0 | 7049 | | if (_httpResponse != null) |
| | 7050 | | { |
| 0 | 7051 | | _httpResponse.Dispose(); |
| | 7052 | | } |
| 0 | 7053 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 7054 | | } |
| | 7055 | | } |
| 2 | 7056 | | if (_shouldTrace) |
| | 7057 | | { |
| 0 | 7058 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 7059 | | } |
| 2 | 7060 | | return _result; |
| 2 | 7061 | | } |
| | 7062 | |
|
| | 7063 | | /// <summary> |
| | 7064 | | /// Unpublish a specific iteration. |
| | 7065 | | /// </summary> |
| | 7066 | | /// <param name='projectId'> |
| | 7067 | | /// The project id. |
| | 7068 | | /// </param> |
| | 7069 | | /// <param name='iterationId'> |
| | 7070 | | /// The iteration id. |
| | 7071 | | /// </param> |
| | 7072 | | /// <param name='customHeaders'> |
| | 7073 | | /// Headers that will be added to request. |
| | 7074 | | /// </param> |
| | 7075 | | /// <param name='cancellationToken'> |
| | 7076 | | /// The cancellation token. |
| | 7077 | | /// </param> |
| | 7078 | | /// <exception cref="CustomVisionErrorException"> |
| | 7079 | | /// Thrown when the operation returned an invalid status code |
| | 7080 | | /// </exception> |
| | 7081 | | /// <exception cref="ValidationException"> |
| | 7082 | | /// Thrown when a required parameter is null |
| | 7083 | | /// </exception> |
| | 7084 | | /// <exception cref="System.ArgumentNullException"> |
| | 7085 | | /// Thrown when a required parameter is null |
| | 7086 | | /// </exception> |
| | 7087 | | /// <return> |
| | 7088 | | /// A response object containing the response body and response headers. |
| | 7089 | | /// </return> |
| | 7090 | | public async Task<HttpOperationResponse> UnpublishIterationWithHttpMessagesAsync(System.Guid projectId, System.G |
| | 7091 | | { |
| 2 | 7092 | | if (Endpoint == null) |
| | 7093 | | { |
| 0 | 7094 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 7095 | | } |
| | 7096 | | // Tracing |
| 2 | 7097 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 7098 | | string _invocationId = null; |
| 2 | 7099 | | if (_shouldTrace) |
| | 7100 | | { |
| 0 | 7101 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 7102 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 7103 | | tracingParameters.Add("projectId", projectId); |
| 0 | 7104 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 7105 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 7106 | | ServiceClientTracing.Enter(_invocationId, this, "UnpublishIteration", tracingParameters); |
| | 7107 | | } |
| | 7108 | | // Construct URL |
| 2 | 7109 | | var _baseUrl = BaseUri; |
| 2 | 7110 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/iterations/{iterationId}/p |
| 2 | 7111 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 7112 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 7113 | | _url = _url.Replace("{iterationId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(iterationId |
| | 7114 | | // Create HTTP transport objects |
| 2 | 7115 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 7116 | | HttpResponseMessage _httpResponse = null; |
| 2 | 7117 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 2 | 7118 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 7119 | | // Set Headers |
| | 7120 | |
|
| | 7121 | |
|
| 2 | 7122 | | if (customHeaders != null) |
| | 7123 | | { |
| 0 | 7124 | | foreach(var _header in customHeaders) |
| | 7125 | | { |
| 0 | 7126 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 7127 | | { |
| 0 | 7128 | | _httpRequest.Headers.Remove(_header.Key); |
| | 7129 | | } |
| 0 | 7130 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 7131 | | } |
| | 7132 | | } |
| | 7133 | |
|
| | 7134 | | // Serialize Request |
| 2 | 7135 | | string _requestContent = null; |
| | 7136 | | // Set Credentials |
| 2 | 7137 | | if (Credentials != null) |
| | 7138 | | { |
| 2 | 7139 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 7140 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 7141 | | } |
| | 7142 | | // Send Request |
| 2 | 7143 | | if (_shouldTrace) |
| | 7144 | | { |
| 0 | 7145 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 7146 | | } |
| 2 | 7147 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 7148 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 7149 | | if (_shouldTrace) |
| | 7150 | | { |
| 0 | 7151 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 7152 | | } |
| 2 | 7153 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 7154 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 7155 | | string _responseContent = null; |
| 2 | 7156 | | if ((int)_statusCode != 204) |
| | 7157 | | { |
| 0 | 7158 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 7159 | | try |
| | 7160 | | { |
| 0 | 7161 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 7162 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 7163 | | if (_errorBody != null) |
| | 7164 | | { |
| 0 | 7165 | | ex.Body = _errorBody; |
| | 7166 | | } |
| 0 | 7167 | | } |
| 0 | 7168 | | catch (JsonException) |
| | 7169 | | { |
| | 7170 | | // Ignore the exception |
| 0 | 7171 | | } |
| 0 | 7172 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 7173 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 7174 | | if (_shouldTrace) |
| | 7175 | | { |
| 0 | 7176 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 7177 | | } |
| 0 | 7178 | | _httpRequest.Dispose(); |
| 0 | 7179 | | if (_httpResponse != null) |
| | 7180 | | { |
| 0 | 7181 | | _httpResponse.Dispose(); |
| | 7182 | | } |
| 0 | 7183 | | throw ex; |
| | 7184 | | } |
| | 7185 | | // Create Result |
| 2 | 7186 | | var _result = new HttpOperationResponse(); |
| 2 | 7187 | | _result.Request = _httpRequest; |
| 2 | 7188 | | _result.Response = _httpResponse; |
| 2 | 7189 | | if (_shouldTrace) |
| | 7190 | | { |
| 0 | 7191 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 7192 | | } |
| 2 | 7193 | | return _result; |
| 2 | 7194 | | } |
| | 7195 | |
|
| | 7196 | | /// <summary> |
| | 7197 | | /// Delete a set of predicted images and their associated prediction results. |
| | 7198 | | /// </summary> |
| | 7199 | | /// <param name='projectId'> |
| | 7200 | | /// The project id. |
| | 7201 | | /// </param> |
| | 7202 | | /// <param name='ids'> |
| | 7203 | | /// The prediction ids. Limited to 64. |
| | 7204 | | /// </param> |
| | 7205 | | /// <param name='customHeaders'> |
| | 7206 | | /// Headers that will be added to request. |
| | 7207 | | /// </param> |
| | 7208 | | /// <param name='cancellationToken'> |
| | 7209 | | /// The cancellation token. |
| | 7210 | | /// </param> |
| | 7211 | | /// <exception cref="CustomVisionErrorException"> |
| | 7212 | | /// Thrown when the operation returned an invalid status code |
| | 7213 | | /// </exception> |
| | 7214 | | /// <exception cref="ValidationException"> |
| | 7215 | | /// Thrown when a required parameter is null |
| | 7216 | | /// </exception> |
| | 7217 | | /// <exception cref="System.ArgumentNullException"> |
| | 7218 | | /// Thrown when a required parameter is null |
| | 7219 | | /// </exception> |
| | 7220 | | /// <return> |
| | 7221 | | /// A response object containing the response body and response headers. |
| | 7222 | | /// </return> |
| | 7223 | | public async Task<HttpOperationResponse> DeletePredictionWithHttpMessagesAsync(System.Guid projectId, IList<Syst |
| | 7224 | | { |
| 2 | 7225 | | if (Endpoint == null) |
| | 7226 | | { |
| 0 | 7227 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 7228 | | } |
| 2 | 7229 | | if (ids == null) |
| | 7230 | | { |
| 0 | 7231 | | throw new ValidationException(ValidationRules.CannotBeNull, "ids"); |
| | 7232 | | } |
| 2 | 7233 | | if (ids != null) |
| | 7234 | | { |
| 2 | 7235 | | if (ids.Count > 64) |
| | 7236 | | { |
| 0 | 7237 | | throw new ValidationException(ValidationRules.MaxItems, "ids", 64); |
| | 7238 | | } |
| 2 | 7239 | | if (ids.Count < 0) |
| | 7240 | | { |
| 0 | 7241 | | throw new ValidationException(ValidationRules.MinItems, "ids", 0); |
| | 7242 | | } |
| | 7243 | | } |
| | 7244 | | // Tracing |
| 2 | 7245 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 7246 | | string _invocationId = null; |
| 2 | 7247 | | if (_shouldTrace) |
| | 7248 | | { |
| 0 | 7249 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 7250 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 7251 | | tracingParameters.Add("projectId", projectId); |
| 0 | 7252 | | tracingParameters.Add("ids", ids); |
| 0 | 7253 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 7254 | | ServiceClientTracing.Enter(_invocationId, this, "DeletePrediction", tracingParameters); |
| | 7255 | | } |
| | 7256 | | // Construct URL |
| 2 | 7257 | | var _baseUrl = BaseUri; |
| 2 | 7258 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/predictions"; |
| 2 | 7259 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 7260 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 7261 | | List<string> _queryParameters = new List<string>(); |
| 2 | 7262 | | if (ids != null) |
| | 7263 | | { |
| 2 | 7264 | | _queryParameters.Add(string.Format("ids={0}", System.Uri.EscapeDataString(string.Join(",", ids)))); |
| | 7265 | | } |
| 2 | 7266 | | if (_queryParameters.Count > 0) |
| | 7267 | | { |
| 2 | 7268 | | _url += "?" + string.Join("&", _queryParameters); |
| | 7269 | | } |
| | 7270 | | // Create HTTP transport objects |
| 2 | 7271 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 7272 | | HttpResponseMessage _httpResponse = null; |
| 2 | 7273 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 2 | 7274 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 7275 | | // Set Headers |
| | 7276 | |
|
| | 7277 | |
|
| 2 | 7278 | | if (customHeaders != null) |
| | 7279 | | { |
| 0 | 7280 | | foreach(var _header in customHeaders) |
| | 7281 | | { |
| 0 | 7282 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 7283 | | { |
| 0 | 7284 | | _httpRequest.Headers.Remove(_header.Key); |
| | 7285 | | } |
| 0 | 7286 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 7287 | | } |
| | 7288 | | } |
| | 7289 | |
|
| | 7290 | | // Serialize Request |
| 2 | 7291 | | string _requestContent = null; |
| | 7292 | | // Set Credentials |
| 2 | 7293 | | if (Credentials != null) |
| | 7294 | | { |
| 2 | 7295 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 7296 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 7297 | | } |
| | 7298 | | // Send Request |
| 2 | 7299 | | if (_shouldTrace) |
| | 7300 | | { |
| 0 | 7301 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 7302 | | } |
| 2 | 7303 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 7304 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 7305 | | if (_shouldTrace) |
| | 7306 | | { |
| 0 | 7307 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 7308 | | } |
| 2 | 7309 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 7310 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 7311 | | string _responseContent = null; |
| 2 | 7312 | | if ((int)_statusCode != 204) |
| | 7313 | | { |
| 0 | 7314 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 7315 | | try |
| | 7316 | | { |
| 0 | 7317 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 7318 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 7319 | | if (_errorBody != null) |
| | 7320 | | { |
| 0 | 7321 | | ex.Body = _errorBody; |
| | 7322 | | } |
| 0 | 7323 | | } |
| 0 | 7324 | | catch (JsonException) |
| | 7325 | | { |
| | 7326 | | // Ignore the exception |
| 0 | 7327 | | } |
| 0 | 7328 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 7329 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 7330 | | if (_shouldTrace) |
| | 7331 | | { |
| 0 | 7332 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 7333 | | } |
| 0 | 7334 | | _httpRequest.Dispose(); |
| 0 | 7335 | | if (_httpResponse != null) |
| | 7336 | | { |
| 0 | 7337 | | _httpResponse.Dispose(); |
| | 7338 | | } |
| 0 | 7339 | | throw ex; |
| | 7340 | | } |
| | 7341 | | // Create Result |
| 2 | 7342 | | var _result = new HttpOperationResponse(); |
| 2 | 7343 | | _result.Request = _httpRequest; |
| 2 | 7344 | | _result.Response = _httpResponse; |
| 2 | 7345 | | if (_shouldTrace) |
| | 7346 | | { |
| 0 | 7347 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 7348 | | } |
| 2 | 7349 | | return _result; |
| 2 | 7350 | | } |
| | 7351 | |
|
| | 7352 | | /// <summary> |
| | 7353 | | /// Get images that were sent to your prediction endpoint. |
| | 7354 | | /// </summary> |
| | 7355 | | /// <param name='projectId'> |
| | 7356 | | /// The project id. |
| | 7357 | | /// </param> |
| | 7358 | | /// <param name='query'> |
| | 7359 | | /// Parameters used to query the predictions. Limited to combining 2 tags. |
| | 7360 | | /// </param> |
| | 7361 | | /// <param name='customHeaders'> |
| | 7362 | | /// Headers that will be added to request. |
| | 7363 | | /// </param> |
| | 7364 | | /// <param name='cancellationToken'> |
| | 7365 | | /// The cancellation token. |
| | 7366 | | /// </param> |
| | 7367 | | /// <exception cref="CustomVisionErrorException"> |
| | 7368 | | /// Thrown when the operation returned an invalid status code |
| | 7369 | | /// </exception> |
| | 7370 | | /// <exception cref="SerializationException"> |
| | 7371 | | /// Thrown when unable to deserialize the response |
| | 7372 | | /// </exception> |
| | 7373 | | /// <exception cref="ValidationException"> |
| | 7374 | | /// Thrown when a required parameter is null |
| | 7375 | | /// </exception> |
| | 7376 | | /// <exception cref="System.ArgumentNullException"> |
| | 7377 | | /// Thrown when a required parameter is null |
| | 7378 | | /// </exception> |
| | 7379 | | /// <return> |
| | 7380 | | /// A response object containing the response body and response headers. |
| | 7381 | | /// </return> |
| | 7382 | | public async Task<HttpOperationResponse<PredictionQueryResult>> QueryPredictionsWithHttpMessagesAsync(System.Gui |
| | 7383 | | { |
| 4 | 7384 | | if (Endpoint == null) |
| | 7385 | | { |
| 0 | 7386 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 7387 | | } |
| 4 | 7388 | | if (query == null) |
| | 7389 | | { |
| 0 | 7390 | | throw new ValidationException(ValidationRules.CannotBeNull, "query"); |
| | 7391 | | } |
| | 7392 | | // Tracing |
| 4 | 7393 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 7394 | | string _invocationId = null; |
| 4 | 7395 | | if (_shouldTrace) |
| | 7396 | | { |
| 0 | 7397 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 7398 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 7399 | | tracingParameters.Add("projectId", projectId); |
| 0 | 7400 | | tracingParameters.Add("query", query); |
| 0 | 7401 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 7402 | | ServiceClientTracing.Enter(_invocationId, this, "QueryPredictions", tracingParameters); |
| | 7403 | | } |
| | 7404 | | // Construct URL |
| 4 | 7405 | | var _baseUrl = BaseUri; |
| 4 | 7406 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/predictions/query"; |
| 4 | 7407 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 4 | 7408 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| | 7409 | | // Create HTTP transport objects |
| 4 | 7410 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 7411 | | HttpResponseMessage _httpResponse = null; |
| 4 | 7412 | | _httpRequest.Method = new HttpMethod("POST"); |
| 4 | 7413 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 7414 | | // Set Headers |
| | 7415 | |
|
| | 7416 | |
|
| 4 | 7417 | | if (customHeaders != null) |
| | 7418 | | { |
| 0 | 7419 | | foreach(var _header in customHeaders) |
| | 7420 | | { |
| 0 | 7421 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 7422 | | { |
| 0 | 7423 | | _httpRequest.Headers.Remove(_header.Key); |
| | 7424 | | } |
| 0 | 7425 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 7426 | | } |
| | 7427 | | } |
| | 7428 | |
|
| | 7429 | | // Serialize Request |
| 4 | 7430 | | string _requestContent = null; |
| 4 | 7431 | | if(query != null) |
| | 7432 | | { |
| 4 | 7433 | | _requestContent = SafeJsonConvert.SerializeObject(query, SerializationSettings); |
| 4 | 7434 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 4 | 7435 | | _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); |
| | 7436 | | } |
| | 7437 | | // Set Credentials |
| 4 | 7438 | | if (Credentials != null) |
| | 7439 | | { |
| 4 | 7440 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 7441 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 7442 | | } |
| | 7443 | | // Send Request |
| 4 | 7444 | | if (_shouldTrace) |
| | 7445 | | { |
| 0 | 7446 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 7447 | | } |
| 4 | 7448 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 7449 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 7450 | | if (_shouldTrace) |
| | 7451 | | { |
| 0 | 7452 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 7453 | | } |
| 4 | 7454 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 7455 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 7456 | | string _responseContent = null; |
| 4 | 7457 | | if ((int)_statusCode != 200) |
| | 7458 | | { |
| 0 | 7459 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 7460 | | try |
| | 7461 | | { |
| 0 | 7462 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 7463 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 7464 | | if (_errorBody != null) |
| | 7465 | | { |
| 0 | 7466 | | ex.Body = _errorBody; |
| | 7467 | | } |
| 0 | 7468 | | } |
| 0 | 7469 | | catch (JsonException) |
| | 7470 | | { |
| | 7471 | | // Ignore the exception |
| 0 | 7472 | | } |
| 0 | 7473 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 7474 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 7475 | | if (_shouldTrace) |
| | 7476 | | { |
| 0 | 7477 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 7478 | | } |
| 0 | 7479 | | _httpRequest.Dispose(); |
| 0 | 7480 | | if (_httpResponse != null) |
| | 7481 | | { |
| 0 | 7482 | | _httpResponse.Dispose(); |
| | 7483 | | } |
| 0 | 7484 | | throw ex; |
| | 7485 | | } |
| | 7486 | | // Create Result |
| 4 | 7487 | | var _result = new HttpOperationResponse<PredictionQueryResult>(); |
| 4 | 7488 | | _result.Request = _httpRequest; |
| 4 | 7489 | | _result.Response = _httpResponse; |
| | 7490 | | // Deserialize Response |
| 4 | 7491 | | if ((int)_statusCode == 200) |
| | 7492 | | { |
| 4 | 7493 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 7494 | | try |
| | 7495 | | { |
| 4 | 7496 | | _result.Body = SafeJsonConvert.DeserializeObject<PredictionQueryResult>(_responseContent, Deserializ |
| 4 | 7497 | | } |
| 0 | 7498 | | catch (JsonException ex) |
| | 7499 | | { |
| 0 | 7500 | | _httpRequest.Dispose(); |
| 0 | 7501 | | if (_httpResponse != null) |
| | 7502 | | { |
| 0 | 7503 | | _httpResponse.Dispose(); |
| | 7504 | | } |
| 0 | 7505 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 7506 | | } |
| | 7507 | | } |
| 4 | 7508 | | if (_shouldTrace) |
| | 7509 | | { |
| 0 | 7510 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 7511 | | } |
| 4 | 7512 | | return _result; |
| 4 | 7513 | | } |
| | 7514 | |
|
| | 7515 | | /// <summary> |
| | 7516 | | /// Quick test an image. |
| | 7517 | | /// </summary> |
| | 7518 | | /// <param name='projectId'> |
| | 7519 | | /// The project id. |
| | 7520 | | /// </param> |
| | 7521 | | /// <param name='imageData'> |
| | 7522 | | /// Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports |
| | 7523 | | /// images up to 6MB. |
| | 7524 | | /// </param> |
| | 7525 | | /// <param name='iterationId'> |
| | 7526 | | /// Optional. Specifies the id of a particular iteration to evaluate against. |
| | 7527 | | /// The default iteration for the project will be used when not specified. |
| | 7528 | | /// </param> |
| | 7529 | | /// <param name='store'> |
| | 7530 | | /// Optional. Specifies whether or not to store the result of this prediction. |
| | 7531 | | /// The default is true, to store. |
| | 7532 | | /// </param> |
| | 7533 | | /// <param name='customHeaders'> |
| | 7534 | | /// Headers that will be added to request. |
| | 7535 | | /// </param> |
| | 7536 | | /// <param name='cancellationToken'> |
| | 7537 | | /// The cancellation token. |
| | 7538 | | /// </param> |
| | 7539 | | /// <exception cref="CustomVisionErrorException"> |
| | 7540 | | /// Thrown when the operation returned an invalid status code |
| | 7541 | | /// </exception> |
| | 7542 | | /// <exception cref="SerializationException"> |
| | 7543 | | /// Thrown when unable to deserialize the response |
| | 7544 | | /// </exception> |
| | 7545 | | /// <exception cref="ValidationException"> |
| | 7546 | | /// Thrown when a required parameter is null |
| | 7547 | | /// </exception> |
| | 7548 | | /// <exception cref="System.ArgumentNullException"> |
| | 7549 | | /// Thrown when a required parameter is null |
| | 7550 | | /// </exception> |
| | 7551 | | /// <return> |
| | 7552 | | /// A response object containing the response body and response headers. |
| | 7553 | | /// </return> |
| | 7554 | | public async Task<HttpOperationResponse<ImagePrediction>> QuickTestImageWithHttpMessagesAsync(System.Guid projec |
| | 7555 | | { |
| | 7556 | | if (Endpoint == null) |
| | 7557 | | { |
| | 7558 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 7559 | | } |
| | 7560 | | if (imageData == null) |
| | 7561 | | { |
| | 7562 | | throw new ValidationException(ValidationRules.CannotBeNull, "imageData"); |
| | 7563 | | } |
| | 7564 | | // Tracing |
| | 7565 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| | 7566 | | string _invocationId = null; |
| | 7567 | | if (_shouldTrace) |
| | 7568 | | { |
| | 7569 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| | 7570 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| | 7571 | | tracingParameters.Add("projectId", projectId); |
| | 7572 | | tracingParameters.Add("iterationId", iterationId); |
| | 7573 | | tracingParameters.Add("store", store); |
| | 7574 | | tracingParameters.Add("imageData", imageData); |
| | 7575 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| | 7576 | | ServiceClientTracing.Enter(_invocationId, this, "QuickTestImage", tracingParameters); |
| | 7577 | | } |
| | 7578 | | // Construct URL |
| | 7579 | | var _baseUrl = BaseUri; |
| | 7580 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/quicktest/image"; |
| | 7581 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| | 7582 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| | 7583 | | List<string> _queryParameters = new List<string>(); |
| | 7584 | | if (iterationId != null) |
| | 7585 | | { |
| | 7586 | | _queryParameters.Add(string.Format("iterationId={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serial |
| | 7587 | | } |
| | 7588 | | if (store != null) |
| | 7589 | | { |
| | 7590 | | _queryParameters.Add(string.Format("store={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObj |
| | 7591 | | } |
| | 7592 | | if (_queryParameters.Count > 0) |
| | 7593 | | { |
| | 7594 | | _url += "?" + string.Join("&", _queryParameters); |
| | 7595 | | } |
| | 7596 | | // Create HTTP transport objects |
| | 7597 | | var _httpRequest = new HttpRequestMessage(); |
| | 7598 | | HttpResponseMessage _httpResponse = null; |
| | 7599 | | _httpRequest.Method = new HttpMethod("POST"); |
| | 7600 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 7601 | | // Set Headers |
| | 7602 | |
|
| | 7603 | |
|
| | 7604 | | if (customHeaders != null) |
| | 7605 | | { |
| | 7606 | | foreach(var _header in customHeaders) |
| | 7607 | | { |
| | 7608 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 7609 | | { |
| | 7610 | | _httpRequest.Headers.Remove(_header.Key); |
| | 7611 | | } |
| | 7612 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 7613 | | } |
| | 7614 | | } |
| | 7615 | |
|
| | 7616 | | // Serialize Request |
| | 7617 | | string _requestContent = null; |
| | 7618 | | MultipartFormDataContent _multiPartContent = new MultipartFormDataContent(); |
| | 7619 | | if (imageData != null) |
| | 7620 | | { |
| | 7621 | | StreamContent _imageData = new StreamContent(imageData); |
| | 7622 | | _imageData.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); |
| | 7623 | | ContentDispositionHeaderValue _contentDispositionHeaderValue = new ContentDispositionHeaderValue("form-d |
| | 7624 | | _contentDispositionHeaderValue.Name = "imageData"; |
| | 7625 | | // get filename from stream if it's a file otherwise, just use 'unknown' |
| | 7626 | | var _fileStream = imageData as FileStream; |
| | 7627 | | var _fileName = (_fileStream != null ? _fileStream.Name : null) ?? "unknown"; |
| 630 | 7628 | | if(System.Linq.Enumerable.Any(_fileName, c => c > 127) ) |
| | 7629 | | { |
| | 7630 | | // non ASCII chars detected, need UTF encoding: |
| | 7631 | | _contentDispositionHeaderValue.FileNameStar = _fileName; |
| | 7632 | | } |
| | 7633 | | else |
| | 7634 | | { |
| | 7635 | | // ASCII only |
| | 7636 | | _contentDispositionHeaderValue.FileName = _fileName; |
| | 7637 | | } |
| | 7638 | | _imageData.Headers.ContentDisposition = _contentDispositionHeaderValue; |
| | 7639 | | _multiPartContent.Add(_imageData, "imageData"); |
| | 7640 | | } |
| | 7641 | | _httpRequest.Content = _multiPartContent; |
| | 7642 | | // Set Credentials |
| | 7643 | | if (Credentials != null) |
| | 7644 | | { |
| | 7645 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 7646 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 7647 | | } |
| | 7648 | | // Send Request |
| | 7649 | | if (_shouldTrace) |
| | 7650 | | { |
| | 7651 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 7652 | | } |
| | 7653 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 7654 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 7655 | | if (_shouldTrace) |
| | 7656 | | { |
| | 7657 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 7658 | | } |
| | 7659 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| | 7660 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 7661 | | string _responseContent = null; |
| | 7662 | | if ((int)_statusCode != 200) |
| | 7663 | | { |
| | 7664 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 7665 | | try |
| | 7666 | | { |
| | 7667 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 7668 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| | 7669 | | if (_errorBody != null) |
| | 7670 | | { |
| | 7671 | | ex.Body = _errorBody; |
| | 7672 | | } |
| | 7673 | | } |
| | 7674 | | catch (JsonException) |
| | 7675 | | { |
| | 7676 | | // Ignore the exception |
| | 7677 | | } |
| | 7678 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| | 7679 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| | 7680 | | if (_shouldTrace) |
| | 7681 | | { |
| | 7682 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 7683 | | } |
| | 7684 | | _httpRequest.Dispose(); |
| | 7685 | | if (_httpResponse != null) |
| | 7686 | | { |
| | 7687 | | _httpResponse.Dispose(); |
| | 7688 | | } |
| | 7689 | | throw ex; |
| | 7690 | | } |
| | 7691 | | // Create Result |
| | 7692 | | var _result = new HttpOperationResponse<ImagePrediction>(); |
| | 7693 | | _result.Request = _httpRequest; |
| | 7694 | | _result.Response = _httpResponse; |
| | 7695 | | // Deserialize Response |
| | 7696 | | if ((int)_statusCode == 200) |
| | 7697 | | { |
| | 7698 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 7699 | | try |
| | 7700 | | { |
| | 7701 | | _result.Body = SafeJsonConvert.DeserializeObject<ImagePrediction>(_responseContent, DeserializationS |
| | 7702 | | } |
| | 7703 | | catch (JsonException ex) |
| | 7704 | | { |
| | 7705 | | _httpRequest.Dispose(); |
| | 7706 | | if (_httpResponse != null) |
| | 7707 | | { |
| | 7708 | | _httpResponse.Dispose(); |
| | 7709 | | } |
| | 7710 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 7711 | | } |
| | 7712 | | } |
| | 7713 | | if (_shouldTrace) |
| | 7714 | | { |
| | 7715 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 7716 | | } |
| | 7717 | | return _result; |
| | 7718 | | } |
| | 7719 | |
|
| | 7720 | | /// <summary> |
| | 7721 | | /// Quick test an image url. |
| | 7722 | | /// </summary> |
| | 7723 | | /// <param name='projectId'> |
| | 7724 | | /// The project to evaluate against. |
| | 7725 | | /// </param> |
| | 7726 | | /// <param name='imageUrl'> |
| | 7727 | | /// An ImageUrl that contains the url of the image to be evaluated. |
| | 7728 | | /// </param> |
| | 7729 | | /// <param name='iterationId'> |
| | 7730 | | /// Optional. Specifies the id of a particular iteration to evaluate against. |
| | 7731 | | /// The default iteration for the project will be used when not specified. |
| | 7732 | | /// </param> |
| | 7733 | | /// <param name='store'> |
| | 7734 | | /// Optional. Specifies whether or not to store the result of this prediction. |
| | 7735 | | /// The default is true, to store. |
| | 7736 | | /// </param> |
| | 7737 | | /// <param name='customHeaders'> |
| | 7738 | | /// Headers that will be added to request. |
| | 7739 | | /// </param> |
| | 7740 | | /// <param name='cancellationToken'> |
| | 7741 | | /// The cancellation token. |
| | 7742 | | /// </param> |
| | 7743 | | /// <exception cref="CustomVisionErrorException"> |
| | 7744 | | /// Thrown when the operation returned an invalid status code |
| | 7745 | | /// </exception> |
| | 7746 | | /// <exception cref="SerializationException"> |
| | 7747 | | /// Thrown when unable to deserialize the response |
| | 7748 | | /// </exception> |
| | 7749 | | /// <exception cref="ValidationException"> |
| | 7750 | | /// Thrown when a required parameter is null |
| | 7751 | | /// </exception> |
| | 7752 | | /// <exception cref="System.ArgumentNullException"> |
| | 7753 | | /// Thrown when a required parameter is null |
| | 7754 | | /// </exception> |
| | 7755 | | /// <return> |
| | 7756 | | /// A response object containing the response body and response headers. |
| | 7757 | | /// </return> |
| | 7758 | | public async Task<HttpOperationResponse<ImagePrediction>> QuickTestImageUrlWithHttpMessagesAsync(System.Guid pro |
| | 7759 | | { |
| 4 | 7760 | | if (Endpoint == null) |
| | 7761 | | { |
| 0 | 7762 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 7763 | | } |
| 4 | 7764 | | if (imageUrl == null) |
| | 7765 | | { |
| 0 | 7766 | | throw new ValidationException(ValidationRules.CannotBeNull, "imageUrl"); |
| | 7767 | | } |
| 4 | 7768 | | if (imageUrl != null) |
| | 7769 | | { |
| 4 | 7770 | | imageUrl.Validate(); |
| | 7771 | | } |
| | 7772 | | // Tracing |
| 4 | 7773 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 7774 | | string _invocationId = null; |
| 4 | 7775 | | if (_shouldTrace) |
| | 7776 | | { |
| 0 | 7777 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 7778 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 7779 | | tracingParameters.Add("projectId", projectId); |
| 0 | 7780 | | tracingParameters.Add("imageUrl", imageUrl); |
| 0 | 7781 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 7782 | | tracingParameters.Add("store", store); |
| 0 | 7783 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 7784 | | ServiceClientTracing.Enter(_invocationId, this, "QuickTestImageUrl", tracingParameters); |
| | 7785 | | } |
| | 7786 | | // Construct URL |
| 4 | 7787 | | var _baseUrl = BaseUri; |
| 4 | 7788 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/quicktest/url"; |
| 4 | 7789 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 4 | 7790 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 4 | 7791 | | List<string> _queryParameters = new List<string>(); |
| 4 | 7792 | | if (iterationId != null) |
| | 7793 | | { |
| 4 | 7794 | | _queryParameters.Add(string.Format("iterationId={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serial |
| | 7795 | | } |
| 4 | 7796 | | if (store != null) |
| | 7797 | | { |
| 4 | 7798 | | _queryParameters.Add(string.Format("store={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObj |
| | 7799 | | } |
| 4 | 7800 | | if (_queryParameters.Count > 0) |
| | 7801 | | { |
| 4 | 7802 | | _url += "?" + string.Join("&", _queryParameters); |
| | 7803 | | } |
| | 7804 | | // Create HTTP transport objects |
| 4 | 7805 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 7806 | | HttpResponseMessage _httpResponse = null; |
| 4 | 7807 | | _httpRequest.Method = new HttpMethod("POST"); |
| 4 | 7808 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 7809 | | // Set Headers |
| | 7810 | |
|
| | 7811 | |
|
| 4 | 7812 | | if (customHeaders != null) |
| | 7813 | | { |
| 0 | 7814 | | foreach(var _header in customHeaders) |
| | 7815 | | { |
| 0 | 7816 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 7817 | | { |
| 0 | 7818 | | _httpRequest.Headers.Remove(_header.Key); |
| | 7819 | | } |
| 0 | 7820 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 7821 | | } |
| | 7822 | | } |
| | 7823 | |
|
| | 7824 | | // Serialize Request |
| 4 | 7825 | | string _requestContent = null; |
| 4 | 7826 | | if(imageUrl != null) |
| | 7827 | | { |
| 4 | 7828 | | _requestContent = SafeJsonConvert.SerializeObject(imageUrl, SerializationSettings); |
| 4 | 7829 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 4 | 7830 | | _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); |
| | 7831 | | } |
| | 7832 | | // Set Credentials |
| 4 | 7833 | | if (Credentials != null) |
| | 7834 | | { |
| 4 | 7835 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 7836 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 7837 | | } |
| | 7838 | | // Send Request |
| 4 | 7839 | | if (_shouldTrace) |
| | 7840 | | { |
| 0 | 7841 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 7842 | | } |
| 4 | 7843 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 7844 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 7845 | | if (_shouldTrace) |
| | 7846 | | { |
| 0 | 7847 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 7848 | | } |
| 4 | 7849 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 7850 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 7851 | | string _responseContent = null; |
| 4 | 7852 | | if ((int)_statusCode != 200) |
| | 7853 | | { |
| 0 | 7854 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 7855 | | try |
| | 7856 | | { |
| 0 | 7857 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 7858 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 7859 | | if (_errorBody != null) |
| | 7860 | | { |
| 0 | 7861 | | ex.Body = _errorBody; |
| | 7862 | | } |
| 0 | 7863 | | } |
| 0 | 7864 | | catch (JsonException) |
| | 7865 | | { |
| | 7866 | | // Ignore the exception |
| 0 | 7867 | | } |
| 0 | 7868 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 7869 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 7870 | | if (_shouldTrace) |
| | 7871 | | { |
| 0 | 7872 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 7873 | | } |
| 0 | 7874 | | _httpRequest.Dispose(); |
| 0 | 7875 | | if (_httpResponse != null) |
| | 7876 | | { |
| 0 | 7877 | | _httpResponse.Dispose(); |
| | 7878 | | } |
| 0 | 7879 | | throw ex; |
| | 7880 | | } |
| | 7881 | | // Create Result |
| 4 | 7882 | | var _result = new HttpOperationResponse<ImagePrediction>(); |
| 4 | 7883 | | _result.Request = _httpRequest; |
| 4 | 7884 | | _result.Response = _httpResponse; |
| | 7885 | | // Deserialize Response |
| 4 | 7886 | | if ((int)_statusCode == 200) |
| | 7887 | | { |
| 4 | 7888 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 7889 | | try |
| | 7890 | | { |
| 4 | 7891 | | _result.Body = SafeJsonConvert.DeserializeObject<ImagePrediction>(_responseContent, DeserializationS |
| 4 | 7892 | | } |
| 0 | 7893 | | catch (JsonException ex) |
| | 7894 | | { |
| 0 | 7895 | | _httpRequest.Dispose(); |
| 0 | 7896 | | if (_httpResponse != null) |
| | 7897 | | { |
| 0 | 7898 | | _httpResponse.Dispose(); |
| | 7899 | | } |
| 0 | 7900 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 7901 | | } |
| | 7902 | | } |
| 4 | 7903 | | if (_shouldTrace) |
| | 7904 | | { |
| 0 | 7905 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 7906 | | } |
| 4 | 7907 | | return _result; |
| 4 | 7908 | | } |
| | 7909 | |
|
| | 7910 | | /// <summary> |
| | 7911 | | /// Get the tags for a given project and iteration. |
| | 7912 | | /// </summary> |
| | 7913 | | /// <param name='projectId'> |
| | 7914 | | /// The project id. |
| | 7915 | | /// </param> |
| | 7916 | | /// <param name='iterationId'> |
| | 7917 | | /// The iteration id. Defaults to workspace. |
| | 7918 | | /// </param> |
| | 7919 | | /// <param name='customHeaders'> |
| | 7920 | | /// Headers that will be added to request. |
| | 7921 | | /// </param> |
| | 7922 | | /// <param name='cancellationToken'> |
| | 7923 | | /// The cancellation token. |
| | 7924 | | /// </param> |
| | 7925 | | /// <exception cref="CustomVisionErrorException"> |
| | 7926 | | /// Thrown when the operation returned an invalid status code |
| | 7927 | | /// </exception> |
| | 7928 | | /// <exception cref="SerializationException"> |
| | 7929 | | /// Thrown when unable to deserialize the response |
| | 7930 | | /// </exception> |
| | 7931 | | /// <exception cref="ValidationException"> |
| | 7932 | | /// Thrown when a required parameter is null |
| | 7933 | | /// </exception> |
| | 7934 | | /// <exception cref="System.ArgumentNullException"> |
| | 7935 | | /// Thrown when a required parameter is null |
| | 7936 | | /// </exception> |
| | 7937 | | /// <return> |
| | 7938 | | /// A response object containing the response body and response headers. |
| | 7939 | | /// </return> |
| | 7940 | | public async Task<HttpOperationResponse<IList<Tag>>> GetTagsWithHttpMessagesAsync(System.Guid projectId, System. |
| | 7941 | | { |
| 12 | 7942 | | if (Endpoint == null) |
| | 7943 | | { |
| 0 | 7944 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 7945 | | } |
| | 7946 | | // Tracing |
| 12 | 7947 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 12 | 7948 | | string _invocationId = null; |
| 12 | 7949 | | if (_shouldTrace) |
| | 7950 | | { |
| 0 | 7951 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 7952 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 7953 | | tracingParameters.Add("projectId", projectId); |
| 0 | 7954 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 7955 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 7956 | | ServiceClientTracing.Enter(_invocationId, this, "GetTags", tracingParameters); |
| | 7957 | | } |
| | 7958 | | // Construct URL |
| 12 | 7959 | | var _baseUrl = BaseUri; |
| 12 | 7960 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/tags"; |
| 12 | 7961 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 12 | 7962 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 12 | 7963 | | List<string> _queryParameters = new List<string>(); |
| 12 | 7964 | | if (iterationId != null) |
| | 7965 | | { |
| 4 | 7966 | | _queryParameters.Add(string.Format("iterationId={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serial |
| | 7967 | | } |
| 12 | 7968 | | if (_queryParameters.Count > 0) |
| | 7969 | | { |
| 4 | 7970 | | _url += "?" + string.Join("&", _queryParameters); |
| | 7971 | | } |
| | 7972 | | // Create HTTP transport objects |
| 12 | 7973 | | var _httpRequest = new HttpRequestMessage(); |
| 12 | 7974 | | HttpResponseMessage _httpResponse = null; |
| 12 | 7975 | | _httpRequest.Method = new HttpMethod("GET"); |
| 12 | 7976 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 7977 | | // Set Headers |
| | 7978 | |
|
| | 7979 | |
|
| 12 | 7980 | | if (customHeaders != null) |
| | 7981 | | { |
| 0 | 7982 | | foreach(var _header in customHeaders) |
| | 7983 | | { |
| 0 | 7984 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 7985 | | { |
| 0 | 7986 | | _httpRequest.Headers.Remove(_header.Key); |
| | 7987 | | } |
| 0 | 7988 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 7989 | | } |
| | 7990 | | } |
| | 7991 | |
|
| | 7992 | | // Serialize Request |
| 12 | 7993 | | string _requestContent = null; |
| | 7994 | | // Set Credentials |
| 12 | 7995 | | if (Credentials != null) |
| | 7996 | | { |
| 12 | 7997 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 7998 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 7999 | | } |
| | 8000 | | // Send Request |
| 12 | 8001 | | if (_shouldTrace) |
| | 8002 | | { |
| 0 | 8003 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 8004 | | } |
| 12 | 8005 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 8006 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 12 | 8007 | | if (_shouldTrace) |
| | 8008 | | { |
| 0 | 8009 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 8010 | | } |
| 12 | 8011 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 12 | 8012 | | cancellationToken.ThrowIfCancellationRequested(); |
| 12 | 8013 | | string _responseContent = null; |
| 12 | 8014 | | if ((int)_statusCode != 200) |
| | 8015 | | { |
| 0 | 8016 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 8017 | | try |
| | 8018 | | { |
| 0 | 8019 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 8020 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 8021 | | if (_errorBody != null) |
| | 8022 | | { |
| 0 | 8023 | | ex.Body = _errorBody; |
| | 8024 | | } |
| 0 | 8025 | | } |
| 0 | 8026 | | catch (JsonException) |
| | 8027 | | { |
| | 8028 | | // Ignore the exception |
| 0 | 8029 | | } |
| 0 | 8030 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 8031 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 8032 | | if (_shouldTrace) |
| | 8033 | | { |
| 0 | 8034 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 8035 | | } |
| 0 | 8036 | | _httpRequest.Dispose(); |
| 0 | 8037 | | if (_httpResponse != null) |
| | 8038 | | { |
| 0 | 8039 | | _httpResponse.Dispose(); |
| | 8040 | | } |
| 0 | 8041 | | throw ex; |
| | 8042 | | } |
| | 8043 | | // Create Result |
| 12 | 8044 | | var _result = new HttpOperationResponse<IList<Tag>>(); |
| 12 | 8045 | | _result.Request = _httpRequest; |
| 12 | 8046 | | _result.Response = _httpResponse; |
| | 8047 | | // Deserialize Response |
| 12 | 8048 | | if ((int)_statusCode == 200) |
| | 8049 | | { |
| 12 | 8050 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 8051 | | try |
| | 8052 | | { |
| 12 | 8053 | | _result.Body = SafeJsonConvert.DeserializeObject<IList<Tag>>(_responseContent, DeserializationSettin |
| 12 | 8054 | | } |
| 0 | 8055 | | catch (JsonException ex) |
| | 8056 | | { |
| 0 | 8057 | | _httpRequest.Dispose(); |
| 0 | 8058 | | if (_httpResponse != null) |
| | 8059 | | { |
| 0 | 8060 | | _httpResponse.Dispose(); |
| | 8061 | | } |
| 0 | 8062 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 8063 | | } |
| | 8064 | | } |
| 12 | 8065 | | if (_shouldTrace) |
| | 8066 | | { |
| 0 | 8067 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 8068 | | } |
| 12 | 8069 | | return _result; |
| 12 | 8070 | | } |
| | 8071 | |
|
| | 8072 | | /// <summary> |
| | 8073 | | /// Create a tag for the project. |
| | 8074 | | /// </summary> |
| | 8075 | | /// <param name='projectId'> |
| | 8076 | | /// The project id. |
| | 8077 | | /// </param> |
| | 8078 | | /// <param name='name'> |
| | 8079 | | /// The tag name. |
| | 8080 | | /// </param> |
| | 8081 | | /// <param name='description'> |
| | 8082 | | /// Optional description for the tag. |
| | 8083 | | /// </param> |
| | 8084 | | /// <param name='type'> |
| | 8085 | | /// Optional type for the tag. Possible values include: 'Regular', 'Negative', |
| | 8086 | | /// 'GeneralProduct' |
| | 8087 | | /// </param> |
| | 8088 | | /// <param name='customHeaders'> |
| | 8089 | | /// Headers that will be added to request. |
| | 8090 | | /// </param> |
| | 8091 | | /// <param name='cancellationToken'> |
| | 8092 | | /// The cancellation token. |
| | 8093 | | /// </param> |
| | 8094 | | /// <exception cref="CustomVisionErrorException"> |
| | 8095 | | /// Thrown when the operation returned an invalid status code |
| | 8096 | | /// </exception> |
| | 8097 | | /// <exception cref="SerializationException"> |
| | 8098 | | /// Thrown when unable to deserialize the response |
| | 8099 | | /// </exception> |
| | 8100 | | /// <exception cref="ValidationException"> |
| | 8101 | | /// Thrown when a required parameter is null |
| | 8102 | | /// </exception> |
| | 8103 | | /// <exception cref="System.ArgumentNullException"> |
| | 8104 | | /// Thrown when a required parameter is null |
| | 8105 | | /// </exception> |
| | 8106 | | /// <return> |
| | 8107 | | /// A response object containing the response body and response headers. |
| | 8108 | | /// </return> |
| | 8109 | | public async Task<HttpOperationResponse<Tag>> CreateTagWithHttpMessagesAsync(System.Guid projectId, string name, |
| | 8110 | | { |
| 18 | 8111 | | if (Endpoint == null) |
| | 8112 | | { |
| 0 | 8113 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 8114 | | } |
| 18 | 8115 | | if (name == null) |
| | 8116 | | { |
| 0 | 8117 | | throw new ValidationException(ValidationRules.CannotBeNull, "name"); |
| | 8118 | | } |
| | 8119 | | // Tracing |
| 18 | 8120 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 18 | 8121 | | string _invocationId = null; |
| 18 | 8122 | | if (_shouldTrace) |
| | 8123 | | { |
| 0 | 8124 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 8125 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 8126 | | tracingParameters.Add("projectId", projectId); |
| 0 | 8127 | | tracingParameters.Add("name", name); |
| 0 | 8128 | | tracingParameters.Add("description", description); |
| 0 | 8129 | | tracingParameters.Add("type", type); |
| 0 | 8130 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 8131 | | ServiceClientTracing.Enter(_invocationId, this, "CreateTag", tracingParameters); |
| | 8132 | | } |
| | 8133 | | // Construct URL |
| 18 | 8134 | | var _baseUrl = BaseUri; |
| 18 | 8135 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/tags"; |
| 18 | 8136 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 18 | 8137 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 18 | 8138 | | List<string> _queryParameters = new List<string>(); |
| 18 | 8139 | | if (name != null) |
| | 8140 | | { |
| 18 | 8141 | | _queryParameters.Add(string.Format("name={0}", System.Uri.EscapeDataString(name))); |
| | 8142 | | } |
| 18 | 8143 | | if (description != null) |
| | 8144 | | { |
| 10 | 8145 | | _queryParameters.Add(string.Format("description={0}", System.Uri.EscapeDataString(description))); |
| | 8146 | | } |
| 18 | 8147 | | if (type != null) |
| | 8148 | | { |
| 0 | 8149 | | _queryParameters.Add(string.Format("type={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObje |
| | 8150 | | } |
| 18 | 8151 | | if (_queryParameters.Count > 0) |
| | 8152 | | { |
| 18 | 8153 | | _url += "?" + string.Join("&", _queryParameters); |
| | 8154 | | } |
| | 8155 | | // Create HTTP transport objects |
| 18 | 8156 | | var _httpRequest = new HttpRequestMessage(); |
| 18 | 8157 | | HttpResponseMessage _httpResponse = null; |
| 18 | 8158 | | _httpRequest.Method = new HttpMethod("POST"); |
| 18 | 8159 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 8160 | | // Set Headers |
| | 8161 | |
|
| | 8162 | |
|
| 18 | 8163 | | if (customHeaders != null) |
| | 8164 | | { |
| 0 | 8165 | | foreach(var _header in customHeaders) |
| | 8166 | | { |
| 0 | 8167 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 8168 | | { |
| 0 | 8169 | | _httpRequest.Headers.Remove(_header.Key); |
| | 8170 | | } |
| 0 | 8171 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 8172 | | } |
| | 8173 | | } |
| | 8174 | |
|
| | 8175 | | // Serialize Request |
| 18 | 8176 | | string _requestContent = null; |
| | 8177 | | // Set Credentials |
| 18 | 8178 | | if (Credentials != null) |
| | 8179 | | { |
| 18 | 8180 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 8181 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 8182 | | } |
| | 8183 | | // Send Request |
| 18 | 8184 | | if (_shouldTrace) |
| | 8185 | | { |
| 0 | 8186 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 8187 | | } |
| 18 | 8188 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 8189 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 18 | 8190 | | if (_shouldTrace) |
| | 8191 | | { |
| 0 | 8192 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 8193 | | } |
| 18 | 8194 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 18 | 8195 | | cancellationToken.ThrowIfCancellationRequested(); |
| 18 | 8196 | | string _responseContent = null; |
| 18 | 8197 | | if ((int)_statusCode != 200) |
| | 8198 | | { |
| 0 | 8199 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 8200 | | try |
| | 8201 | | { |
| 0 | 8202 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 8203 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 8204 | | if (_errorBody != null) |
| | 8205 | | { |
| 0 | 8206 | | ex.Body = _errorBody; |
| | 8207 | | } |
| 0 | 8208 | | } |
| 0 | 8209 | | catch (JsonException) |
| | 8210 | | { |
| | 8211 | | // Ignore the exception |
| 0 | 8212 | | } |
| 0 | 8213 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 8214 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 8215 | | if (_shouldTrace) |
| | 8216 | | { |
| 0 | 8217 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 8218 | | } |
| 0 | 8219 | | _httpRequest.Dispose(); |
| 0 | 8220 | | if (_httpResponse != null) |
| | 8221 | | { |
| 0 | 8222 | | _httpResponse.Dispose(); |
| | 8223 | | } |
| 0 | 8224 | | throw ex; |
| | 8225 | | } |
| | 8226 | | // Create Result |
| 18 | 8227 | | var _result = new HttpOperationResponse<Tag>(); |
| 18 | 8228 | | _result.Request = _httpRequest; |
| 18 | 8229 | | _result.Response = _httpResponse; |
| | 8230 | | // Deserialize Response |
| 18 | 8231 | | if ((int)_statusCode == 200) |
| | 8232 | | { |
| 18 | 8233 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 8234 | | try |
| | 8235 | | { |
| 18 | 8236 | | _result.Body = SafeJsonConvert.DeserializeObject<Tag>(_responseContent, DeserializationSettings); |
| 18 | 8237 | | } |
| 0 | 8238 | | catch (JsonException ex) |
| | 8239 | | { |
| 0 | 8240 | | _httpRequest.Dispose(); |
| 0 | 8241 | | if (_httpResponse != null) |
| | 8242 | | { |
| 0 | 8243 | | _httpResponse.Dispose(); |
| | 8244 | | } |
| 0 | 8245 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 8246 | | } |
| | 8247 | | } |
| 18 | 8248 | | if (_shouldTrace) |
| | 8249 | | { |
| 0 | 8250 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 8251 | | } |
| 18 | 8252 | | return _result; |
| 18 | 8253 | | } |
| | 8254 | |
|
| | 8255 | | /// <summary> |
| | 8256 | | /// Get information about a specific tag. |
| | 8257 | | /// </summary> |
| | 8258 | | /// <param name='projectId'> |
| | 8259 | | /// The project this tag belongs to. |
| | 8260 | | /// </param> |
| | 8261 | | /// <param name='tagId'> |
| | 8262 | | /// The tag id. |
| | 8263 | | /// </param> |
| | 8264 | | /// <param name='iterationId'> |
| | 8265 | | /// The iteration to retrieve this tag from. Optional, defaults to current |
| | 8266 | | /// training set. |
| | 8267 | | /// </param> |
| | 8268 | | /// <param name='customHeaders'> |
| | 8269 | | /// Headers that will be added to request. |
| | 8270 | | /// </param> |
| | 8271 | | /// <param name='cancellationToken'> |
| | 8272 | | /// The cancellation token. |
| | 8273 | | /// </param> |
| | 8274 | | /// <exception cref="CustomVisionErrorException"> |
| | 8275 | | /// Thrown when the operation returned an invalid status code |
| | 8276 | | /// </exception> |
| | 8277 | | /// <exception cref="SerializationException"> |
| | 8278 | | /// Thrown when unable to deserialize the response |
| | 8279 | | /// </exception> |
| | 8280 | | /// <exception cref="ValidationException"> |
| | 8281 | | /// Thrown when a required parameter is null |
| | 8282 | | /// </exception> |
| | 8283 | | /// <exception cref="System.ArgumentNullException"> |
| | 8284 | | /// Thrown when a required parameter is null |
| | 8285 | | /// </exception> |
| | 8286 | | /// <return> |
| | 8287 | | /// A response object containing the response body and response headers. |
| | 8288 | | /// </return> |
| | 8289 | | public async Task<HttpOperationResponse<Tag>> GetTagWithHttpMessagesAsync(System.Guid projectId, System.Guid tag |
| | 8290 | | { |
| 4 | 8291 | | if (Endpoint == null) |
| | 8292 | | { |
| 0 | 8293 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 8294 | | } |
| | 8295 | | // Tracing |
| 4 | 8296 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 8297 | | string _invocationId = null; |
| 4 | 8298 | | if (_shouldTrace) |
| | 8299 | | { |
| 0 | 8300 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 8301 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 8302 | | tracingParameters.Add("projectId", projectId); |
| 0 | 8303 | | tracingParameters.Add("tagId", tagId); |
| 0 | 8304 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 8305 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 8306 | | ServiceClientTracing.Enter(_invocationId, this, "GetTag", tracingParameters); |
| | 8307 | | } |
| | 8308 | | // Construct URL |
| 4 | 8309 | | var _baseUrl = BaseUri; |
| 4 | 8310 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/tags/{tagId}"; |
| 4 | 8311 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 4 | 8312 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 4 | 8313 | | _url = _url.Replace("{tagId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(tagId, Serializat |
| 4 | 8314 | | List<string> _queryParameters = new List<string>(); |
| 4 | 8315 | | if (iterationId != null) |
| | 8316 | | { |
| 4 | 8317 | | _queryParameters.Add(string.Format("iterationId={0}", System.Uri.EscapeDataString(SafeJsonConvert.Serial |
| | 8318 | | } |
| 4 | 8319 | | if (_queryParameters.Count > 0) |
| | 8320 | | { |
| 4 | 8321 | | _url += "?" + string.Join("&", _queryParameters); |
| | 8322 | | } |
| | 8323 | | // Create HTTP transport objects |
| 4 | 8324 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 8325 | | HttpResponseMessage _httpResponse = null; |
| 4 | 8326 | | _httpRequest.Method = new HttpMethod("GET"); |
| 4 | 8327 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 8328 | | // Set Headers |
| | 8329 | |
|
| | 8330 | |
|
| 4 | 8331 | | if (customHeaders != null) |
| | 8332 | | { |
| 0 | 8333 | | foreach(var _header in customHeaders) |
| | 8334 | | { |
| 0 | 8335 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 8336 | | { |
| 0 | 8337 | | _httpRequest.Headers.Remove(_header.Key); |
| | 8338 | | } |
| 0 | 8339 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 8340 | | } |
| | 8341 | | } |
| | 8342 | |
|
| | 8343 | | // Serialize Request |
| 4 | 8344 | | string _requestContent = null; |
| | 8345 | | // Set Credentials |
| 4 | 8346 | | if (Credentials != null) |
| | 8347 | | { |
| 4 | 8348 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 8349 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 8350 | | } |
| | 8351 | | // Send Request |
| 4 | 8352 | | if (_shouldTrace) |
| | 8353 | | { |
| 0 | 8354 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 8355 | | } |
| 4 | 8356 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 8357 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 8358 | | if (_shouldTrace) |
| | 8359 | | { |
| 0 | 8360 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 8361 | | } |
| 4 | 8362 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 8363 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 8364 | | string _responseContent = null; |
| 4 | 8365 | | if ((int)_statusCode != 200) |
| | 8366 | | { |
| 0 | 8367 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 8368 | | try |
| | 8369 | | { |
| 0 | 8370 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 8371 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 8372 | | if (_errorBody != null) |
| | 8373 | | { |
| 0 | 8374 | | ex.Body = _errorBody; |
| | 8375 | | } |
| 0 | 8376 | | } |
| 0 | 8377 | | catch (JsonException) |
| | 8378 | | { |
| | 8379 | | // Ignore the exception |
| 0 | 8380 | | } |
| 0 | 8381 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 8382 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 8383 | | if (_shouldTrace) |
| | 8384 | | { |
| 0 | 8385 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 8386 | | } |
| 0 | 8387 | | _httpRequest.Dispose(); |
| 0 | 8388 | | if (_httpResponse != null) |
| | 8389 | | { |
| 0 | 8390 | | _httpResponse.Dispose(); |
| | 8391 | | } |
| 0 | 8392 | | throw ex; |
| | 8393 | | } |
| | 8394 | | // Create Result |
| 4 | 8395 | | var _result = new HttpOperationResponse<Tag>(); |
| 4 | 8396 | | _result.Request = _httpRequest; |
| 4 | 8397 | | _result.Response = _httpResponse; |
| | 8398 | | // Deserialize Response |
| 4 | 8399 | | if ((int)_statusCode == 200) |
| | 8400 | | { |
| 4 | 8401 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 8402 | | try |
| | 8403 | | { |
| 4 | 8404 | | _result.Body = SafeJsonConvert.DeserializeObject<Tag>(_responseContent, DeserializationSettings); |
| 4 | 8405 | | } |
| 0 | 8406 | | catch (JsonException ex) |
| | 8407 | | { |
| 0 | 8408 | | _httpRequest.Dispose(); |
| 0 | 8409 | | if (_httpResponse != null) |
| | 8410 | | { |
| 0 | 8411 | | _httpResponse.Dispose(); |
| | 8412 | | } |
| 0 | 8413 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 8414 | | } |
| | 8415 | | } |
| 4 | 8416 | | if (_shouldTrace) |
| | 8417 | | { |
| 0 | 8418 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 8419 | | } |
| 4 | 8420 | | return _result; |
| 4 | 8421 | | } |
| | 8422 | |
|
| | 8423 | | /// <summary> |
| | 8424 | | /// Delete a tag from the project. |
| | 8425 | | /// </summary> |
| | 8426 | | /// <param name='projectId'> |
| | 8427 | | /// The project id. |
| | 8428 | | /// </param> |
| | 8429 | | /// <param name='tagId'> |
| | 8430 | | /// Id of the tag to be deleted. |
| | 8431 | | /// </param> |
| | 8432 | | /// <param name='customHeaders'> |
| | 8433 | | /// Headers that will be added to request. |
| | 8434 | | /// </param> |
| | 8435 | | /// <param name='cancellationToken'> |
| | 8436 | | /// The cancellation token. |
| | 8437 | | /// </param> |
| | 8438 | | /// <exception cref="CustomVisionErrorException"> |
| | 8439 | | /// Thrown when the operation returned an invalid status code |
| | 8440 | | /// </exception> |
| | 8441 | | /// <exception cref="ValidationException"> |
| | 8442 | | /// Thrown when a required parameter is null |
| | 8443 | | /// </exception> |
| | 8444 | | /// <exception cref="System.ArgumentNullException"> |
| | 8445 | | /// Thrown when a required parameter is null |
| | 8446 | | /// </exception> |
| | 8447 | | /// <return> |
| | 8448 | | /// A response object containing the response body and response headers. |
| | 8449 | | /// </return> |
| | 8450 | | public async Task<HttpOperationResponse> DeleteTagWithHttpMessagesAsync(System.Guid projectId, System.Guid tagId |
| | 8451 | | { |
| 4 | 8452 | | if (Endpoint == null) |
| | 8453 | | { |
| 0 | 8454 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 8455 | | } |
| | 8456 | | // Tracing |
| 4 | 8457 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 4 | 8458 | | string _invocationId = null; |
| 4 | 8459 | | if (_shouldTrace) |
| | 8460 | | { |
| 0 | 8461 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 8462 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 8463 | | tracingParameters.Add("projectId", projectId); |
| 0 | 8464 | | tracingParameters.Add("tagId", tagId); |
| 0 | 8465 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 8466 | | ServiceClientTracing.Enter(_invocationId, this, "DeleteTag", tracingParameters); |
| | 8467 | | } |
| | 8468 | | // Construct URL |
| 4 | 8469 | | var _baseUrl = BaseUri; |
| 4 | 8470 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/tags/{tagId}"; |
| 4 | 8471 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 4 | 8472 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 4 | 8473 | | _url = _url.Replace("{tagId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(tagId, Serializat |
| | 8474 | | // Create HTTP transport objects |
| 4 | 8475 | | var _httpRequest = new HttpRequestMessage(); |
| 4 | 8476 | | HttpResponseMessage _httpResponse = null; |
| 4 | 8477 | | _httpRequest.Method = new HttpMethod("DELETE"); |
| 4 | 8478 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 8479 | | // Set Headers |
| | 8480 | |
|
| | 8481 | |
|
| 4 | 8482 | | if (customHeaders != null) |
| | 8483 | | { |
| 0 | 8484 | | foreach(var _header in customHeaders) |
| | 8485 | | { |
| 0 | 8486 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 8487 | | { |
| 0 | 8488 | | _httpRequest.Headers.Remove(_header.Key); |
| | 8489 | | } |
| 0 | 8490 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 8491 | | } |
| | 8492 | | } |
| | 8493 | |
|
| | 8494 | | // Serialize Request |
| 4 | 8495 | | string _requestContent = null; |
| | 8496 | | // Set Credentials |
| 4 | 8497 | | if (Credentials != null) |
| | 8498 | | { |
| 4 | 8499 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 8500 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 8501 | | } |
| | 8502 | | // Send Request |
| 4 | 8503 | | if (_shouldTrace) |
| | 8504 | | { |
| 0 | 8505 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 8506 | | } |
| 4 | 8507 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 8508 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 4 | 8509 | | if (_shouldTrace) |
| | 8510 | | { |
| 0 | 8511 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 8512 | | } |
| 4 | 8513 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 4 | 8514 | | cancellationToken.ThrowIfCancellationRequested(); |
| 4 | 8515 | | string _responseContent = null; |
| 4 | 8516 | | if ((int)_statusCode != 204) |
| | 8517 | | { |
| 0 | 8518 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 8519 | | try |
| | 8520 | | { |
| 0 | 8521 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 8522 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 8523 | | if (_errorBody != null) |
| | 8524 | | { |
| 0 | 8525 | | ex.Body = _errorBody; |
| | 8526 | | } |
| 0 | 8527 | | } |
| 0 | 8528 | | catch (JsonException) |
| | 8529 | | { |
| | 8530 | | // Ignore the exception |
| 0 | 8531 | | } |
| 0 | 8532 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 8533 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 8534 | | if (_shouldTrace) |
| | 8535 | | { |
| 0 | 8536 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 8537 | | } |
| 0 | 8538 | | _httpRequest.Dispose(); |
| 0 | 8539 | | if (_httpResponse != null) |
| | 8540 | | { |
| 0 | 8541 | | _httpResponse.Dispose(); |
| | 8542 | | } |
| 0 | 8543 | | throw ex; |
| | 8544 | | } |
| | 8545 | | // Create Result |
| 4 | 8546 | | var _result = new HttpOperationResponse(); |
| 4 | 8547 | | _result.Request = _httpRequest; |
| 4 | 8548 | | _result.Response = _httpResponse; |
| 4 | 8549 | | if (_shouldTrace) |
| | 8550 | | { |
| 0 | 8551 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 8552 | | } |
| 4 | 8553 | | return _result; |
| 4 | 8554 | | } |
| | 8555 | |
|
| | 8556 | | /// <summary> |
| | 8557 | | /// Update a tag. |
| | 8558 | | /// </summary> |
| | 8559 | | /// <param name='projectId'> |
| | 8560 | | /// The project id. |
| | 8561 | | /// </param> |
| | 8562 | | /// <param name='tagId'> |
| | 8563 | | /// The id of the target tag. |
| | 8564 | | /// </param> |
| | 8565 | | /// <param name='updatedTag'> |
| | 8566 | | /// The updated tag model. |
| | 8567 | | /// </param> |
| | 8568 | | /// <param name='customHeaders'> |
| | 8569 | | /// Headers that will be added to request. |
| | 8570 | | /// </param> |
| | 8571 | | /// <param name='cancellationToken'> |
| | 8572 | | /// The cancellation token. |
| | 8573 | | /// </param> |
| | 8574 | | /// <exception cref="CustomVisionErrorException"> |
| | 8575 | | /// Thrown when the operation returned an invalid status code |
| | 8576 | | /// </exception> |
| | 8577 | | /// <exception cref="SerializationException"> |
| | 8578 | | /// Thrown when unable to deserialize the response |
| | 8579 | | /// </exception> |
| | 8580 | | /// <exception cref="ValidationException"> |
| | 8581 | | /// Thrown when a required parameter is null |
| | 8582 | | /// </exception> |
| | 8583 | | /// <exception cref="System.ArgumentNullException"> |
| | 8584 | | /// Thrown when a required parameter is null |
| | 8585 | | /// </exception> |
| | 8586 | | /// <return> |
| | 8587 | | /// A response object containing the response body and response headers. |
| | 8588 | | /// </return> |
| | 8589 | | public async Task<HttpOperationResponse<Tag>> UpdateTagWithHttpMessagesAsync(System.Guid projectId, System.Guid |
| | 8590 | | { |
| 2 | 8591 | | if (Endpoint == null) |
| | 8592 | | { |
| 0 | 8593 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 8594 | | } |
| 2 | 8595 | | if (updatedTag == null) |
| | 8596 | | { |
| 0 | 8597 | | throw new ValidationException(ValidationRules.CannotBeNull, "updatedTag"); |
| | 8598 | | } |
| | 8599 | | // Tracing |
| 2 | 8600 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 8601 | | string _invocationId = null; |
| 2 | 8602 | | if (_shouldTrace) |
| | 8603 | | { |
| 0 | 8604 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 8605 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 8606 | | tracingParameters.Add("projectId", projectId); |
| 0 | 8607 | | tracingParameters.Add("tagId", tagId); |
| 0 | 8608 | | tracingParameters.Add("updatedTag", updatedTag); |
| 0 | 8609 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 8610 | | ServiceClientTracing.Enter(_invocationId, this, "UpdateTag", tracingParameters); |
| | 8611 | | } |
| | 8612 | | // Construct URL |
| 2 | 8613 | | var _baseUrl = BaseUri; |
| 2 | 8614 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/tags/{tagId}"; |
| 2 | 8615 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 8616 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 8617 | | _url = _url.Replace("{tagId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(tagId, Serializat |
| | 8618 | | // Create HTTP transport objects |
| 2 | 8619 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 8620 | | HttpResponseMessage _httpResponse = null; |
| 2 | 8621 | | _httpRequest.Method = new HttpMethod("PATCH"); |
| 2 | 8622 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 8623 | | // Set Headers |
| | 8624 | |
|
| | 8625 | |
|
| 2 | 8626 | | if (customHeaders != null) |
| | 8627 | | { |
| 0 | 8628 | | foreach(var _header in customHeaders) |
| | 8629 | | { |
| 0 | 8630 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 8631 | | { |
| 0 | 8632 | | _httpRequest.Headers.Remove(_header.Key); |
| | 8633 | | } |
| 0 | 8634 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 8635 | | } |
| | 8636 | | } |
| | 8637 | |
|
| | 8638 | | // Serialize Request |
| 2 | 8639 | | string _requestContent = null; |
| 2 | 8640 | | if(updatedTag != null) |
| | 8641 | | { |
| 2 | 8642 | | _requestContent = SafeJsonConvert.SerializeObject(updatedTag, SerializationSettings); |
| 2 | 8643 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 2 | 8644 | | _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); |
| | 8645 | | } |
| | 8646 | | // Set Credentials |
| 2 | 8647 | | if (Credentials != null) |
| | 8648 | | { |
| 2 | 8649 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 8650 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 8651 | | } |
| | 8652 | | // Send Request |
| 2 | 8653 | | if (_shouldTrace) |
| | 8654 | | { |
| 0 | 8655 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 8656 | | } |
| 2 | 8657 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 8658 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 8659 | | if (_shouldTrace) |
| | 8660 | | { |
| 0 | 8661 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 8662 | | } |
| 2 | 8663 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 8664 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 8665 | | string _responseContent = null; |
| 2 | 8666 | | if ((int)_statusCode != 200) |
| | 8667 | | { |
| 0 | 8668 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 8669 | | try |
| | 8670 | | { |
| 0 | 8671 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 8672 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 8673 | | if (_errorBody != null) |
| | 8674 | | { |
| 0 | 8675 | | ex.Body = _errorBody; |
| | 8676 | | } |
| 0 | 8677 | | } |
| 0 | 8678 | | catch (JsonException) |
| | 8679 | | { |
| | 8680 | | // Ignore the exception |
| 0 | 8681 | | } |
| 0 | 8682 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 8683 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 8684 | | if (_shouldTrace) |
| | 8685 | | { |
| 0 | 8686 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 8687 | | } |
| 0 | 8688 | | _httpRequest.Dispose(); |
| 0 | 8689 | | if (_httpResponse != null) |
| | 8690 | | { |
| 0 | 8691 | | _httpResponse.Dispose(); |
| | 8692 | | } |
| 0 | 8693 | | throw ex; |
| | 8694 | | } |
| | 8695 | | // Create Result |
| 2 | 8696 | | var _result = new HttpOperationResponse<Tag>(); |
| 2 | 8697 | | _result.Request = _httpRequest; |
| 2 | 8698 | | _result.Response = _httpResponse; |
| | 8699 | | // Deserialize Response |
| 2 | 8700 | | if ((int)_statusCode == 200) |
| | 8701 | | { |
| 2 | 8702 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 8703 | | try |
| | 8704 | | { |
| 2 | 8705 | | _result.Body = SafeJsonConvert.DeserializeObject<Tag>(_responseContent, DeserializationSettings); |
| 2 | 8706 | | } |
| 0 | 8707 | | catch (JsonException ex) |
| | 8708 | | { |
| 0 | 8709 | | _httpRequest.Dispose(); |
| 0 | 8710 | | if (_httpResponse != null) |
| | 8711 | | { |
| 0 | 8712 | | _httpResponse.Dispose(); |
| | 8713 | | } |
| 0 | 8714 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 8715 | | } |
| | 8716 | | } |
| 2 | 8717 | | if (_shouldTrace) |
| | 8718 | | { |
| 0 | 8719 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 8720 | | } |
| 2 | 8721 | | return _result; |
| 2 | 8722 | | } |
| | 8723 | |
|
| | 8724 | | /// <summary> |
| | 8725 | | /// Suggest tags and regions for an array/batch of untagged images. Returns |
| | 8726 | | /// empty array if no tags are found. |
| | 8727 | | /// </summary> |
| | 8728 | | /// <remarks> |
| | 8729 | | /// This API will get suggested tags and regions for an array/batch of untagged |
| | 8730 | | /// images along with confidences for the tags. It returns an empty array if no |
| | 8731 | | /// tags are found. |
| | 8732 | | /// There is a limit of 64 images in the batch. |
| | 8733 | | /// </remarks> |
| | 8734 | | /// <param name='projectId'> |
| | 8735 | | /// The project id. |
| | 8736 | | /// </param> |
| | 8737 | | /// <param name='iterationId'> |
| | 8738 | | /// IterationId to use for tag and region suggestion. |
| | 8739 | | /// </param> |
| | 8740 | | /// <param name='imageIds'> |
| | 8741 | | /// Array of image ids tag suggestion are needed for. Use GetUntaggedImages API |
| | 8742 | | /// to get imageIds. |
| | 8743 | | /// </param> |
| | 8744 | | /// <param name='customHeaders'> |
| | 8745 | | /// Headers that will be added to request. |
| | 8746 | | /// </param> |
| | 8747 | | /// <param name='cancellationToken'> |
| | 8748 | | /// The cancellation token. |
| | 8749 | | /// </param> |
| | 8750 | | /// <exception cref="CustomVisionErrorException"> |
| | 8751 | | /// Thrown when the operation returned an invalid status code |
| | 8752 | | /// </exception> |
| | 8753 | | /// <exception cref="SerializationException"> |
| | 8754 | | /// Thrown when unable to deserialize the response |
| | 8755 | | /// </exception> |
| | 8756 | | /// <exception cref="ValidationException"> |
| | 8757 | | /// Thrown when a required parameter is null |
| | 8758 | | /// </exception> |
| | 8759 | | /// <exception cref="System.ArgumentNullException"> |
| | 8760 | | /// Thrown when a required parameter is null |
| | 8761 | | /// </exception> |
| | 8762 | | /// <return> |
| | 8763 | | /// A response object containing the response body and response headers. |
| | 8764 | | /// </return> |
| | 8765 | | public async Task<HttpOperationResponse<IList<SuggestedTagAndRegion>>> SuggestTagsAndRegionsWithHttpMessagesAsyn |
| | 8766 | | { |
| 6 | 8767 | | if (Endpoint == null) |
| | 8768 | | { |
| 0 | 8769 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 8770 | | } |
| 6 | 8771 | | if (imageIds == null) |
| | 8772 | | { |
| 0 | 8773 | | throw new ValidationException(ValidationRules.CannotBeNull, "imageIds"); |
| | 8774 | | } |
| 6 | 8775 | | if (imageIds != null) |
| | 8776 | | { |
| 6 | 8777 | | if (imageIds.Count > 64) |
| | 8778 | | { |
| 0 | 8779 | | throw new ValidationException(ValidationRules.MaxItems, "imageIds", 64); |
| | 8780 | | } |
| 6 | 8781 | | if (imageIds.Count < 0) |
| | 8782 | | { |
| 0 | 8783 | | throw new ValidationException(ValidationRules.MinItems, "imageIds", 0); |
| | 8784 | | } |
| | 8785 | | } |
| | 8786 | | // Tracing |
| 6 | 8787 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 6 | 8788 | | string _invocationId = null; |
| 6 | 8789 | | if (_shouldTrace) |
| | 8790 | | { |
| 0 | 8791 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 8792 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 8793 | | tracingParameters.Add("projectId", projectId); |
| 0 | 8794 | | tracingParameters.Add("iterationId", iterationId); |
| 0 | 8795 | | tracingParameters.Add("imageIds", imageIds); |
| 0 | 8796 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 8797 | | ServiceClientTracing.Enter(_invocationId, this, "SuggestTagsAndRegions", tracingParameters); |
| | 8798 | | } |
| | 8799 | | // Construct URL |
| 6 | 8800 | | var _baseUrl = BaseUri; |
| 6 | 8801 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/tagsandregions/suggestions |
| 6 | 8802 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 6 | 8803 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 6 | 8804 | | List<string> _queryParameters = new List<string>(); |
| 6 | 8805 | | _queryParameters.Add(string.Format("iterationId={0}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeO |
| 6 | 8806 | | if (imageIds != null) |
| | 8807 | | { |
| 6 | 8808 | | _queryParameters.Add(string.Format("imageIds={0}", System.Uri.EscapeDataString(string.Join(",", imageIds |
| | 8809 | | } |
| 6 | 8810 | | if (_queryParameters.Count > 0) |
| | 8811 | | { |
| 6 | 8812 | | _url += "?" + string.Join("&", _queryParameters); |
| | 8813 | | } |
| | 8814 | | // Create HTTP transport objects |
| 6 | 8815 | | var _httpRequest = new HttpRequestMessage(); |
| 6 | 8816 | | HttpResponseMessage _httpResponse = null; |
| 6 | 8817 | | _httpRequest.Method = new HttpMethod("POST"); |
| 6 | 8818 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 8819 | | // Set Headers |
| | 8820 | |
|
| | 8821 | |
|
| 6 | 8822 | | if (customHeaders != null) |
| | 8823 | | { |
| 0 | 8824 | | foreach(var _header in customHeaders) |
| | 8825 | | { |
| 0 | 8826 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 8827 | | { |
| 0 | 8828 | | _httpRequest.Headers.Remove(_header.Key); |
| | 8829 | | } |
| 0 | 8830 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 8831 | | } |
| | 8832 | | } |
| | 8833 | |
|
| | 8834 | | // Serialize Request |
| 6 | 8835 | | string _requestContent = null; |
| | 8836 | | // Set Credentials |
| 6 | 8837 | | if (Credentials != null) |
| | 8838 | | { |
| 6 | 8839 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 8840 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 8841 | | } |
| | 8842 | | // Send Request |
| 6 | 8843 | | if (_shouldTrace) |
| | 8844 | | { |
| 0 | 8845 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 8846 | | } |
| 6 | 8847 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 8848 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 6 | 8849 | | if (_shouldTrace) |
| | 8850 | | { |
| 0 | 8851 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 8852 | | } |
| 6 | 8853 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 6 | 8854 | | cancellationToken.ThrowIfCancellationRequested(); |
| 6 | 8855 | | string _responseContent = null; |
| 6 | 8856 | | if ((int)_statusCode != 200) |
| | 8857 | | { |
| 0 | 8858 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 8859 | | try |
| | 8860 | | { |
| 0 | 8861 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 8862 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 8863 | | if (_errorBody != null) |
| | 8864 | | { |
| 0 | 8865 | | ex.Body = _errorBody; |
| | 8866 | | } |
| 0 | 8867 | | } |
| 0 | 8868 | | catch (JsonException) |
| | 8869 | | { |
| | 8870 | | // Ignore the exception |
| 0 | 8871 | | } |
| 0 | 8872 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 8873 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 8874 | | if (_shouldTrace) |
| | 8875 | | { |
| 0 | 8876 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 8877 | | } |
| 0 | 8878 | | _httpRequest.Dispose(); |
| 0 | 8879 | | if (_httpResponse != null) |
| | 8880 | | { |
| 0 | 8881 | | _httpResponse.Dispose(); |
| | 8882 | | } |
| 0 | 8883 | | throw ex; |
| | 8884 | | } |
| | 8885 | | // Create Result |
| 6 | 8886 | | var _result = new HttpOperationResponse<IList<SuggestedTagAndRegion>>(); |
| 6 | 8887 | | _result.Request = _httpRequest; |
| 6 | 8888 | | _result.Response = _httpResponse; |
| | 8889 | | // Deserialize Response |
| 6 | 8890 | | if ((int)_statusCode == 200) |
| | 8891 | | { |
| 6 | 8892 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 8893 | | try |
| | 8894 | | { |
| 6 | 8895 | | _result.Body = SafeJsonConvert.DeserializeObject<IList<SuggestedTagAndRegion>>(_responseContent, Des |
| 6 | 8896 | | } |
| 0 | 8897 | | catch (JsonException ex) |
| | 8898 | | { |
| 0 | 8899 | | _httpRequest.Dispose(); |
| 0 | 8900 | | if (_httpResponse != null) |
| | 8901 | | { |
| 0 | 8902 | | _httpResponse.Dispose(); |
| | 8903 | | } |
| 0 | 8904 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 8905 | | } |
| | 8906 | | } |
| 6 | 8907 | | if (_shouldTrace) |
| | 8908 | | { |
| 0 | 8909 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 8910 | | } |
| 6 | 8911 | | return _result; |
| 6 | 8912 | | } |
| | 8913 | |
|
| | 8914 | | /// <summary> |
| | 8915 | | /// Queues project for training. |
| | 8916 | | /// </summary> |
| | 8917 | | /// <param name='projectId'> |
| | 8918 | | /// The project id. |
| | 8919 | | /// </param> |
| | 8920 | | /// <param name='trainingType'> |
| | 8921 | | /// The type of training to use to train the project (default: Regular). |
| | 8922 | | /// Possible values include: 'Regular', 'Advanced' |
| | 8923 | | /// </param> |
| | 8924 | | /// <param name='reservedBudgetInHours'> |
| | 8925 | | /// The number of hours reserved as budget for training (if applicable). |
| | 8926 | | /// </param> |
| | 8927 | | /// <param name='forceTrain'> |
| | 8928 | | /// Whether to force train even if dataset and configuration does not change |
| | 8929 | | /// (default: false). |
| | 8930 | | /// </param> |
| | 8931 | | /// <param name='notificationEmailAddress'> |
| | 8932 | | /// The email address to send notification to when training finishes (default: |
| | 8933 | | /// null). |
| | 8934 | | /// </param> |
| | 8935 | | /// <param name='trainingParameters'> |
| | 8936 | | /// Additional training parameters passed in to control how the project is |
| | 8937 | | /// trained. |
| | 8938 | | /// </param> |
| | 8939 | | /// <param name='customHeaders'> |
| | 8940 | | /// Headers that will be added to request. |
| | 8941 | | /// </param> |
| | 8942 | | /// <param name='cancellationToken'> |
| | 8943 | | /// The cancellation token. |
| | 8944 | | /// </param> |
| | 8945 | | /// <exception cref="CustomVisionErrorException"> |
| | 8946 | | /// Thrown when the operation returned an invalid status code |
| | 8947 | | /// </exception> |
| | 8948 | | /// <exception cref="SerializationException"> |
| | 8949 | | /// Thrown when unable to deserialize the response |
| | 8950 | | /// </exception> |
| | 8951 | | /// <exception cref="ValidationException"> |
| | 8952 | | /// Thrown when a required parameter is null |
| | 8953 | | /// </exception> |
| | 8954 | | /// <exception cref="System.ArgumentNullException"> |
| | 8955 | | /// Thrown when a required parameter is null |
| | 8956 | | /// </exception> |
| | 8957 | | /// <return> |
| | 8958 | | /// A response object containing the response body and response headers. |
| | 8959 | | /// </return> |
| | 8960 | | public async Task<HttpOperationResponse<Iteration>> TrainProjectWithHttpMessagesAsync(System.Guid projectId, str |
| | 8961 | | { |
| 2 | 8962 | | if (Endpoint == null) |
| | 8963 | | { |
| 0 | 8964 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 8965 | | } |
| | 8966 | | // Tracing |
| 2 | 8967 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 8968 | | string _invocationId = null; |
| 2 | 8969 | | if (_shouldTrace) |
| | 8970 | | { |
| 0 | 8971 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 8972 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 8973 | | tracingParameters.Add("projectId", projectId); |
| 0 | 8974 | | tracingParameters.Add("trainingType", trainingType); |
| 0 | 8975 | | tracingParameters.Add("reservedBudgetInHours", reservedBudgetInHours); |
| 0 | 8976 | | tracingParameters.Add("forceTrain", forceTrain); |
| 0 | 8977 | | tracingParameters.Add("notificationEmailAddress", notificationEmailAddress); |
| 0 | 8978 | | tracingParameters.Add("trainingParameters", trainingParameters); |
| 0 | 8979 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 8980 | | ServiceClientTracing.Enter(_invocationId, this, "TrainProject", tracingParameters); |
| | 8981 | | } |
| | 8982 | | // Construct URL |
| 2 | 8983 | | var _baseUrl = BaseUri; |
| 2 | 8984 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/{projectId}/train"; |
| 2 | 8985 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 8986 | | _url = _url.Replace("{projectId}", System.Uri.EscapeDataString(SafeJsonConvert.SerializeObject(projectId, Se |
| 2 | 8987 | | List<string> _queryParameters = new List<string>(); |
| 2 | 8988 | | if (trainingType != null) |
| | 8989 | | { |
| 0 | 8990 | | _queryParameters.Add(string.Format("trainingType={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seria |
| | 8991 | | } |
| 2 | 8992 | | if (reservedBudgetInHours != null) |
| | 8993 | | { |
| 2 | 8994 | | _queryParameters.Add(string.Format("reservedBudgetInHours={0}", System.Uri.EscapeDataString(SafeJsonConv |
| | 8995 | | } |
| 2 | 8996 | | if (forceTrain != null) |
| | 8997 | | { |
| 2 | 8998 | | _queryParameters.Add(string.Format("forceTrain={0}", System.Uri.EscapeDataString(SafeJsonConvert.Seriali |
| | 8999 | | } |
| 2 | 9000 | | if (notificationEmailAddress != null) |
| | 9001 | | { |
| 0 | 9002 | | _queryParameters.Add(string.Format("notificationEmailAddress={0}", System.Uri.EscapeDataString(notificat |
| | 9003 | | } |
| 2 | 9004 | | if (_queryParameters.Count > 0) |
| | 9005 | | { |
| 2 | 9006 | | _url += "?" + string.Join("&", _queryParameters); |
| | 9007 | | } |
| | 9008 | | // Create HTTP transport objects |
| 2 | 9009 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 9010 | | HttpResponseMessage _httpResponse = null; |
| 2 | 9011 | | _httpRequest.Method = new HttpMethod("POST"); |
| 2 | 9012 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 9013 | | // Set Headers |
| | 9014 | |
|
| | 9015 | |
|
| 2 | 9016 | | if (customHeaders != null) |
| | 9017 | | { |
| 0 | 9018 | | foreach(var _header in customHeaders) |
| | 9019 | | { |
| 0 | 9020 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 9021 | | { |
| 0 | 9022 | | _httpRequest.Headers.Remove(_header.Key); |
| | 9023 | | } |
| 0 | 9024 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 9025 | | } |
| | 9026 | | } |
| | 9027 | |
|
| | 9028 | | // Serialize Request |
| 2 | 9029 | | string _requestContent = null; |
| 2 | 9030 | | if(trainingParameters != null) |
| | 9031 | | { |
| 0 | 9032 | | _requestContent = SafeJsonConvert.SerializeObject(trainingParameters, SerializationSettings); |
| 0 | 9033 | | _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); |
| 0 | 9034 | | _httpRequest.Content.Headers.ContentType =MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); |
| | 9035 | | } |
| | 9036 | | // Set Credentials |
| 2 | 9037 | | if (Credentials != null) |
| | 9038 | | { |
| 2 | 9039 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 9040 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 9041 | | } |
| | 9042 | | // Send Request |
| 2 | 9043 | | if (_shouldTrace) |
| | 9044 | | { |
| 0 | 9045 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 9046 | | } |
| 2 | 9047 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 9048 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 9049 | | if (_shouldTrace) |
| | 9050 | | { |
| 0 | 9051 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 9052 | | } |
| 2 | 9053 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 9054 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 9055 | | string _responseContent = null; |
| 2 | 9056 | | if ((int)_statusCode != 200) |
| | 9057 | | { |
| 0 | 9058 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 9059 | | try |
| | 9060 | | { |
| 0 | 9061 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 9062 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 9063 | | if (_errorBody != null) |
| | 9064 | | { |
| 0 | 9065 | | ex.Body = _errorBody; |
| | 9066 | | } |
| 0 | 9067 | | } |
| 0 | 9068 | | catch (JsonException) |
| | 9069 | | { |
| | 9070 | | // Ignore the exception |
| 0 | 9071 | | } |
| 0 | 9072 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 9073 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 9074 | | if (_shouldTrace) |
| | 9075 | | { |
| 0 | 9076 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 9077 | | } |
| 0 | 9078 | | _httpRequest.Dispose(); |
| 0 | 9079 | | if (_httpResponse != null) |
| | 9080 | | { |
| 0 | 9081 | | _httpResponse.Dispose(); |
| | 9082 | | } |
| 0 | 9083 | | throw ex; |
| | 9084 | | } |
| | 9085 | | // Create Result |
| 2 | 9086 | | var _result = new HttpOperationResponse<Iteration>(); |
| 2 | 9087 | | _result.Request = _httpRequest; |
| 2 | 9088 | | _result.Response = _httpResponse; |
| | 9089 | | // Deserialize Response |
| 2 | 9090 | | if ((int)_statusCode == 200) |
| | 9091 | | { |
| 2 | 9092 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 9093 | | try |
| | 9094 | | { |
| 2 | 9095 | | _result.Body = SafeJsonConvert.DeserializeObject<Iteration>(_responseContent, DeserializationSetting |
| 2 | 9096 | | } |
| 0 | 9097 | | catch (JsonException ex) |
| | 9098 | | { |
| 0 | 9099 | | _httpRequest.Dispose(); |
| 0 | 9100 | | if (_httpResponse != null) |
| | 9101 | | { |
| 0 | 9102 | | _httpResponse.Dispose(); |
| | 9103 | | } |
| 0 | 9104 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 9105 | | } |
| | 9106 | | } |
| 2 | 9107 | | if (_shouldTrace) |
| | 9108 | | { |
| 0 | 9109 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 9110 | | } |
| 2 | 9111 | | return _result; |
| 2 | 9112 | | } |
| | 9113 | |
|
| | 9114 | | /// <summary> |
| | 9115 | | /// Imports a project. |
| | 9116 | | /// </summary> |
| | 9117 | | /// <param name='token'> |
| | 9118 | | /// Token generated from the export project call. |
| | 9119 | | /// </param> |
| | 9120 | | /// <param name='name'> |
| | 9121 | | /// Optional, name of the project to use instead of auto-generated name. |
| | 9122 | | /// </param> |
| | 9123 | | /// <param name='customHeaders'> |
| | 9124 | | /// Headers that will be added to request. |
| | 9125 | | /// </param> |
| | 9126 | | /// <param name='cancellationToken'> |
| | 9127 | | /// The cancellation token. |
| | 9128 | | /// </param> |
| | 9129 | | /// <exception cref="CustomVisionErrorException"> |
| | 9130 | | /// Thrown when the operation returned an invalid status code |
| | 9131 | | /// </exception> |
| | 9132 | | /// <exception cref="SerializationException"> |
| | 9133 | | /// Thrown when unable to deserialize the response |
| | 9134 | | /// </exception> |
| | 9135 | | /// <exception cref="ValidationException"> |
| | 9136 | | /// Thrown when a required parameter is null |
| | 9137 | | /// </exception> |
| | 9138 | | /// <exception cref="System.ArgumentNullException"> |
| | 9139 | | /// Thrown when a required parameter is null |
| | 9140 | | /// </exception> |
| | 9141 | | /// <return> |
| | 9142 | | /// A response object containing the response body and response headers. |
| | 9143 | | /// </return> |
| | 9144 | | public async Task<HttpOperationResponse<Project>> ImportProjectWithHttpMessagesAsync(string token, string name = |
| | 9145 | | { |
| 2 | 9146 | | if (Endpoint == null) |
| | 9147 | | { |
| 0 | 9148 | | throw new ValidationException(ValidationRules.CannotBeNull, "this.Endpoint"); |
| | 9149 | | } |
| 2 | 9150 | | if (token == null) |
| | 9151 | | { |
| 0 | 9152 | | throw new ValidationException(ValidationRules.CannotBeNull, "token"); |
| | 9153 | | } |
| | 9154 | | // Tracing |
| 2 | 9155 | | bool _shouldTrace = ServiceClientTracing.IsEnabled; |
| 2 | 9156 | | string _invocationId = null; |
| 2 | 9157 | | if (_shouldTrace) |
| | 9158 | | { |
| 0 | 9159 | | _invocationId = ServiceClientTracing.NextInvocationId.ToString(); |
| 0 | 9160 | | Dictionary<string, object> tracingParameters = new Dictionary<string, object>(); |
| 0 | 9161 | | tracingParameters.Add("token", token); |
| 0 | 9162 | | tracingParameters.Add("name", name); |
| 0 | 9163 | | tracingParameters.Add("cancellationToken", cancellationToken); |
| 0 | 9164 | | ServiceClientTracing.Enter(_invocationId, this, "ImportProject", tracingParameters); |
| | 9165 | | } |
| | 9166 | | // Construct URL |
| 2 | 9167 | | var _baseUrl = BaseUri; |
| 2 | 9168 | | var _url = _baseUrl + (_baseUrl.EndsWith("/") ? "" : "/") + "projects/import"; |
| 2 | 9169 | | _url = _url.Replace("{Endpoint}", Endpoint); |
| 2 | 9170 | | List<string> _queryParameters = new List<string>(); |
| 2 | 9171 | | if (token != null) |
| | 9172 | | { |
| 2 | 9173 | | _queryParameters.Add(string.Format("token={0}", System.Uri.EscapeDataString(token))); |
| | 9174 | | } |
| 2 | 9175 | | if (name != null) |
| | 9176 | | { |
| 0 | 9177 | | _queryParameters.Add(string.Format("name={0}", System.Uri.EscapeDataString(name))); |
| | 9178 | | } |
| 2 | 9179 | | if (_queryParameters.Count > 0) |
| | 9180 | | { |
| 2 | 9181 | | _url += "?" + string.Join("&", _queryParameters); |
| | 9182 | | } |
| | 9183 | | // Create HTTP transport objects |
| 2 | 9184 | | var _httpRequest = new HttpRequestMessage(); |
| 2 | 9185 | | HttpResponseMessage _httpResponse = null; |
| 2 | 9186 | | _httpRequest.Method = new HttpMethod("POST"); |
| 2 | 9187 | | _httpRequest.RequestUri = new System.Uri(_url); |
| | 9188 | | // Set Headers |
| | 9189 | |
|
| | 9190 | |
|
| 2 | 9191 | | if (customHeaders != null) |
| | 9192 | | { |
| 0 | 9193 | | foreach(var _header in customHeaders) |
| | 9194 | | { |
| 0 | 9195 | | if (_httpRequest.Headers.Contains(_header.Key)) |
| | 9196 | | { |
| 0 | 9197 | | _httpRequest.Headers.Remove(_header.Key); |
| | 9198 | | } |
| 0 | 9199 | | _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); |
| | 9200 | | } |
| | 9201 | | } |
| | 9202 | |
|
| | 9203 | | // Serialize Request |
| 2 | 9204 | | string _requestContent = null; |
| | 9205 | | // Set Credentials |
| 2 | 9206 | | if (Credentials != null) |
| | 9207 | | { |
| 2 | 9208 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 9209 | | await Credentials.ProcessHttpRequestAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| | 9210 | | } |
| | 9211 | | // Send Request |
| 2 | 9212 | | if (_shouldTrace) |
| | 9213 | | { |
| 0 | 9214 | | ServiceClientTracing.SendRequest(_invocationId, _httpRequest); |
| | 9215 | | } |
| 2 | 9216 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 9217 | | _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); |
| 2 | 9218 | | if (_shouldTrace) |
| | 9219 | | { |
| 0 | 9220 | | ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); |
| | 9221 | | } |
| 2 | 9222 | | HttpStatusCode _statusCode = _httpResponse.StatusCode; |
| 2 | 9223 | | cancellationToken.ThrowIfCancellationRequested(); |
| 2 | 9224 | | string _responseContent = null; |
| 2 | 9225 | | if ((int)_statusCode != 200) |
| | 9226 | | { |
| 0 | 9227 | | var ex = new CustomVisionErrorException(string.Format("Operation returned an invalid status code '{0}'", |
| | 9228 | | try |
| | 9229 | | { |
| 0 | 9230 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| 0 | 9231 | | CustomVisionError _errorBody = SafeJsonConvert.DeserializeObject<CustomVisionError>(_responseConten |
| 0 | 9232 | | if (_errorBody != null) |
| | 9233 | | { |
| 0 | 9234 | | ex.Body = _errorBody; |
| | 9235 | | } |
| 0 | 9236 | | } |
| 0 | 9237 | | catch (JsonException) |
| | 9238 | | { |
| | 9239 | | // Ignore the exception |
| 0 | 9240 | | } |
| 0 | 9241 | | ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); |
| 0 | 9242 | | ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); |
| 0 | 9243 | | if (_shouldTrace) |
| | 9244 | | { |
| 0 | 9245 | | ServiceClientTracing.Error(_invocationId, ex); |
| | 9246 | | } |
| 0 | 9247 | | _httpRequest.Dispose(); |
| 0 | 9248 | | if (_httpResponse != null) |
| | 9249 | | { |
| 0 | 9250 | | _httpResponse.Dispose(); |
| | 9251 | | } |
| 0 | 9252 | | throw ex; |
| | 9253 | | } |
| | 9254 | | // Create Result |
| 2 | 9255 | | var _result = new HttpOperationResponse<Project>(); |
| 2 | 9256 | | _result.Request = _httpRequest; |
| 2 | 9257 | | _result.Response = _httpResponse; |
| | 9258 | | // Deserialize Response |
| 2 | 9259 | | if ((int)_statusCode == 200) |
| | 9260 | | { |
| 2 | 9261 | | _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); |
| | 9262 | | try |
| | 9263 | | { |
| 2 | 9264 | | _result.Body = SafeJsonConvert.DeserializeObject<Project>(_responseContent, DeserializationSettings) |
| 2 | 9265 | | } |
| 0 | 9266 | | catch (JsonException ex) |
| | 9267 | | { |
| 0 | 9268 | | _httpRequest.Dispose(); |
| 0 | 9269 | | if (_httpResponse != null) |
| | 9270 | | { |
| 0 | 9271 | | _httpResponse.Dispose(); |
| | 9272 | | } |
| 0 | 9273 | | throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); |
| | 9274 | | } |
| | 9275 | | } |
| 2 | 9276 | | if (_shouldTrace) |
| | 9277 | | { |
| 0 | 9278 | | ServiceClientTracing.Exit(_invocationId, _result); |
| | 9279 | | } |
| 2 | 9280 | | return _result; |
| 2 | 9281 | | } |
| | 9282 | |
|
| | 9283 | | } |
| | 9284 | | } |