diff --git a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiExpandImage.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiExpandImage.g.cs index b681d4a..20fd7ec 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiExpandImage.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiExpandImage.g.cs @@ -14,6 +14,7 @@ public partial class GenAIInpaintingImage2ImageClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -47,16 +48,19 @@ partial void ProcessGenaiExpandImageResponseContent( /// This service is engineered to accommodate the need for larger image sizes without compromising on quality. The requirement that the specified width and height dimensions exceed the original image dimensions ensures that users can seamlessly scale their images up to meet various requirements, whether for professional presentations, digital marketing materials, web design, or personal use. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiExpandImageAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiExpandImageAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -69,11 +73,13 @@ partial void ProcessGenaiExpandImageResponseContent( /// This service is engineered to accommodate the need for larger image sizes without compromising on quality. The requirement that the specified width and height dimensions exceed the original image dimensions ensures that users can seamlessly scale their images up to meet various requirements, whether for professional presentations, digital marketing materials, web design, or personal use. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiExpandImageAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -88,22 +94,43 @@ partial void ProcessGenaiExpandImageResponseContent( securityRequirements: s_GenaiExpandImageSecurityRequirements, operationName: "GenaiExpandImageAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/painting/expand", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/painting/expand", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -113,576 +140,735 @@ partial void ProcessGenaiExpandImageResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiExpandImageRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiExpandImageResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiExpandImageRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiExpandImage", + methodName: "GenaiExpandImageAsync", + pathTemplate: "\"/genai/painting/expand\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiExpandImage", + methodName: "GenaiExpandImageAsync", + pathTemplate: "\"/genai/painting/expand\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiExpandImage", + methodName: "GenaiExpandImageAsync", + pathTemplate: "\"/genai/painting/expand\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + if (__response == null) { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiExpandImageResponseContent( + response: __response); + ProcessGenaiExpandImageResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiExpandImageResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiExpandImage", + methodName: "GenaiExpandImageAsync", + pathTemplate: "\"/genai/painting/expand\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiExpandImageResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiExpandImage", + methodName: "GenaiExpandImageAsync", + pathTemplate: "\"/genai/painting/expand\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiExpandImageResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiExpandImageResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiExpandImageResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Expand Image
@@ -690,9 +876,11 @@ partial void ProcessGenaiExpandImageResponseContent( ///
/// This service is engineered to accommodate the need for larger image sizes without compromising on quality. The requirement that the specified width and height dimensions exceed the original image dimensions ensures that users can seamlessly scale their images up to meet various requirements, whether for professional presentations, digital marketing materials, web design, or personal use. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiExpandImageAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -701,6 +889,7 @@ partial void ProcessGenaiExpandImageResponseContent( return await GenaiExpandImageAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiGenerateImageBleed.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiGenerateImageBleed.g.cs index b49dd27..470a315 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiGenerateImageBleed.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiGenerateImageBleed.g.cs @@ -14,6 +14,7 @@ public partial class GenAIInpaintingImage2ImageClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -46,16 +47,19 @@ partial void ProcessGenaiGenerateImageBleedResponseContent( /// This service enlarges the original images and generates additional pixels around the original from all sides. This helps print original images without needing to cut part of it during the print production process. The generated bleed area is a continuation of the original image and will ensure a consistent and high cut quality. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiGenerateImageBleedAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiGenerateImageBleedAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -67,11 +71,13 @@ partial void ProcessGenaiGenerateImageBleedResponseContent( /// This service enlarges the original images and generates additional pixels around the original from all sides. This helps print original images without needing to cut part of it during the print production process. The generated bleed area is a continuation of the original image and will ensure a consistent and high cut quality. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiGenerateImageBleedAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -86,22 +92,43 @@ partial void ProcessGenaiGenerateImageBleedResponseContent( securityRequirements: s_GenaiGenerateImageBleedSecurityRequirements, operationName: "GenaiGenerateImageBleedAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/painting/bleed", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/painting/bleed", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -111,585 +138,746 @@ partial void ProcessGenaiGenerateImageBleedResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiGenerateImageBleedRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiGenerateImageBleedResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiGenerateImageBleedRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateImageBleed", + methodName: "GenaiGenerateImageBleedAsync", + pathTemplate: "\"/genai/painting/bleed\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateImageBleed", + methodName: "GenaiGenerateImageBleedAsync", + pathTemplate: "\"/genai/painting/bleed\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateImageBleed", + methodName: "GenaiGenerateImageBleedAsync", + pathTemplate: "\"/genai/painting/bleed\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + if (__response == null) { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiGenerateImageBleedResponseContent( + response: __response); + ProcessGenaiGenerateImageBleedResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiGenerateImageBleedResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateImageBleed", + methodName: "GenaiGenerateImageBleedAsync", + pathTemplate: "\"/genai/painting/bleed\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiGenerateImageBleedResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateImageBleed", + methodName: "GenaiGenerateImageBleedAsync", + pathTemplate: "\"/genai/painting/bleed\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiGenerateImageBleedResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiGenerateImageBleedResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiGenerateImageBleedResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Generate Bleed
/// This service offers a groundbreaking functionality designed to enhance digital imagery by enabling users to enlarge any image.
/// This service enlarges the original images and generates additional pixels around the original from all sides. This helps print original images without needing to cut part of it during the print production process. The generated bleed area is a continuation of the original image and will ensure a consistent and high cut quality. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiGenerateImageBleedAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -698,6 +886,7 @@ partial void ProcessGenaiGenerateImageBleedResponseContent( return await GenaiGenerateImageBleedAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiImageInpainting.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiImageInpainting.g.cs index 6facf6b..13d914d 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiImageInpainting.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiImageInpainting.g.cs @@ -14,6 +14,7 @@ public partial class GenAIInpaintingImage2ImageClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessGenaiImageInpaintingResponseContent( /// The **Inpainting** service offers inpainting (image2Image) capabilities, enabling users to fill or replace areas within an image based on specified criteria. It operates in two modes: * Single Image Mode: Submit one RGBA image. The API fills the specified inner area with content based on the prompt parameter. * Mask Mode: Along with the RGBA image, provide a mask of identical size and format. The API uses this mask to identify areas for inpainting with content determined by the prompt parameter. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiImageInpaintingAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiImageInpaintingAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessGenaiImageInpaintingResponseContent( /// The **Inpainting** service offers inpainting (image2Image) capabilities, enabling users to fill or replace areas within an image based on specified criteria. It operates in two modes: * Single Image Mode: Submit one RGBA image. The API fills the specified inner area with content based on the prompt parameter. * Mask Mode: Along with the RGBA image, provide a mask of identical size and format. The API uses this mask to identify areas for inpainting with content determined by the prompt parameter. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiImageInpaintingAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessGenaiImageInpaintingResponseContent( securityRequirements: s_GenaiImageInpaintingSecurityRequirements, operationName: "GenaiImageInpaintingAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/painting/inpaint", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/painting/inpaint", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,584 +136,745 @@ partial void ProcessGenaiImageInpaintingResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiImageInpaintingRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiImageInpaintingResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiImageInpaintingRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageInpainting", + methodName: "GenaiImageInpaintingAsync", + pathTemplate: "\"/genai/painting/inpaint\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageInpainting", + methodName: "GenaiImageInpaintingAsync", + pathTemplate: "\"/genai/painting/inpaint\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageInpainting", + methodName: "GenaiImageInpaintingAsync", + pathTemplate: "\"/genai/painting/inpaint\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + if (__response == null) { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiImageInpaintingResponseContent( + response: __response); + ProcessGenaiImageInpaintingResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiImageInpaintingResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageInpainting", + methodName: "GenaiImageInpaintingAsync", + pathTemplate: "\"/genai/painting/inpaint\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiImageInpaintingResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageInpainting", + methodName: "GenaiImageInpaintingAsync", + pathTemplate: "\"/genai/painting/inpaint\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiImageInpaintingResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiImageInpaintingResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiImageInpaintingResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Inpaint Image
/// The **Inpainting** service offers inpainting (image2Image) capabilities, enabling users to fill or replace areas within an image based on specified criteria. It operates in two modes: * Single Image Mode: Submit one RGBA image. The API fills the specified inner area with content based on the prompt parameter. * Mask Mode: Along with the RGBA image, provide a mask of identical size and format. The API uses this mask to identify areas for inpainting with content determined by the prompt parameter. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiImageInpaintingAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -695,6 +883,7 @@ partial void ProcessGenaiImageInpaintingResponseContent( return await GenaiImageInpaintingAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiImageInpaintingGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiImageInpaintingGetresult.g.cs index b7477e8..7cac248 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiImageInpaintingGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiImageInpaintingGetresult.g.cs @@ -14,6 +14,7 @@ public partial class GenAIInpaintingImage2ImageClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -46,14 +47,17 @@ partial void ProcessGenaiImageInpaintingGetresultResponseContent( /// Use this service to check up on the result. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiImageInpaintingGetresultAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiImageInpaintingGetresultAsResponseAsync( inferenceId: inferenceId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,10 +69,12 @@ partial void ProcessGenaiImageInpaintingGetresultResponseContent( /// Use this service to check up on the result. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiImageInpaintingGetresultAsResponseAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -83,22 +89,43 @@ partial void ProcessGenaiImageInpaintingGetresultResponseContent( securityRequirements: s_GenaiImageInpaintingGetresultSecurityRequirements, operationName: "GenaiImageInpaintingGetresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/genai/painting/{inferenceId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/genai/painting/{inferenceId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -108,574 +135,733 @@ partial void ProcessGenaiImageInpaintingGetresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiImageInpaintingGetresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - inferenceId: inferenceId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiImageInpaintingGetresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiImageInpaintingGetresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + inferenceId: inferenceId); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageInpaintingGetresult", + methodName: "GenaiImageInpaintingGetresultAsync", + pathTemplate: "$\"/genai/painting/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageInpaintingGetresult", + methodName: "GenaiImageInpaintingGetresultAsync", + pathTemplate: "$\"/genai/painting/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageInpaintingGetresult", + methodName: "GenaiImageInpaintingGetresultAsync", + pathTemplate: "$\"/genai/painting/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } + break; } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiImageInpaintingGetresultResponseContent( + response: __response); + ProcessGenaiImageInpaintingGetresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiImageInpaintingGetresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageInpaintingGetresult", + methodName: "GenaiImageInpaintingGetresultAsync", + pathTemplate: "$\"/genai/painting/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiImageInpaintingGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageInpaintingGetresult", + methodName: "GenaiImageInpaintingGetresultAsync", + pathTemplate: "$\"/genai/painting/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiImageInpaintingGetresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiImageInpaintingGetresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiImageInpaintingGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiImageOutpainting.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiImageOutpainting.g.cs index 0e81922..505b0e0 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiImageOutpainting.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiImageOutpainting.g.cs @@ -14,6 +14,7 @@ public partial class GenAIInpaintingImage2ImageClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -48,16 +49,19 @@ partial void ProcessGenaiImageOutpaintingResponseContent( /// * Mask Mode: Provide an RGBA image along with a mask of the same size. The API applies this mask to paint beyond the masked region, using content determined by the prompt parameter. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiImageOutpaintingAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiImageOutpaintingAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -71,11 +75,13 @@ partial void ProcessGenaiImageOutpaintingResponseContent( /// * Mask Mode: Provide an RGBA image along with a mask of the same size. The API applies this mask to paint beyond the masked region, using content determined by the prompt parameter. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiImageOutpaintingAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -90,22 +96,43 @@ partial void ProcessGenaiImageOutpaintingResponseContent( securityRequirements: s_GenaiImageOutpaintingSecurityRequirements, operationName: "GenaiImageOutpaintingAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/painting/outpaint", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/painting/outpaint", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -115,576 +142,735 @@ partial void ProcessGenaiImageOutpaintingResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiImageOutpaintingRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiImageOutpaintingResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiImageOutpaintingRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageOutpainting", + methodName: "GenaiImageOutpaintingAsync", + pathTemplate: "\"/genai/painting/outpaint\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageOutpainting", + methodName: "GenaiImageOutpaintingAsync", + pathTemplate: "\"/genai/painting/outpaint\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageOutpainting", + methodName: "GenaiImageOutpaintingAsync", + pathTemplate: "\"/genai/painting/outpaint\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + if (__response == null) { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiImageOutpaintingResponseContent( + response: __response); + ProcessGenaiImageOutpaintingResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiImageOutpaintingResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageOutpainting", + methodName: "GenaiImageOutpaintingAsync", + pathTemplate: "\"/genai/painting/outpaint\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiImageOutpaintingResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImageOutpainting", + methodName: "GenaiImageOutpaintingAsync", + pathTemplate: "\"/genai/painting/outpaint\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiImageOutpaintingResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiImageOutpaintingResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiImageOutpaintingResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Outpaint Image
@@ -693,9 +879,11 @@ partial void ProcessGenaiImageOutpaintingResponseContent( /// * Single Image Mode: Upload one RGBA image. The API enhances the outer area with content based on the prompt parameter.
/// * Mask Mode: Provide an RGBA image along with a mask of the same size. The API applies this mask to paint beyond the masked region, using content determined by the prompt parameter. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiImageOutpaintingAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -704,6 +892,7 @@ partial void ProcessGenaiImageOutpaintingResponseContent( return await GenaiImageOutpaintingAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiRemoveObject.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiRemoveObject.g.cs index 852f8b8..cd2bb1b 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiRemoveObject.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiRemoveObject.g.cs @@ -14,6 +14,7 @@ public partial class GenAIInpaintingImage2ImageClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -46,16 +47,19 @@ partial void ProcessGenaiRemoveObjectResponseContent( /// Even though the same type of a result can also achieved via the <a href="https://docs.picsart.io/reference/genai-image-inpainting">Inpainting</a> service, this service uses a specially trained model to provide fine tuned results. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiRemoveObjectAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiRemoveObjectAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -67,11 +71,13 @@ partial void ProcessGenaiRemoveObjectResponseContent( /// Even though the same type of a result can also achieved via the <a href="https://docs.picsart.io/reference/genai-image-inpainting">Inpainting</a> service, this service uses a specially trained model to provide fine tuned results. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiRemoveObjectAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -86,22 +92,43 @@ partial void ProcessGenaiRemoveObjectResponseContent( securityRequirements: s_GenaiRemoveObjectSecurityRequirements, operationName: "GenaiRemoveObjectAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/painting/remove-object", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/painting/remove-object", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -111,585 +138,746 @@ partial void ProcessGenaiRemoveObjectResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiRemoveObjectRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiRemoveObjectResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiRemoveObjectRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiRemoveObject", + methodName: "GenaiRemoveObjectAsync", + pathTemplate: "\"/genai/painting/remove-object\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiRemoveObject", + methodName: "GenaiRemoveObjectAsync", + pathTemplate: "\"/genai/painting/remove-object\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiRemoveObject", + methodName: "GenaiRemoveObjectAsync", + pathTemplate: "\"/genai/painting/remove-object\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + if (__response == null) { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiRemoveObjectResponseContent( + response: __response); + ProcessGenaiRemoveObjectResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiRemoveObjectResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiRemoveObject", + methodName: "GenaiRemoveObjectAsync", + pathTemplate: "\"/genai/painting/remove-object\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiRemoveObjectResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiRemoveObject", + methodName: "GenaiRemoveObjectAsync", + pathTemplate: "\"/genai/painting/remove-object\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiRemoveObjectResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiRemoveObjectResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiRemoveObjectResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Remove Object from an Image
/// This service allows to remove objects from the original image by providing a mask.
/// Even though the same type of a result can also achieved via the <a href="https://docs.picsart.io/reference/genai-image-inpainting">Inpainting</a> service, this service uses a specially trained model to provide fine tuned results. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiRemoveObjectAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -698,6 +886,7 @@ partial void ProcessGenaiRemoveObjectResponseContent( return await GenaiRemoveObjectAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiSmartBackground.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiSmartBackground.g.cs index 89d9bd7..c17d7a7 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiSmartBackground.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.GenaiSmartBackground.g.cs @@ -14,6 +14,7 @@ public partial class GenAIInpaintingImage2ImageClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -49,16 +50,19 @@ partial void ProcessGenaiSmartBackgroundResponseContent( /// With Smart Background, users have the unique opportunity to reimagine their photos by simply submitting an image along with a narrative of the desired background. Our advanced AI algorithms then work to seamlessly integrate a bespoke, contextually appropriate scene behind the subject of the photo. This not only allows for unparalleled personalization but also offers a creative freedom unmatched by conventional methods. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiSmartBackgroundAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiSmartBackgroundAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -73,11 +77,13 @@ partial void ProcessGenaiSmartBackgroundResponseContent( /// With Smart Background, users have the unique opportunity to reimagine their photos by simply submitting an image along with a narrative of the desired background. Our advanced AI algorithms then work to seamlessly integrate a bespoke, contextually appropriate scene behind the subject of the photo. This not only allows for unparalleled personalization but also offers a creative freedom unmatched by conventional methods. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiSmartBackgroundAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -92,22 +98,43 @@ partial void ProcessGenaiSmartBackgroundResponseContent( securityRequirements: s_GenaiSmartBackgroundSecurityRequirements, operationName: "GenaiSmartBackgroundAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/painting/replace-background", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/painting/replace-background", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -117,576 +144,735 @@ partial void ProcessGenaiSmartBackgroundResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiSmartBackgroundRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiSmartBackgroundResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiSmartBackgroundRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiSmartBackground", + methodName: "GenaiSmartBackgroundAsync", + pathTemplate: "\"/genai/painting/replace-background\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiSmartBackground", + methodName: "GenaiSmartBackgroundAsync", + pathTemplate: "\"/genai/painting/replace-background\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiSmartBackground", + methodName: "GenaiSmartBackgroundAsync", + pathTemplate: "\"/genai/painting/replace-background\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + if (__response == null) { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiSmartBackgroundResponseContent( + response: __response); + ProcessGenaiSmartBackgroundResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiSmartBackgroundResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiSmartBackground", + methodName: "GenaiSmartBackgroundAsync", + pathTemplate: "\"/genai/painting/replace-background\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiSmartBackgroundResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiSmartBackground", + methodName: "GenaiSmartBackgroundAsync", + pathTemplate: "\"/genai/painting/replace-background\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiSmartBackgroundResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiSmartBackgroundResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiSmartBackgroundResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Smart Background
@@ -696,9 +882,11 @@ partial void ProcessGenaiSmartBackgroundResponseContent( ///
/// With Smart Background, users have the unique opportunity to reimagine their photos by simply submitting an image along with a narrative of the desired background. Our advanced AI algorithms then work to seamlessly integrate a bespoke, contextually appropriate scene behind the subject of the photo. This not only allows for unparalleled personalization but also offers a creative freedom unmatched by conventional methods. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiSmartBackgroundAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -707,6 +895,7 @@ partial void ProcessGenaiSmartBackgroundResponseContent( return await GenaiSmartBackgroundAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.g.cs index 24f0310..e1a7880 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIInpaintingImage2ImageClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class GenAIInpaintingImage2ImageClient : global::Picsart.I #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public GenAIInpaintingImage2ImageClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the GenAIInpaintingImage2ImageClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public GenAIInpaintingImage2ImageClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.GenaiText2audioGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.GenaiText2audioGetresult.g.cs index 9f53ac9..96d3e79 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.GenaiText2audioGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.GenaiText2audioGetresult.g.cs @@ -14,6 +14,7 @@ public partial class GenAIText2AudioClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,14 +46,17 @@ partial void ProcessGenaiText2audioGetresultResponseContent( /// Use this method, along with inference id, to retrieve the generated speech or sound/music. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2audioGetresultAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiText2audioGetresultAsResponseAsync( inferenceId: inferenceId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,10 +67,12 @@ partial void ProcessGenaiText2audioGetresultResponseContent( /// Use this method, along with inference id, to retrieve the generated speech or sound/music. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiText2audioGetresultAsResponseAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -81,22 +87,43 @@ partial void ProcessGenaiText2audioGetresultResponseContent( securityRequirements: s_GenaiText2audioGetresultSecurityRequirements, operationName: "GenaiText2audioGetresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/genai/audio/{inferenceId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/genai/audio/{inferenceId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -106,574 +133,733 @@ partial void ProcessGenaiText2audioGetresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiText2audioGetresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - inferenceId: inferenceId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiText2audioGetresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiText2audioGetresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + inferenceId: inferenceId); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2audioGetresult", + methodName: "GenaiText2audioGetresultAsync", + pathTemplate: "$\"/genai/audio/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2audioGetresult", + methodName: "GenaiText2audioGetresultAsync", + pathTemplate: "$\"/genai/audio/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2audioGetresult", + methodName: "GenaiText2audioGetresultAsync", + pathTemplate: "$\"/genai/audio/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } + break; } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiText2audioGetresultResponseContent( + response: __response); + ProcessGenaiText2audioGetresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiText2audioGetresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2audioGetresult", + methodName: "GenaiText2audioGetresultAsync", + pathTemplate: "$\"/genai/audio/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiText2audioGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2audioGetresult", + methodName: "GenaiText2audioGetresultAsync", + pathTemplate: "$\"/genai/audio/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiText2audioGetresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiText2audioGetresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiText2audioGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.GenaiText2sound.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.GenaiText2sound.g.cs index e275fea..0e2fbe6 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.GenaiText2sound.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.GenaiText2sound.g.cs @@ -14,6 +14,7 @@ public partial class GenAIText2AudioClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessGenaiText2soundResponseContent( /// The *Text2Sound* service helps generate an music/sound based on the prompt introduced as input by the user. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2soundAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiText2soundAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessGenaiText2soundResponseContent( /// The *Text2Sound* service helps generate an music/sound based on the prompt introduced as input by the user. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiText2soundAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessGenaiText2soundResponseContent( securityRequirements: s_GenaiText2soundSecurityRequirements, operationName: "GenaiText2soundAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/text2sound", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/text2sound", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,588 +136,749 @@ partial void ProcessGenaiText2soundResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiText2soundRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiText2soundResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiText2soundRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2sound", + methodName: "GenaiText2soundAsync", + pathTemplate: "\"/genai/text2sound\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2sound", + methodName: "GenaiText2soundAsync", + pathTemplate: "\"/genai/text2sound\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2sound", + methodName: "GenaiText2soundAsync", + pathTemplate: "\"/genai/text2sound\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiText2soundResponseContent( + response: __response); + ProcessGenaiText2soundResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiText2soundResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2sound", + methodName: "GenaiText2soundAsync", + pathTemplate: "\"/genai/text2sound\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiText2soundResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2sound", + methodName: "GenaiText2soundAsync", + pathTemplate: "\"/genai/text2sound\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiText2soundResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiText2soundResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiText2soundResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Text2Sound
/// The *Text2Sound* service helps generate an music/sound based on the prompt introduced as input by the user. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2soundAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -699,6 +887,7 @@ partial void ProcessGenaiText2soundResponseContent( return await GenaiText2soundAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.GenaiText2speech.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.GenaiText2speech.g.cs index 66a3cad..3585d15 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.GenaiText2speech.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.GenaiText2speech.g.cs @@ -14,6 +14,7 @@ public partial class GenAIText2AudioClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessGenaiText2speechResponseContent( /// The *Text2Speech* service helps generate an audio based on the text introduced as input by the user. The audio will speak the text provided. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2speechAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiText2speechAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessGenaiText2speechResponseContent( /// The *Text2Speech* service helps generate an audio based on the text introduced as input by the user. The audio will speak the text provided. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiText2speechAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessGenaiText2speechResponseContent( securityRequirements: s_GenaiText2speechSecurityRequirements, operationName: "GenaiText2speechAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/text2speech", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/text2speech", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,588 +136,749 @@ partial void ProcessGenaiText2speechResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiText2speechRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiText2speechResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiText2speechRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2speech", + methodName: "GenaiText2speechAsync", + pathTemplate: "\"/genai/text2speech\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2speech", + methodName: "GenaiText2speechAsync", + pathTemplate: "\"/genai/text2speech\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2speech", + methodName: "GenaiText2speechAsync", + pathTemplate: "\"/genai/text2speech\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiText2speechResponseContent( + response: __response); + ProcessGenaiText2speechResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiText2speechResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2speech", + methodName: "GenaiText2speechAsync", + pathTemplate: "\"/genai/text2speech\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiText2speechResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2speech", + methodName: "GenaiText2speechAsync", + pathTemplate: "\"/genai/text2speech\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiText2speechResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiText2speechResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiText2speechResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Text2Speech
/// The *Text2Speech* service helps generate an audio based on the text introduced as input by the user. The audio will speak the text provided. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2speechAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -699,6 +887,7 @@ partial void ProcessGenaiText2speechResponseContent( return await GenaiText2speechAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.g.cs index 864edf9..f1f1fcd 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2AudioClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class GenAIText2AudioClient : global::Picsart.IGenAIText2A #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public GenAIText2AudioClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the GenAIText2AudioClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public GenAIText2AudioClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiGenerateLogo.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiGenerateLogo.g.cs index bdb358a..11acaa0 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiGenerateLogo.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiGenerateLogo.g.cs @@ -14,6 +14,7 @@ public partial class GenAIText2ImageClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessGenaiGenerateLogoResponseContent( /// Generate logos using company info, general description. You can add additional information to guide on the details you want to get on the logo. It is also possible to provide an example logo to generate similar logos. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiGenerateLogoAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiGenerateLogoAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessGenaiGenerateLogoResponseContent( /// Generate logos using company info, general description. You can add additional information to guide on the details you want to get on the logo. It is also possible to provide an example logo to generate similar logos. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiGenerateLogoAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessGenaiGenerateLogoResponseContent( securityRequirements: s_GenaiGenerateLogoSecurityRequirements, operationName: "GenaiGenerateLogoAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/logo", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/logo", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,584 +136,745 @@ partial void ProcessGenaiGenerateLogoResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiGenerateLogoRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiGenerateLogoResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiGenerateLogoRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateLogo", + methodName: "GenaiGenerateLogoAsync", + pathTemplate: "\"/genai/logo\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateLogo", + methodName: "GenaiGenerateLogoAsync", + pathTemplate: "\"/genai/logo\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateLogo", + methodName: "GenaiGenerateLogoAsync", + pathTemplate: "\"/genai/logo\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + if (__response == null) { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiGenerateLogoResponseContent( + response: __response); + ProcessGenaiGenerateLogoResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiGenerateLogoResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateLogo", + methodName: "GenaiGenerateLogoAsync", + pathTemplate: "\"/genai/logo\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiGenerateLogoResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateLogo", + methodName: "GenaiGenerateLogoAsync", + pathTemplate: "\"/genai/logo\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiGenerateLogoResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiGenerateLogoResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiGenerateLogoResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Logo Generator
/// Generate logos using company info, general description. You can add additional information to guide on the details you want to get on the logo. It is also possible to provide an example logo to generate similar logos. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiGenerateLogoAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -695,6 +883,7 @@ partial void ProcessGenaiGenerateLogoResponseContent( return await GenaiGenerateLogoAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiGenerateLogoGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiGenerateLogoGetresult.g.cs index 4e65677..c89a33d 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiGenerateLogoGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiGenerateLogoGetresult.g.cs @@ -14,6 +14,7 @@ public partial class GenAIText2ImageClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,14 +46,17 @@ partial void ProcessGenaiGenerateLogoGetresultResponseContent( /// Get the results of your logo generation. Use the inference identifier from the [Logo Generator](https://docs.picsart.io/reference/genai-generate-logo). /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiGenerateLogoGetresultAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiGenerateLogoGetresultAsResponseAsync( inferenceId: inferenceId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,10 +67,12 @@ partial void ProcessGenaiGenerateLogoGetresultResponseContent( /// Get the results of your logo generation. Use the inference identifier from the [Logo Generator](https://docs.picsart.io/reference/genai-generate-logo). /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiGenerateLogoGetresultAsResponseAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -81,22 +87,43 @@ partial void ProcessGenaiGenerateLogoGetresultResponseContent( securityRequirements: s_GenaiGenerateLogoGetresultSecurityRequirements, operationName: "GenaiGenerateLogoGetresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/genai/logo/inferences/{inferenceId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/genai/logo/inferences/{inferenceId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -106,574 +133,733 @@ partial void ProcessGenaiGenerateLogoGetresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiGenerateLogoGetresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - inferenceId: inferenceId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiGenerateLogoGetresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiGenerateLogoGetresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + inferenceId: inferenceId); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateLogoGetresult", + methodName: "GenaiGenerateLogoGetresultAsync", + pathTemplate: "$\"/genai/logo/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateLogoGetresult", + methodName: "GenaiGenerateLogoGetresultAsync", + pathTemplate: "$\"/genai/logo/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateLogoGetresult", + methodName: "GenaiGenerateLogoGetresultAsync", + pathTemplate: "$\"/genai/logo/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } + break; } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiGenerateLogoGetresultResponseContent( + response: __response); + ProcessGenaiGenerateLogoGetresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiGenerateLogoGetresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateLogoGetresult", + methodName: "GenaiGenerateLogoGetresultAsync", + pathTemplate: "$\"/genai/logo/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiGenerateLogoGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiGenerateLogoGetresult", + methodName: "GenaiGenerateLogoGetresultAsync", + pathTemplate: "$\"/genai/logo/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiGenerateLogoGetresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiGenerateLogoGetresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiGenerateLogoGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2image.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2image.g.cs index 6eabc61..899b16a 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2image.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2image.g.cs @@ -14,6 +14,7 @@ public partial class GenAIText2ImageClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -46,16 +47,19 @@ partial void ProcessGenaiText2imageResponseContent( /// The result images can be as big as 1024x1024 pixels. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2imageAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiText2imageAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -67,11 +71,13 @@ partial void ProcessGenaiText2imageResponseContent( /// The result images can be as big as 1024x1024 pixels. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiText2imageAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -86,22 +92,43 @@ partial void ProcessGenaiText2imageResponseContent( securityRequirements: s_GenaiText2imageSecurityRequirements, operationName: "GenaiText2imageAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/text2image", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/text2image", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -111,589 +138,750 @@ partial void ProcessGenaiText2imageResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiText2imageRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiText2imageResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiText2imageRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2image", + methodName: "GenaiText2imageAsync", + pathTemplate: "\"/genai/text2image\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2image", + methodName: "GenaiText2imageAsync", + pathTemplate: "\"/genai/text2image\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2image", + methodName: "GenaiText2imageAsync", + pathTemplate: "\"/genai/text2image\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiText2imageResponseContent( + response: __response); + ProcessGenaiText2imageResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiText2imageResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2image", + methodName: "GenaiText2imageAsync", + pathTemplate: "\"/genai/text2image\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiText2imageResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2image", + methodName: "GenaiText2imageAsync", + pathTemplate: "\"/genai/text2image\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiText2imageResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiText2imageResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiText2imageResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Text2Image
/// The *Text2Image* service helps generate an image based on the text introduced as input by the user.
/// The result images can be as big as 1024x1024 pixels. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2imageAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -702,6 +890,7 @@ partial void ProcessGenaiText2imageResponseContent( return await GenaiText2imageAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2imageGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2imageGetresult.g.cs index 761c657..c0d627d 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2imageGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2imageGetresult.g.cs @@ -14,6 +14,7 @@ public partial class GenAIText2ImageClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,14 +46,17 @@ partial void ProcessGenaiText2imageGetresultResponseContent( /// Get the generated images. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2imageGetresultAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiText2imageGetresultAsResponseAsync( inferenceId: inferenceId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,10 +67,12 @@ partial void ProcessGenaiText2imageGetresultResponseContent( /// Get the generated images. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiText2imageGetresultAsResponseAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -81,22 +87,43 @@ partial void ProcessGenaiText2imageGetresultResponseContent( securityRequirements: s_GenaiText2imageGetresultSecurityRequirements, operationName: "GenaiText2imageGetresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/genai/text2image/inferences/{inferenceId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/genai/text2image/inferences/{inferenceId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -106,574 +133,733 @@ partial void ProcessGenaiText2imageGetresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiText2imageGetresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - inferenceId: inferenceId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiText2imageGetresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiText2imageGetresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + inferenceId: inferenceId); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2imageGetresult", + methodName: "GenaiText2imageGetresultAsync", + pathTemplate: "$\"/genai/text2image/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2imageGetresult", + methodName: "GenaiText2imageGetresultAsync", + pathTemplate: "$\"/genai/text2image/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2imageGetresult", + methodName: "GenaiText2imageGetresultAsync", + pathTemplate: "$\"/genai/text2image/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } + break; } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiText2imageGetresultResponseContent( + response: __response); + ProcessGenaiText2imageGetresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiText2imageGetresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2imageGetresult", + methodName: "GenaiText2imageGetresultAsync", + pathTemplate: "$\"/genai/text2image/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiText2imageGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2imageGetresult", + methodName: "GenaiText2imageGetresultAsync", + pathTemplate: "$\"/genai/text2image/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiText2imageGetresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiText2imageGetresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiText2imageGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2sticker.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2sticker.g.cs index 93f2f75..c52981c 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2sticker.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2sticker.g.cs @@ -14,6 +14,7 @@ public partial class GenAIText2ImageClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -46,16 +47,19 @@ partial void ProcessGenaiText2stickerResponseContent( /// The result images can be as big as 1024x1024 pixels. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2stickerAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiText2stickerAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -67,11 +71,13 @@ partial void ProcessGenaiText2stickerResponseContent( /// The result images can be as big as 1024x1024 pixels. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiText2stickerAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -86,22 +92,43 @@ partial void ProcessGenaiText2stickerResponseContent( securityRequirements: s_GenaiText2stickerSecurityRequirements, operationName: "GenaiText2stickerAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/text2sticker", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/text2sticker", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -111,589 +138,750 @@ partial void ProcessGenaiText2stickerResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiText2stickerRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiText2stickerResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiText2stickerRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2sticker", + methodName: "GenaiText2stickerAsync", + pathTemplate: "\"/genai/text2sticker\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2sticker", + methodName: "GenaiText2stickerAsync", + pathTemplate: "\"/genai/text2sticker\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2sticker", + methodName: "GenaiText2stickerAsync", + pathTemplate: "\"/genai/text2sticker\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiText2stickerResponseContent( + response: __response); + ProcessGenaiText2stickerResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiText2stickerResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2sticker", + methodName: "GenaiText2stickerAsync", + pathTemplate: "\"/genai/text2sticker\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiText2stickerResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2sticker", + methodName: "GenaiText2stickerAsync", + pathTemplate: "\"/genai/text2sticker\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiText2stickerResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiText2stickerResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiText2stickerResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Text2Sticker
/// The *Text2Sticker* service helps generate a sticker based on the text introduced as input by the user.
/// The result images can be as big as 1024x1024 pixels. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2stickerAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -702,6 +890,7 @@ partial void ProcessGenaiText2stickerResponseContent( return await GenaiText2stickerAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2stickerGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2stickerGetresult.g.cs index 3589171..28f22af 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2stickerGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2stickerGetresult.g.cs @@ -14,6 +14,7 @@ public partial class GenAIText2ImageClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,14 +46,17 @@ partial void ProcessGenaiText2stickerGetresultResponseContent( /// Get the generated stickers. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2stickerGetresultAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiText2stickerGetresultAsResponseAsync( inferenceId: inferenceId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,10 +67,12 @@ partial void ProcessGenaiText2stickerGetresultResponseContent( /// Get the generated stickers. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiText2stickerGetresultAsResponseAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -81,22 +87,43 @@ partial void ProcessGenaiText2stickerGetresultResponseContent( securityRequirements: s_GenaiText2stickerGetresultSecurityRequirements, operationName: "GenaiText2stickerGetresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/genai/text2sticker/inferences/{inferenceId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/genai/text2sticker/inferences/{inferenceId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -106,574 +133,733 @@ partial void ProcessGenaiText2stickerGetresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiText2stickerGetresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - inferenceId: inferenceId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiText2stickerGetresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiText2stickerGetresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + inferenceId: inferenceId); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2stickerGetresult", + methodName: "GenaiText2stickerGetresultAsync", + pathTemplate: "$\"/genai/text2sticker/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2stickerGetresult", + methodName: "GenaiText2stickerGetresultAsync", + pathTemplate: "$\"/genai/text2sticker/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2stickerGetresult", + methodName: "GenaiText2stickerGetresultAsync", + pathTemplate: "$\"/genai/text2sticker/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } + break; } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiText2stickerGetresultResponseContent( + response: __response); + ProcessGenaiText2stickerGetresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiText2stickerGetresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2stickerGetresult", + methodName: "GenaiText2stickerGetresultAsync", + pathTemplate: "$\"/genai/text2sticker/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiText2stickerGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2stickerGetresult", + methodName: "GenaiText2stickerGetresultAsync", + pathTemplate: "$\"/genai/text2sticker/inferences/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiText2stickerGetresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiText2stickerGetresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiText2stickerGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2stickerLaserEngraving.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2stickerLaserEngraving.g.cs index e88fa9e..7451226 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2stickerLaserEngraving.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.GenaiText2stickerLaserEngraving.g.cs @@ -14,6 +14,7 @@ public partial class GenAIText2ImageClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -46,16 +47,19 @@ partial void ProcessGenaiText2stickerLaserEngravingResponseContent( /// The result images can be as big as 1024x1024 pixels. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2stickerLaserEngravingAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiText2stickerLaserEngravingAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -67,11 +71,13 @@ partial void ProcessGenaiText2stickerLaserEngravingResponseContent( /// The result images can be as big as 1024x1024 pixels. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiText2stickerLaserEngravingAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -86,22 +92,43 @@ partial void ProcessGenaiText2stickerLaserEngravingResponseContent( securityRequirements: s_GenaiText2stickerLaserEngravingSecurityRequirements, operationName: "GenaiText2stickerLaserEngravingAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/text2sticker/laserengraving", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/text2sticker/laserengraving", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -111,589 +138,750 @@ partial void ProcessGenaiText2stickerLaserEngravingResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiText2stickerLaserEngravingRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiText2stickerLaserEngravingResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiText2stickerLaserEngravingRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2stickerLaserEngraving", + methodName: "GenaiText2stickerLaserEngravingAsync", + pathTemplate: "\"/genai/text2sticker/laserengraving\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2stickerLaserEngraving", + methodName: "GenaiText2stickerLaserEngravingAsync", + pathTemplate: "\"/genai/text2sticker/laserengraving\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2stickerLaserEngraving", + methodName: "GenaiText2stickerLaserEngravingAsync", + pathTemplate: "\"/genai/text2sticker/laserengraving\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiText2stickerLaserEngravingResponseContent( + response: __response); + ProcessGenaiText2stickerLaserEngravingResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiText2stickerLaserEngravingResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2stickerLaserEngraving", + methodName: "GenaiText2stickerLaserEngravingAsync", + pathTemplate: "\"/genai/text2sticker/laserengraving\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiText2stickerLaserEngravingResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2stickerLaserEngraving", + methodName: "GenaiText2stickerLaserEngravingAsync", + pathTemplate: "\"/genai/text2sticker/laserengraving\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiText2stickerLaserEngravingResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiText2stickerLaserEngravingResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiText2stickerLaserEngravingResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Text2Sticker with Laser Engraving Effect
/// This service generates stickers similar to the standard /text2sticker service, and in addition to that it adds a laser engraving effect.
/// The result images can be as big as 1024x1024 pixels. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2stickerLaserEngravingAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -702,6 +890,7 @@ partial void ProcessGenaiText2stickerLaserEngravingResponseContent( return await GenaiText2stickerLaserEngravingAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.g.cs index e964d5f..14f264d 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2ImageClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class GenAIText2ImageClient : global::Picsart.IGenAIText2I #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public GenAIText2ImageClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the GenAIText2ImageClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public GenAIText2ImageClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2TextClient.GenaiText2textCompletions.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2TextClient.GenaiText2textCompletions.g.cs index be2cfa5..ac925d2 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2TextClient.GenaiText2textCompletions.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2TextClient.GenaiText2textCompletions.g.cs @@ -14,6 +14,7 @@ public partial class GenAIText2TextClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessGenaiText2textCompletionsResponseContent( /// The *Text2Text Completion* service helps generate a text based on the text introduced as input by the user. It also takes the pain out of writing to give your social, marketing, and advertising copy a premium edge. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2textCompletionsAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiText2textCompletionsAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessGenaiText2textCompletionsResponseContent( /// The *Text2Text Completion* service helps generate a text based on the text introduced as input by the user. It also takes the pain out of writing to give your social, marketing, and advertising copy a premium edge. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiText2textCompletionsAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessGenaiText2textCompletionsResponseContent( securityRequirements: s_GenaiText2textCompletionsSecurityRequirements, operationName: "GenaiText2textCompletionsAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/text2text/chat/completions", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/text2text/chat/completions", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,588 +136,749 @@ partial void ProcessGenaiText2textCompletionsResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiText2textCompletionsRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiText2textCompletionsResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiText2textCompletionsRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2textCompletions", + methodName: "GenaiText2textCompletionsAsync", + pathTemplate: "\"/genai/text2text/chat/completions\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2textCompletions", + methodName: "GenaiText2textCompletionsAsync", + pathTemplate: "\"/genai/text2text/chat/completions\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2textCompletions", + methodName: "GenaiText2textCompletionsAsync", + pathTemplate: "\"/genai/text2text/chat/completions\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiText2textCompletionsResponseContent( + response: __response); + ProcessGenaiText2textCompletionsResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiText2textCompletionsResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2textCompletions", + methodName: "GenaiText2textCompletionsAsync", + pathTemplate: "\"/genai/text2text/chat/completions\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiText2textCompletionsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2textCompletions", + methodName: "GenaiText2textCompletionsAsync", + pathTemplate: "\"/genai/text2text/chat/completions\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiText2textCompletionsResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiText2textCompletionsResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiText2textCompletionsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Text2Text Completions
/// The *Text2Text Completion* service helps generate a text based on the text introduced as input by the user. It also takes the pain out of writing to give your social, marketing, and advertising copy a premium edge. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2textCompletionsAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -699,6 +887,7 @@ partial void ProcessGenaiText2textCompletionsResponseContent( return await GenaiText2textCompletionsAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2TextClient.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2TextClient.g.cs index 5c2a728..54f4bd8 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2TextClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2TextClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class GenAIText2TextClient : global::Picsart.IGenAIText2Te #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public GenAIText2TextClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the GenAIText2TextClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public GenAIText2TextClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.GenaiImage2video.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.GenaiImage2video.g.cs index af9c8cc..e33d778 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.GenaiImage2video.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.GenaiImage2video.g.cs @@ -14,6 +14,7 @@ public partial class GenAIText2VideoImage2VideoClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -47,16 +48,19 @@ partial void ProcessGenaiImage2videoResponseContent( /// Similarly, note that different models do support different resolutions and output video quality parameters. In this case as well, the output video's resolutions and quality are not guaranteed to be exactly the same as provided input params. The service will provide what's "closer" to the original request. To make sure there are minimal deviations, we recommend doing test requests and checking the output video as well as doing research on original model's official documentation. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiImage2videoAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiImage2videoAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -69,11 +73,13 @@ partial void ProcessGenaiImage2videoResponseContent( /// Similarly, note that different models do support different resolutions and output video quality parameters. In this case as well, the output video's resolutions and quality are not guaranteed to be exactly the same as provided input params. The service will provide what's "closer" to the original request. To make sure there are minimal deviations, we recommend doing test requests and checking the output video as well as doing research on original model's official documentation. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiImage2videoAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -88,22 +94,43 @@ partial void ProcessGenaiImage2videoResponseContent( securityRequirements: s_GenaiImage2videoSecurityRequirements, operationName: "GenaiImage2videoAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/image2video", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/image2video", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -113,580 +140,739 @@ partial void ProcessGenaiImage2videoResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiImage2videoRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiImage2videoResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiImage2videoRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImage2video", + methodName: "GenaiImage2videoAsync", + pathTemplate: "\"/genai/image2video\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImage2video", + methodName: "GenaiImage2videoAsync", + pathTemplate: "\"/genai/image2video\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImage2video", + methodName: "GenaiImage2videoAsync", + pathTemplate: "\"/genai/image2video\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiImage2videoResponseContent( + response: __response); + ProcessGenaiImage2videoResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiImage2videoResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImage2video", + methodName: "GenaiImage2videoAsync", + pathTemplate: "\"/genai/image2video\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiImage2videoResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiImage2video", + methodName: "GenaiImage2videoAsync", + pathTemplate: "\"/genai/image2video\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiImage2videoResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiImage2videoResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiImage2videoResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Image2Video
@@ -694,9 +880,11 @@ partial void ProcessGenaiImage2videoResponseContent( /// Note, that considering the big number of different models that are supported with this service, some limitations may apply. For example, some models (e.g. Grok Imagine Video / OpenAI Sora 2 / Sora 2 Pro / OVI) don't support the option to disable sound. With these models the result video will always be generated regardless to the provided input params.
/// Similarly, note that different models do support different resolutions and output video quality parameters. In this case as well, the output video's resolutions and quality are not guaranteed to be exactly the same as provided input params. The service will provide what's "closer" to the original request. To make sure there are minimal deviations, we recommend doing test requests and checking the output video as well as doing research on original model's official documentation. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiImage2videoAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -705,6 +893,7 @@ partial void ProcessGenaiImage2videoResponseContent( return await GenaiImage2videoAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.GenaiText2video.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.GenaiText2video.g.cs index 00a5bae..5af4f1f 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.GenaiText2video.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.GenaiText2video.g.cs @@ -14,6 +14,7 @@ public partial class GenAIText2VideoImage2VideoClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -47,16 +48,19 @@ partial void ProcessGenaiText2videoResponseContent( /// Similarly, note that different models do support different resolutions and output video quality parameters. In this case as well, the output video's resolutions and quality are not guaranteed to be exactly the same as provided input params. The service will provide what's "closer" to the original request. To make sure there are minimal deviations, we recommend doing test requests and checking the output video as well as doing research on original model's official documentation. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2videoAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiText2videoAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -69,11 +73,13 @@ partial void ProcessGenaiText2videoResponseContent( /// Similarly, note that different models do support different resolutions and output video quality parameters. In this case as well, the output video's resolutions and quality are not guaranteed to be exactly the same as provided input params. The service will provide what's "closer" to the original request. To make sure there are minimal deviations, we recommend doing test requests and checking the output video as well as doing research on original model's official documentation. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiText2videoAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -88,22 +94,43 @@ partial void ProcessGenaiText2videoResponseContent( securityRequirements: s_GenaiText2videoSecurityRequirements, operationName: "GenaiText2videoAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/text2video", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/text2video", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -113,580 +140,739 @@ partial void ProcessGenaiText2videoResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiText2videoRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiText2videoResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiText2videoRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2video", + methodName: "GenaiText2videoAsync", + pathTemplate: "\"/genai/text2video\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2video", + methodName: "GenaiText2videoAsync", + pathTemplate: "\"/genai/text2video\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2video", + methodName: "GenaiText2videoAsync", + pathTemplate: "\"/genai/text2video\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiText2videoResponseContent( + response: __response); + ProcessGenaiText2videoResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiText2videoResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2video", + methodName: "GenaiText2videoAsync", + pathTemplate: "\"/genai/text2video\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiText2videoResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2video", + methodName: "GenaiText2videoAsync", + pathTemplate: "\"/genai/text2video\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiText2videoResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiText2videoResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiText2videoResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Text2Video
@@ -694,9 +880,11 @@ partial void ProcessGenaiText2videoResponseContent( /// Note, that considering the big number of different models that are supported with this service, some limitations may apply. For example, some models (e.g. Grok Imagine Video / OpenAI Sora 2 / Sora 2 Pro / OVI) don't support the option to disable sound. With these models the result video will always be generated regardless to the provided input params.
/// Similarly, note that different models do support different resolutions and output video quality parameters. In this case as well, the output video's resolutions and quality are not guaranteed to be exactly the same as provided input params. The service will provide what's "closer" to the original request. To make sure there are minimal deviations, we recommend doing test requests and checking the output video as well as doing research on original model's official documentation. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2videoAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -705,6 +893,7 @@ partial void ProcessGenaiText2videoResponseContent( return await GenaiText2videoAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.GenaiText2videoGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.GenaiText2videoGetresult.g.cs index d91a603..733c6c0 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.GenaiText2videoGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.GenaiText2videoGetresult.g.cs @@ -14,6 +14,7 @@ public partial class GenAIText2VideoImage2VideoClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,14 +46,17 @@ partial void ProcessGenaiText2videoGetresultResponseContent( /// Use this method, along with inference id, to retrieve the generated video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiText2videoGetresultAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiText2videoGetresultAsResponseAsync( inferenceId: inferenceId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,10 +67,12 @@ partial void ProcessGenaiText2videoGetresultResponseContent( /// Use this method, along with inference id, to retrieve the generated video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiText2videoGetresultAsResponseAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -81,22 +87,43 @@ partial void ProcessGenaiText2videoGetresultResponseContent( securityRequirements: s_GenaiText2videoGetresultSecurityRequirements, operationName: "GenaiText2videoGetresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/genai/video/{inferenceId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/genai/video/{inferenceId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -106,574 +133,733 @@ partial void ProcessGenaiText2videoGetresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiText2videoGetresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - inferenceId: inferenceId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiText2videoGetresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiText2videoGetresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + inferenceId: inferenceId); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2videoGetresult", + methodName: "GenaiText2videoGetresultAsync", + pathTemplate: "$\"/genai/video/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2videoGetresult", + methodName: "GenaiText2videoGetresultAsync", + pathTemplate: "$\"/genai/video/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2videoGetresult", + methodName: "GenaiText2videoGetresultAsync", + pathTemplate: "$\"/genai/video/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } + break; } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiText2videoGetresultResponseContent( + response: __response); + ProcessGenaiText2videoGetresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiText2videoGetresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2videoGetresult", + methodName: "GenaiText2videoGetresultAsync", + pathTemplate: "$\"/genai/video/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiText2videoGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiText2videoGetresult", + methodName: "GenaiText2videoGetresultAsync", + pathTemplate: "$\"/genai/video/{inferenceId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiText2videoGetresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiText2videoGetresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiText2videoGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.g.cs index 65b7d12..4c5fa34 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIText2VideoImage2VideoClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class GenAIText2VideoImage2VideoClient : global::Picsart.I #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public GenAIText2VideoImage2VideoClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the GenAIText2VideoImage2VideoClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public GenAIText2VideoImage2VideoClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.GenAIUtilitiesClient.GenaiCreditsBalance.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIUtilitiesClient.GenaiCreditsBalance.g.cs index ee1de52..0a3a373 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIUtilitiesClient.GenaiCreditsBalance.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIUtilitiesClient.GenaiCreditsBalance.g.cs @@ -14,6 +14,7 @@ public partial class GenAIUtilitiesClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -44,12 +45,15 @@ partial void ProcessGenaiCreditsBalanceResponseContent( /// **Authorization:**
/// Requires an API key to be provided in the **X-Picsart-API-Key** request header. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GenaiCreditsBalanceAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await GenaiCreditsBalanceAsResponseAsync( + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -61,9 +65,11 @@ partial void ProcessGenaiCreditsBalanceResponseContent( /// **Authorization:**
/// Requires an API key to be provided in the **X-Picsart-API-Key** request header. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> GenaiCreditsBalanceAsResponseAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -77,22 +83,43 @@ partial void ProcessGenaiCreditsBalanceResponseContent( securityRequirements: s_GenaiCreditsBalanceSecurityRequirements, operationName: "GenaiCreditsBalanceAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/genai/balance", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/genai/balance", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -102,573 +129,732 @@ partial void ProcessGenaiCreditsBalanceResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGenaiCreditsBalanceRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGenaiCreditsBalanceResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.GenAIError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.GenAIError? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.GenAIError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.GenAIError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.GenAIError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.GenAIError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.GenAIError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.GenAIError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGenaiCreditsBalanceRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.GenAIError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.GenAIError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiCreditsBalance", + methodName: "GenaiCreditsBalanceAsync", + pathTemplate: "\"/genai/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiCreditsBalance", + methodName: "GenaiCreditsBalanceAsync", + pathTemplate: "\"/genai/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.GenAIError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiCreditsBalance", + methodName: "GenaiCreditsBalanceAsync", + pathTemplate: "\"/genai/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + if (__response == null) { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.GenAIError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessGenaiCreditsBalanceResponseContent( + response: __response); + ProcessGenaiCreditsBalanceResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.GenaiCreditsBalanceResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiCreditsBalance", + methodName: "GenaiCreditsBalanceAsync", + pathTemplate: "\"/genai/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.GenaiCreditsBalanceResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GenaiCreditsBalance", + methodName: "GenaiCreditsBalanceAsync", + pathTemplate: "\"/genai/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.GenAIError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.GenAIError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.GenAIError? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.GenAIError.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.GenAIError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.GenAIError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.GenAIError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.GenAIError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.GenAIError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.GenAIError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.GenAIError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.GenAIError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.GenAIError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.GenAIError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.GenAIError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.GenAIError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.GenAIError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.GenAIError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.GenAIError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.GenAIError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.GenAIError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.GenAIError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.GenAIError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.GenAIError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGenaiCreditsBalanceResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.GenaiCreditsBalanceResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.GenaiCreditsBalanceResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.GenAIUtilitiesClient.g.cs b/src/libs/Picsart/Generated/Picsart.GenAIUtilitiesClient.g.cs index c794fc5..dc9c845 100644 --- a/src/libs/Picsart/Generated/Picsart.GenAIUtilitiesClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.GenAIUtilitiesClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class GenAIUtilitiesClient : global::Picsart.IGenAIUtiliti #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public GenAIUtilitiesClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the GenAIUtilitiesClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public GenAIUtilitiesClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiExpandImage.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiExpandImage.g.cs index 7c795cd..4fd2693 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiExpandImage.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiExpandImage.g.cs @@ -11,11 +11,13 @@ public partial interface IGenAIInpaintingImage2ImageClient /// This service is engineered to accommodate the need for larger image sizes without compromising on quality. The requirement that the specified width and height dimensions exceed the original image dimensions ensures that users can seamlessly scale their images up to meet various requirements, whether for professional presentations, digital marketing materials, web design, or personal use. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiExpandImageAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Expand Image
@@ -24,11 +26,13 @@ public partial interface IGenAIInpaintingImage2ImageClient /// This service is engineered to accommodate the need for larger image sizes without compromising on quality. The requirement that the specified width and height dimensions exceed the original image dimensions ensures that users can seamlessly scale their images up to meet various requirements, whether for professional presentations, digital marketing materials, web design, or personal use. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiExpandImageAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Expand Image
@@ -36,9 +40,11 @@ public partial interface IGenAIInpaintingImage2ImageClient ///
/// This service is engineered to accommodate the need for larger image sizes without compromising on quality. The requirement that the specified width and height dimensions exceed the original image dimensions ensures that users can seamlessly scale their images up to meet various requirements, whether for professional presentations, digital marketing materials, web design, or personal use. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiExpandImageAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiGenerateImageBleed.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiGenerateImageBleed.g.cs index 03519a5..2934c19 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiGenerateImageBleed.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiGenerateImageBleed.g.cs @@ -10,11 +10,13 @@ public partial interface IGenAIInpaintingImage2ImageClient /// This service enlarges the original images and generates additional pixels around the original from all sides. This helps print original images without needing to cut part of it during the print production process. The generated bleed area is a continuation of the original image and will ensure a consistent and high cut quality. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiGenerateImageBleedAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Generate Bleed
@@ -22,20 +24,24 @@ public partial interface IGenAIInpaintingImage2ImageClient /// This service enlarges the original images and generates additional pixels around the original from all sides. This helps print original images without needing to cut part of it during the print production process. The generated bleed area is a continuation of the original image and will ensure a consistent and high cut quality. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiGenerateImageBleedAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Generate Bleed
/// This service offers a groundbreaking functionality designed to enhance digital imagery by enabling users to enlarge any image.
/// This service enlarges the original images and generates additional pixels around the original from all sides. This helps print original images without needing to cut part of it during the print production process. The generated bleed area is a continuation of the original image and will ensure a consistent and high cut quality. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiGenerateImageBleedAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiImageInpainting.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiImageInpainting.g.cs index 1f3bdc8..f9bf178 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiImageInpainting.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiImageInpainting.g.cs @@ -9,30 +9,36 @@ public partial interface IGenAIInpaintingImage2ImageClient /// The **Inpainting** service offers inpainting (image2Image) capabilities, enabling users to fill or replace areas within an image based on specified criteria. It operates in two modes: * Single Image Mode: Submit one RGBA image. The API fills the specified inner area with content based on the prompt parameter. * Mask Mode: Along with the RGBA image, provide a mask of identical size and format. The API uses this mask to identify areas for inpainting with content determined by the prompt parameter. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiImageInpaintingAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Inpaint Image
/// The **Inpainting** service offers inpainting (image2Image) capabilities, enabling users to fill or replace areas within an image based on specified criteria. It operates in two modes: * Single Image Mode: Submit one RGBA image. The API fills the specified inner area with content based on the prompt parameter. * Mask Mode: Along with the RGBA image, provide a mask of identical size and format. The API uses this mask to identify areas for inpainting with content determined by the prompt parameter. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiImageInpaintingAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Inpaint Image
/// The **Inpainting** service offers inpainting (image2Image) capabilities, enabling users to fill or replace areas within an image based on specified criteria. It operates in two modes: * Single Image Mode: Submit one RGBA image. The API fills the specified inner area with content based on the prompt parameter. * Mask Mode: Along with the RGBA image, provide a mask of identical size and format. The API uses this mask to identify areas for inpainting with content determined by the prompt parameter. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiImageInpaintingAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiImageInpaintingGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiImageInpaintingGetresult.g.cs index d61385f..b4f697b 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiImageInpaintingGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiImageInpaintingGetresult.g.cs @@ -10,10 +10,12 @@ public partial interface IGenAIInpaintingImage2ImageClient /// Use this service to check up on the result. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiImageInpaintingGetresultAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the results of the painting
@@ -21,10 +23,12 @@ public partial interface IGenAIInpaintingImage2ImageClient /// Use this service to check up on the result. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiImageInpaintingGetresultAsResponseAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiImageOutpainting.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiImageOutpainting.g.cs index ec6a7f7..cf85288 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiImageOutpainting.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiImageOutpainting.g.cs @@ -12,11 +12,13 @@ public partial interface IGenAIInpaintingImage2ImageClient /// * Mask Mode: Provide an RGBA image along with a mask of the same size. The API applies this mask to paint beyond the masked region, using content determined by the prompt parameter. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiImageOutpaintingAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Outpaint Image
@@ -26,11 +28,13 @@ public partial interface IGenAIInpaintingImage2ImageClient /// * Mask Mode: Provide an RGBA image along with a mask of the same size. The API applies this mask to paint beyond the masked region, using content determined by the prompt parameter. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiImageOutpaintingAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Outpaint Image
@@ -39,9 +43,11 @@ public partial interface IGenAIInpaintingImage2ImageClient /// * Single Image Mode: Upload one RGBA image. The API enhances the outer area with content based on the prompt parameter.
/// * Mask Mode: Provide an RGBA image along with a mask of the same size. The API applies this mask to paint beyond the masked region, using content determined by the prompt parameter. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiImageOutpaintingAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiRemoveObject.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiRemoveObject.g.cs index 636723a..bb945e5 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiRemoveObject.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiRemoveObject.g.cs @@ -10,11 +10,13 @@ public partial interface IGenAIInpaintingImage2ImageClient /// Even though the same type of a result can also achieved via the <a href="https://docs.picsart.io/reference/genai-image-inpainting">Inpainting</a> service, this service uses a specially trained model to provide fine tuned results. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiRemoveObjectAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Remove Object from an Image
@@ -22,20 +24,24 @@ public partial interface IGenAIInpaintingImage2ImageClient /// Even though the same type of a result can also achieved via the <a href="https://docs.picsart.io/reference/genai-image-inpainting">Inpainting</a> service, this service uses a specially trained model to provide fine tuned results. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiRemoveObjectAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Remove Object from an Image
/// This service allows to remove objects from the original image by providing a mask.
/// Even though the same type of a result can also achieved via the <a href="https://docs.picsart.io/reference/genai-image-inpainting">Inpainting</a> service, this service uses a specially trained model to provide fine tuned results. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiRemoveObjectAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiSmartBackground.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiSmartBackground.g.cs index dcaa69a..6f2e573 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiSmartBackground.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.GenaiSmartBackground.g.cs @@ -13,11 +13,13 @@ public partial interface IGenAIInpaintingImage2ImageClient /// With Smart Background, users have the unique opportunity to reimagine their photos by simply submitting an image along with a narrative of the desired background. Our advanced AI algorithms then work to seamlessly integrate a bespoke, contextually appropriate scene behind the subject of the photo. This not only allows for unparalleled personalization but also offers a creative freedom unmatched by conventional methods. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiSmartBackgroundAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Smart Background
@@ -28,11 +30,13 @@ public partial interface IGenAIInpaintingImage2ImageClient /// With Smart Background, users have the unique opportunity to reimagine their photos by simply submitting an image along with a narrative of the desired background. Our advanced AI algorithms then work to seamlessly integrate a bespoke, contextually appropriate scene behind the subject of the photo. This not only allows for unparalleled personalization but also offers a creative freedom unmatched by conventional methods. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiSmartBackgroundAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Smart Background
@@ -42,9 +46,11 @@ public partial interface IGenAIInpaintingImage2ImageClient ///
/// With Smart Background, users have the unique opportunity to reimagine their photos by simply submitting an image along with a narrative of the desired background. Our advanced AI algorithms then work to seamlessly integrate a bespoke, contextually appropriate scene behind the subject of the photo. This not only allows for unparalleled personalization but also offers a creative freedom unmatched by conventional methods. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiSmartBackgroundAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.g.cs index eb83206..1cda2b4 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIInpaintingImage2ImageClient.g.cs @@ -33,6 +33,11 @@ public partial interface IGenAIInpaintingImage2ImageClient : global::System.IDis /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.GenaiText2audioGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.GenaiText2audioGetresult.g.cs index a24a632..b368b98 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.GenaiText2audioGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.GenaiText2audioGetresult.g.cs @@ -9,20 +9,24 @@ public partial interface IGenAIText2AudioClient /// Use this method, along with inference id, to retrieve the generated speech or sound/music. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2audioGetresultAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the Audio Generation result
/// Use this method, along with inference id, to retrieve the generated speech or sound/music. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiText2audioGetresultAsResponseAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.GenaiText2sound.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.GenaiText2sound.g.cs index b1d99f9..9fcaca7 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.GenaiText2sound.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.GenaiText2sound.g.cs @@ -9,30 +9,36 @@ public partial interface IGenAIText2AudioClient /// The *Text2Sound* service helps generate an music/sound based on the prompt introduced as input by the user. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2soundAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Text2Sound
/// The *Text2Sound* service helps generate an music/sound based on the prompt introduced as input by the user. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiText2soundAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Text2Sound
/// The *Text2Sound* service helps generate an music/sound based on the prompt introduced as input by the user. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2soundAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.GenaiText2speech.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.GenaiText2speech.g.cs index 687a2ae..020016c 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.GenaiText2speech.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.GenaiText2speech.g.cs @@ -9,30 +9,36 @@ public partial interface IGenAIText2AudioClient /// The *Text2Speech* service helps generate an audio based on the text introduced as input by the user. The audio will speak the text provided. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2speechAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Text2Speech
/// The *Text2Speech* service helps generate an audio based on the text introduced as input by the user. The audio will speak the text provided. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiText2speechAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Text2Speech
/// The *Text2Speech* service helps generate an audio based on the text introduced as input by the user. The audio will speak the text provided. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2speechAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.g.cs index 966072d..8f30f2b 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2AudioClient.g.cs @@ -33,6 +33,11 @@ public partial interface IGenAIText2AudioClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiGenerateLogo.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiGenerateLogo.g.cs index e7e2d9e..a657262 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiGenerateLogo.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiGenerateLogo.g.cs @@ -9,30 +9,36 @@ public partial interface IGenAIText2ImageClient /// Generate logos using company info, general description. You can add additional information to guide on the details you want to get on the logo. It is also possible to provide an example logo to generate similar logos. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiGenerateLogoAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Logo Generator
/// Generate logos using company info, general description. You can add additional information to guide on the details you want to get on the logo. It is also possible to provide an example logo to generate similar logos. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiGenerateLogoAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Logo Generator
/// Generate logos using company info, general description. You can add additional information to guide on the details you want to get on the logo. It is also possible to provide an example logo to generate similar logos. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiGenerateLogoAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiGenerateLogoGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiGenerateLogoGetresult.g.cs index f33f613..71ad6a7 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiGenerateLogoGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiGenerateLogoGetresult.g.cs @@ -9,20 +9,24 @@ public partial interface IGenAIText2ImageClient /// Get the results of your logo generation. Use the inference identifier from the [Logo Generator](https://docs.picsart.io/reference/genai-generate-logo). /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiGenerateLogoGetresultAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the Logo Generator result
/// Get the results of your logo generation. Use the inference identifier from the [Logo Generator](https://docs.picsart.io/reference/genai-generate-logo). ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiGenerateLogoGetresultAsResponseAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2image.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2image.g.cs index 3812e61..260b9f9 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2image.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2image.g.cs @@ -10,11 +10,13 @@ public partial interface IGenAIText2ImageClient /// The result images can be as big as 1024x1024 pixels. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2imageAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Text2Image
@@ -22,20 +24,24 @@ public partial interface IGenAIText2ImageClient /// The result images can be as big as 1024x1024 pixels. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiText2imageAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Text2Image
/// The *Text2Image* service helps generate an image based on the text introduced as input by the user.
/// The result images can be as big as 1024x1024 pixels. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2imageAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2imageGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2imageGetresult.g.cs index 16ea5c0..2d757c2 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2imageGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2imageGetresult.g.cs @@ -9,20 +9,24 @@ public partial interface IGenAIText2ImageClient /// Get the generated images. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2imageGetresultAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the Text2Image result
/// Get the generated images. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiText2imageGetresultAsResponseAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2sticker.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2sticker.g.cs index c1dc05d..2036d21 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2sticker.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2sticker.g.cs @@ -10,11 +10,13 @@ public partial interface IGenAIText2ImageClient /// The result images can be as big as 1024x1024 pixels. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2stickerAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Text2Sticker
@@ -22,20 +24,24 @@ public partial interface IGenAIText2ImageClient /// The result images can be as big as 1024x1024 pixels. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiText2stickerAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Text2Sticker
/// The *Text2Sticker* service helps generate a sticker based on the text introduced as input by the user.
/// The result images can be as big as 1024x1024 pixels. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2stickerAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2stickerGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2stickerGetresult.g.cs index a0bd0af..8db326a 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2stickerGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2stickerGetresult.g.cs @@ -9,20 +9,24 @@ public partial interface IGenAIText2ImageClient /// Get the generated stickers. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2stickerGetresultAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the Text2Sticker result
/// Get the generated stickers. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiText2stickerGetresultAsResponseAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2stickerLaserEngraving.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2stickerLaserEngraving.g.cs index 67a5c79..a0e620e 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2stickerLaserEngraving.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.GenaiText2stickerLaserEngraving.g.cs @@ -10,11 +10,13 @@ public partial interface IGenAIText2ImageClient /// The result images can be as big as 1024x1024 pixels. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2stickerLaserEngravingAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Text2Sticker with Laser Engraving Effect
@@ -22,20 +24,24 @@ public partial interface IGenAIText2ImageClient /// The result images can be as big as 1024x1024 pixels. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiText2stickerLaserEngravingAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Text2Sticker with Laser Engraving Effect
/// This service generates stickers similar to the standard /text2sticker service, and in addition to that it adds a laser engraving effect.
/// The result images can be as big as 1024x1024 pixels. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2stickerLaserEngravingAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.g.cs index 033dbc5..435d44a 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2ImageClient.g.cs @@ -33,6 +33,11 @@ public partial interface IGenAIText2ImageClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2TextClient.GenaiText2textCompletions.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2TextClient.GenaiText2textCompletions.g.cs index bfcb617..226a752 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2TextClient.GenaiText2textCompletions.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2TextClient.GenaiText2textCompletions.g.cs @@ -9,30 +9,36 @@ public partial interface IGenAIText2TextClient /// The *Text2Text Completion* service helps generate a text based on the text introduced as input by the user. It also takes the pain out of writing to give your social, marketing, and advertising copy a premium edge. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2textCompletionsAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Text2Text Completions
/// The *Text2Text Completion* service helps generate a text based on the text introduced as input by the user. It also takes the pain out of writing to give your social, marketing, and advertising copy a premium edge. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiText2textCompletionsAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Text2Text Completions
/// The *Text2Text Completion* service helps generate a text based on the text introduced as input by the user. It also takes the pain out of writing to give your social, marketing, and advertising copy a premium edge. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2textCompletionsAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2TextClient.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2TextClient.g.cs index ccd23f2..d5b7187 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2TextClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2TextClient.g.cs @@ -33,6 +33,11 @@ public partial interface IGenAIText2TextClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.GenaiImage2video.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.GenaiImage2video.g.cs index b6b861c..5b77eff 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.GenaiImage2video.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.GenaiImage2video.g.cs @@ -11,11 +11,13 @@ public partial interface IGenAIText2VideoImage2VideoClient /// Similarly, note that different models do support different resolutions and output video quality parameters. In this case as well, the output video's resolutions and quality are not guaranteed to be exactly the same as provided input params. The service will provide what's "closer" to the original request. To make sure there are minimal deviations, we recommend doing test requests and checking the output video as well as doing research on original model's official documentation. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiImage2videoAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Image2Video
@@ -24,11 +26,13 @@ public partial interface IGenAIText2VideoImage2VideoClient /// Similarly, note that different models do support different resolutions and output video quality parameters. In this case as well, the output video's resolutions and quality are not guaranteed to be exactly the same as provided input params. The service will provide what's "closer" to the original request. To make sure there are minimal deviations, we recommend doing test requests and checking the output video as well as doing research on original model's official documentation. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiImage2videoAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Image2Video
@@ -36,9 +40,11 @@ public partial interface IGenAIText2VideoImage2VideoClient /// Note, that considering the big number of different models that are supported with this service, some limitations may apply. For example, some models (e.g. Grok Imagine Video / OpenAI Sora 2 / Sora 2 Pro / OVI) don't support the option to disable sound. With these models the result video will always be generated regardless to the provided input params.
/// Similarly, note that different models do support different resolutions and output video quality parameters. In this case as well, the output video's resolutions and quality are not guaranteed to be exactly the same as provided input params. The service will provide what's "closer" to the original request. To make sure there are minimal deviations, we recommend doing test requests and checking the output video as well as doing research on original model's official documentation. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiImage2videoAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.GenaiText2video.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.GenaiText2video.g.cs index 9179656..2a4f2eb 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.GenaiText2video.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.GenaiText2video.g.cs @@ -11,11 +11,13 @@ public partial interface IGenAIText2VideoImage2VideoClient /// Similarly, note that different models do support different resolutions and output video quality parameters. In this case as well, the output video's resolutions and quality are not guaranteed to be exactly the same as provided input params. The service will provide what's "closer" to the original request. To make sure there are minimal deviations, we recommend doing test requests and checking the output video as well as doing research on original model's official documentation. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2videoAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Text2Video
@@ -24,11 +26,13 @@ public partial interface IGenAIText2VideoImage2VideoClient /// Similarly, note that different models do support different resolutions and output video quality parameters. In this case as well, the output video's resolutions and quality are not guaranteed to be exactly the same as provided input params. The service will provide what's "closer" to the original request. To make sure there are minimal deviations, we recommend doing test requests and checking the output video as well as doing research on original model's official documentation. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiText2videoAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Text2Video
@@ -36,9 +40,11 @@ public partial interface IGenAIText2VideoImage2VideoClient /// Note, that considering the big number of different models that are supported with this service, some limitations may apply. For example, some models (e.g. Grok Imagine Video / OpenAI Sora 2 / Sora 2 Pro / OVI) don't support the option to disable sound. With these models the result video will always be generated regardless to the provided input params.
/// Similarly, note that different models do support different resolutions and output video quality parameters. In this case as well, the output video's resolutions and quality are not guaranteed to be exactly the same as provided input params. The service will provide what's "closer" to the original request. To make sure there are minimal deviations, we recommend doing test requests and checking the output video as well as doing research on original model's official documentation. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2videoAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.GenaiText2videoGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.GenaiText2videoGetresult.g.cs index c76282b..3fc7520 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.GenaiText2videoGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.GenaiText2videoGetresult.g.cs @@ -9,20 +9,24 @@ public partial interface IGenAIText2VideoImage2VideoClient /// Use this method, along with inference id, to retrieve the generated video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiText2videoGetresultAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the Video Generation result
/// Use this method, along with inference id, to retrieve the generated video. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiText2videoGetresultAsResponseAsync( string inferenceId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.g.cs index 906ee79..34d7b40 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIText2VideoImage2VideoClient.g.cs @@ -33,6 +33,11 @@ public partial interface IGenAIText2VideoImage2VideoClient : global::System.IDis /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIUtilitiesClient.GenaiCreditsBalance.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIUtilitiesClient.GenaiCreditsBalance.g.cs index 79e0402..3a1e2de 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIUtilitiesClient.GenaiCreditsBalance.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIUtilitiesClient.GenaiCreditsBalance.g.cs @@ -10,9 +10,11 @@ public partial interface IGenAIUtilitiesClient /// **Authorization:**
/// Requires an API key to be provided in the **X-Picsart-API-Key** request header. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GenaiCreditsBalanceAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Credits Balance
@@ -20,9 +22,11 @@ public partial interface IGenAIUtilitiesClient /// **Authorization:**
/// Requires an API key to be provided in the **X-Picsart-API-Key** request header. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> GenaiCreditsBalanceAsResponseAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IGenAIUtilitiesClient.g.cs b/src/libs/Picsart/Generated/Picsart.IGenAIUtilitiesClient.g.cs index d869df8..34af0b9 100644 --- a/src/libs/Picsart/Generated/Picsart.IGenAIUtilitiesClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IGenAIUtilitiesClient.g.cs @@ -33,6 +33,11 @@ public partial interface IGenAIUtilitiesClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageCarsClassifier.g.cs b/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageCarsClassifier.g.cs index 2ab4475..05f80a9 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageCarsClassifier.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageCarsClassifier.g.cs @@ -12,11 +12,13 @@ public partial interface IImageClassificationClient /// It is mandatory that the provided input image is a car image. If the image is not a car image, the service will not generate an error, and the result may not be relevant. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageCarsClassifierAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Classify the Car Image
@@ -24,11 +26,13 @@ public partial interface IImageClassificationClient /// It is mandatory that the provided input image is a car image. If the image is not a car image, the service will not generate an error, and the result may not be relevant. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageCarsClassifierAsResponseAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Classify the Car Image
@@ -44,12 +48,14 @@ public partial interface IImageClassificationClient /// /// Source image URL. (If this parameter is present, the other image source parameters must be empty.) /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageCarsClassifierAsync( byte[]? image = default, string? imagename = default, string? imageUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageDescriber.g.cs b/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageDescriber.g.cs index b734cc7..4784af0 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageDescriber.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageDescriber.g.cs @@ -11,22 +11,26 @@ public partial interface IImageClassificationClient /// The image *Describer* service helps generate a detailed text description for the provided image (image2text). ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageDescriberAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Describe Image
/// The image *Describer* service helps generate a detailed text description for the provided image (image2text). ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageDescriberAsResponseAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Describe Image
@@ -41,12 +45,14 @@ public partial interface IImageClassificationClient /// /// Source image URL. (If this parameter is present, the other image source parameters must be empty.) /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageDescriberAsync( byte[]? image = default, string? imagename = default, string? imageUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageExtractColors.g.cs b/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageExtractColors.g.cs index 9656f1b..42895f1 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageExtractColors.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageExtractColors.g.cs @@ -12,11 +12,13 @@ public partial interface IImageClassificationClient /// The service analyzes an image and returns up to five prominent colors, including dominant foreground and background tones. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageExtractColorsAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Extract Image Colors
@@ -24,11 +26,13 @@ public partial interface IImageClassificationClient /// The service analyzes an image and returns up to five prominent colors, including dominant foreground and background tones. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageExtractColorsAsResponseAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Extract Image Colors
@@ -44,12 +48,14 @@ public partial interface IImageClassificationClient /// /// Source image URL. (If this parameter is present, the other image source parameters must be empty.) /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageExtractColorsAsync( byte[]? image = default, string? imagename = default, string? imageUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageSegmentation.g.cs b/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageSegmentation.g.cs index cca3af3..82188bf 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageSegmentation.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageSegmentation.g.cs @@ -9,30 +9,36 @@ public partial interface IImageClassificationClient /// Performs multi-matting segmentation on the input image, identifying and isolating specific classes like hair, clothes, or sky. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageSegmentationAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Image Segmentation
/// Performs multi-matting segmentation on the input image, identifying and isolating specific classes like hair, clothes, or sky. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageSegmentationAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Image Segmentation
/// Performs multi-matting segmentation on the input image, identifying and isolating specific classes like hair, clothes, or sky. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageSegmentationAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageTagging.g.cs b/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageTagging.g.cs index 47e3dc2..c77022d 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageTagging.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.ImageTagging.g.cs @@ -11,22 +11,26 @@ public partial interface IImageClassificationClient /// This tagging service analyzes the image and suggests hashtags that are relevant to the content. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageTaggingAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Image Tagging
/// This tagging service analyzes the image and suggests hashtags that are relevant to the content. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageTaggingAsResponseAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Image Tagging
@@ -41,12 +45,14 @@ public partial interface IImageClassificationClient /// /// Source image URL. (If this parameter is present, the other image source parameters must be empty.) /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageTaggingAsync( byte[]? image = default, string? imagename = default, string? imageUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.g.cs b/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.g.cs index 8ceb7da..3c4a4a6 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageClassificationClient.g.cs @@ -33,6 +33,11 @@ public partial interface IImageClassificationClient : global::System.IDisposable ///
public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IImageContentGenerationClient.ImageGeneratePattern.g.cs b/src/libs/Picsart/Generated/Picsart.IImageContentGenerationClient.ImageGeneratePattern.g.cs index 72797b4..c0af47a 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageContentGenerationClient.ImageGeneratePattern.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageContentGenerationClient.ImageGeneratePattern.g.cs @@ -9,30 +9,36 @@ public partial interface IImageContentGenerationClient /// The *pattern generator* tool generates a background texture pattern for the input image. You can create unlimited patterns from the same source image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageGeneratePatternAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Pattern Generator
/// The *pattern generator* tool generates a background texture pattern for the input image. You can create unlimited patterns from the same source image. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageGeneratePatternAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Pattern Generator
/// The *pattern generator* tool generates a background texture pattern for the input image. You can create unlimited patterns from the same source image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageGeneratePatternAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageContentGenerationClient.g.cs b/src/libs/Picsart/Generated/Picsart.IImageContentGenerationClient.g.cs index d5a80bc..8669c80 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageContentGenerationClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageContentGenerationClient.g.cs @@ -33,6 +33,11 @@ public partial interface IImageContentGenerationClient : global::System.IDisposa /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IImageConversionClient.ImageDesignImport.g.cs b/src/libs/Picsart/Generated/Picsart.IImageConversionClient.ImageDesignImport.g.cs index 74810d8..8cc668d 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageConversionClient.ImageDesignImport.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageConversionClient.ImageDesignImport.g.cs @@ -14,11 +14,13 @@ public partial interface IImageConversionClient /// * SVG (Scalable Vector Graphics) /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageDesignImportAsync( global::Picsart.ImageFileParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Design Import (beta)
@@ -30,11 +32,13 @@ public partial interface IImageConversionClient /// * SVG (Scalable Vector Graphics) ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageDesignImportAsResponseAsync( global::Picsart.ImageFileParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Design Import (beta)
@@ -54,12 +58,14 @@ public partial interface IImageConversionClient /// /// Source file URL. (If this parameter is present, the other source parameters must be empty.) /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageDesignImportAsync( byte[]? file = default, string? filename = default, string? fileUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageConversionClient.ImageDesignImportGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.IImageConversionClient.ImageDesignImportGetresult.g.cs index c70a217..59e9607 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageConversionClient.ImageDesignImportGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageConversionClient.ImageDesignImportGetresult.g.cs @@ -9,20 +9,24 @@ public partial interface IImageConversionClient /// Get the result of the Design Import. Use the inference identifier from the POST request to fetch the latest status and result here. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageDesignImportGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the Design Import Result
/// Get the result of the Design Import. Use the inference identifier from the POST request to fetch the latest status and result here. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageDesignImportGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageConversionClient.ImageVectorizeRasterToSvg.g.cs b/src/libs/Picsart/Generated/Picsart.IImageConversionClient.ImageVectorizeRasterToSvg.g.cs index e04a8fa..fa61bed 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageConversionClient.ImageVectorizeRasterToSvg.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageConversionClient.ImageVectorizeRasterToSvg.g.cs @@ -9,30 +9,36 @@ public partial interface IImageConversionClient /// With the *vectorizer* tool you can instantly turn your raster image into high quality vector graphic as it converts a PNG image to a SVG image. Using geometric figures, like curves and lines, the vectorizer converts the pixel information of raster input into vector image, which can be enlarged and edited without quality loss. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageVectorizeRasterToSvgAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Image Vectorizer
/// With the *vectorizer* tool you can instantly turn your raster image into high quality vector graphic as it converts a PNG image to a SVG image. Using geometric figures, like curves and lines, the vectorizer converts the pixel information of raster input into vector image, which can be enlarged and edited without quality loss. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageVectorizeRasterToSvgAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Image Vectorizer
/// With the *vectorizer* tool you can instantly turn your raster image into high quality vector graphic as it converts a PNG image to a SVG image. Using geometric figures, like curves and lines, the vectorizer converts the pixel information of raster input into vector image, which can be enlarged and edited without quality loss. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageVectorizeRasterToSvgAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageConversionClient.g.cs b/src/libs/Picsart/Generated/Picsart.IImageConversionClient.g.cs index aa08cfa..3fb3412 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageConversionClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageConversionClient.g.cs @@ -33,6 +33,11 @@ public partial interface IImageConversionClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageBlend.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageBlend.g.cs index 89ad6d7..da06725 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageBlend.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageBlend.g.cs @@ -11,11 +11,13 @@ public partial interface IImageEditingClient /// No need for manual edits or complex graphic design tools. With the blend API, your app or service can automate visually rich output that's both fast and fully customizable. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageBlendAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Blending
@@ -24,11 +26,13 @@ public partial interface IImageEditingClient /// No need for manual edits or complex graphic design tools. With the blend API, your app or service can automate visually rich output that's both fast and fully customizable. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageBlendAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Blending
@@ -36,9 +40,11 @@ public partial interface IImageEditingClient /// This endpoint lets you seamlessly combine a base image with another visual layer - like an overlay, mask, or logo - while giving you full control over how the two interact. Think of it as your virtual creative layer engine: the same power you'd expect from a professional design tool, now embedded into your workflow or platform.
/// No need for manual edits or complex graphic design tools. With the blend API, your app or service can automate visually rich output that's both fast and fully customizable. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageBlendAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageEdit.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageEdit.g.cs index 69486d7..31c1948 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageEdit.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageEdit.g.cs @@ -9,30 +9,36 @@ public partial interface IImageEditingClient /// The *Edit* service applies basic image editing to an input image. The basic editing operations are resize, crop, flip, rotate and perspective manipulation. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageEditAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Basic Editing
/// The *Edit* service applies basic image editing to an input image. The basic editing operations are resize, crop, flip, rotate and perspective manipulation. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageEditAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Basic Editing
/// The *Edit* service applies basic image editing to an input image. The basic editing operations are resize, crop, flip, rotate and perspective manipulation. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageEditAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageSmartCrop.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageSmartCrop.g.cs index 876216c..7644088 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageSmartCrop.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageSmartCrop.g.cs @@ -9,30 +9,36 @@ public partial interface IImageEditingClient /// Use AI to define the segment that should be cropped, e.g. foreground or product name (e.g. hat, gloves, boots, etc). /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageSmartCropAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Smart Crop
/// Use AI to define the segment that should be cropped, e.g. foreground or product name (e.g. hat, gloves, boots, etc). ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageSmartCropAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Smart Crop
/// Use AI to define the segment that should be cropped, e.g. foreground or product name (e.g. hat, gloves, boots, etc). ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageSmartCropAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageZoom.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageZoom.g.cs index 290e5b7..ecbdca5 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageZoom.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEditingClient.ImageZoom.g.cs @@ -9,30 +9,36 @@ public partial interface IImageEditingClient /// Zoom your images with 1-75 scale factors. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageZoomAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Zoom
/// Zoom your images with 1-75 scale factors. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageZoomAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Zoom
/// Zoom your images with 1-75 scale factors. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageZoomAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEditingClient.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEditingClient.g.cs index 03214ff..4eb4cc6 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEditingClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEditingClient.g.cs @@ -33,6 +33,11 @@ public partial interface IImageEditingClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageAdjust.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageAdjust.g.cs index 5dd5e42..977046c 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageAdjust.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageAdjust.g.cs @@ -9,30 +9,36 @@ public partial interface IImageEffectsClient /// The *adjust* service applies adjustments to an input image. There are 11 different adjustments in all available. The adjust service can be used with all photo types. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageAdjustAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Adjust
/// The *adjust* service applies adjustments to an input image. There are 11 different adjustments in all available. The adjust service can be used with all photo types. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageAdjustAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Adjust
/// The *adjust* service applies adjustments to an input image. There are 11 different adjustments in all available. The adjust service can be used with all photo types. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageAdjustAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyAiEffect.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyAiEffect.g.cs index 71f0cd6..f742390 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyAiEffect.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyAiEffect.g.cs @@ -9,30 +9,36 @@ public partial interface IImageEffectsClient /// With the *AI Effects* service you can apply up to 40+ different AI effects to an image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageApplyAiEffectAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// AI Effects
/// With the *AI Effects* service you can apply up to 40+ different AI effects to an image. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageApplyAiEffectAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// AI Effects
/// With the *AI Effects* service you can apply up to 40+ different AI effects to an image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageApplyAiEffectAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyEffect.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyEffect.g.cs index 11698ed..9e3d673 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyEffect.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyEffect.g.cs @@ -9,30 +9,36 @@ public partial interface IImageEffectsClient /// With the *effects* service you can apply up to 24 different effects to an image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageApplyEffectAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Effects
/// With the *effects* service you can apply up to 24 different effects to an image. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageApplyEffectAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Effects
/// With the *effects* service you can apply up to 24 different effects to an image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageApplyEffectAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyLaserEngravingEffect.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyLaserEngravingEffect.g.cs index 231f2f2..bb488f6 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyLaserEngravingEffect.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyLaserEngravingEffect.g.cs @@ -9,30 +9,36 @@ public partial interface IImageEffectsClient /// Apply a laser engraving effect to your stickers. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageApplyLaserEngravingEffectAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Laser Engraving Effect
/// Apply a laser engraving effect to your stickers. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageApplyLaserEngravingEffectAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Laser Engraving Effect
/// Apply a laser engraving effect to your stickers. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageApplyLaserEngravingEffectAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyMask.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyMask.g.cs index 331075d..71052aa 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyMask.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageApplyMask.g.cs @@ -9,30 +9,36 @@ public partial interface IImageEffectsClient /// The *masks* service applies a mask to an image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageApplyMaskAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Masks
/// The *masks* service applies a mask to an image. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageApplyMaskAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Masks
/// The *masks* service applies a mask to an image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageApplyMaskAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageCreateEffectPreviews.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageCreateEffectPreviews.g.cs index 83f83df..88cc427 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageCreateEffectPreviews.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageCreateEffectPreviews.g.cs @@ -9,30 +9,36 @@ public partial interface IImageEffectsClient /// The *effects previews* service applies an effect to a given input image and returns a preview (i.e., thumbnail) of the effect. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageCreateEffectPreviewsAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Effect Previews
/// The *effects previews* service applies an effect to a given input image and returns a preview (i.e., thumbnail) of the effect. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageCreateEffectPreviewsAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Effect Previews
/// The *effects previews* service applies an effect to a given input image and returns a preview (i.e., thumbnail) of the effect. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageCreateEffectPreviewsAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageCreateMaskPreviews.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageCreateMaskPreviews.g.cs index 03a8d09..abdef4b 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageCreateMaskPreviews.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageCreateMaskPreviews.g.cs @@ -9,30 +9,36 @@ public partial interface IImageEffectsClient /// The *masks previews* service applies mask effects to a given input image and returns a preview (i.e., thumbnail) of the effect. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageCreateMaskPreviewsAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Mask Previews
/// The *masks previews* service applies mask effects to a given input image and returns a preview (i.e., thumbnail) of the effect. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageCreateMaskPreviewsAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Mask Previews
/// The *masks previews* service applies mask effects to a given input image and returns a preview (i.e., thumbnail) of the effect. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageCreateMaskPreviewsAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageListAiEffectNames.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageListAiEffectNames.g.cs index 92133e1..92eed6b 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageListAiEffectNames.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageListAiEffectNames.g.cs @@ -8,17 +8,21 @@ public partial interface IImageEffectsClient /// AI Effect Names
/// This service retrieves the list of supported AI effects. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageListAiEffectNamesAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// AI Effect Names
/// This service retrieves the list of supported AI effects. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageListAiEffectNamesAsResponseAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageListEffectNames.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageListEffectNames.g.cs index 1982ff4..61bf0ec 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageListEffectNames.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageListEffectNames.g.cs @@ -8,17 +8,21 @@ public partial interface IImageEffectsClient /// Effect Names
/// This service retrieves a list of supported effects. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageListEffectNamesAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Effect Names
/// This service retrieves a list of supported effects. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageListEffectNamesAsResponseAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageSelectiveBlur.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageSelectiveBlur.g.cs index 7ea5f68..a69bc06 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageSelectiveBlur.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageSelectiveBlur.g.cs @@ -9,30 +9,36 @@ public partial interface IImageEffectsClient /// Use AI to define the segment that should be blurred, e.g. foreground or background, faces or car plates. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageSelectiveBlurAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Selective Blur
/// Use AI to define the segment that should be blurred, e.g. foreground or background, faces or car plates. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageSelectiveBlurAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Selective Blur
/// Use AI to define the segment that should be blurred, e.g. foreground or background, faces or car plates. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageSelectiveBlurAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageTransferColor.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageTransferColor.g.cs index 72b8092..0365d92 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageTransferColor.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageTransferColor.g.cs @@ -9,30 +9,36 @@ public partial interface IImageEffectsClient /// The *color transfer* tool transfers the color style from a reference image to the target image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageTransferColorAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Color Transfer
/// The *color transfer* tool transfers the color style from a reference image to the target image. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageTransferColorAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Color Transfer
/// The *color transfer* tool transfers the color style from a reference image to the target image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageTransferColorAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageTransferStyle.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageTransferStyle.g.cs index a0d0a88..e76d53a 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageTransferStyle.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.ImageTransferStyle.g.cs @@ -9,30 +9,36 @@ public partial interface IImageEffectsClient /// The *style transfer* tool transfers a style from a reference image to a content image. The smart algorithm blends the two images together so the output looks like the content image, but "painted" in the style of the reference image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageTransferStyleAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Style Transfer
/// The *style transfer* tool transfers a style from a reference image to a content image. The smart algorithm blends the two images together so the output looks like the content image, but "painted" in the style of the reference image. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageTransferStyleAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Style Transfer
/// The *style transfer* tool transfers a style from a reference image to a content image. The smart algorithm blends the two images together so the output looks like the content image, but "painted" in the style of the reference image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageTransferStyleAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.g.cs b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.g.cs index 47e48a3..9fac3e0 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageEffectsClient.g.cs @@ -33,6 +33,11 @@ public partial interface IImageEffectsClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageFaceEnhance.g.cs b/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageFaceEnhance.g.cs index d6c9530..ed37f48 100644 --- a/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageFaceEnhance.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageFaceEnhance.g.cs @@ -9,30 +9,36 @@ public partial interface IImagePhotoEnhancementClient /// With our *enhance face* tool, you can turn your old, blurry photos into clear portraits and selfies. ur AI technology will find faces, perform restoration and do color enhancement simultaneously. It will improve the skin texture and sharpen details while keeping a good balance of realness and fidelity with much less artifacts. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageFaceEnhanceAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Face Enhancement
/// With our *enhance face* tool, you can turn your old, blurry photos into clear portraits and selfies. ur AI technology will find faces, perform restoration and do color enhancement simultaneously. It will improve the skin texture and sharpen details while keeping a good balance of realness and fidelity with much less artifacts. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageFaceEnhanceAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Face Enhancement
/// With our *enhance face* tool, you can turn your old, blurry photos into clear portraits and selfies. ur AI technology will find faces, perform restoration and do color enhancement simultaneously. It will improve the skin texture and sharpen details while keeping a good balance of realness and fidelity with much less artifacts. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageFaceEnhanceAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUltraEnhance.g.cs b/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUltraEnhance.g.cs index aac96a3..124c8f8 100644 --- a/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUltraEnhance.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUltraEnhance.g.cs @@ -20,11 +20,13 @@ public partial interface IImagePhotoEnhancementClient /// If you plan to upscale enhance an image several times, we recommend you first upload the source image using the *Upload* method and then use the reference image ID. Otherwise, you can source the image by providing a file or a URL to an online image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageUltraEnhanceAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Ultra Enhance
@@ -42,11 +44,13 @@ public partial interface IImagePhotoEnhancementClient /// If you plan to upscale enhance an image several times, we recommend you first upload the source image using the *Upload* method and then use the reference image ID. Otherwise, you can source the image by providing a file or a URL to an online image. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageUltraEnhanceAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Ultra Enhance
@@ -63,9 +67,11 @@ public partial interface IImagePhotoEnhancementClient /// **Source Image:**
/// If you plan to upscale enhance an image several times, we recommend you first upload the source image using the *Upload* method and then use the reference image ID. Otherwise, you can source the image by providing a file or a URL to an online image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageUltraEnhanceAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUltraUpscale.g.cs b/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUltraUpscale.g.cs index 2767643..bccaae7 100644 --- a/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUltraUpscale.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUltraUpscale.g.cs @@ -9,30 +9,36 @@ public partial interface IImagePhotoEnhancementClient /// *Upscale Ultra* is a new upscaling technique which does upscaling with noise suppression. It works well on images with faces, small resolution images, stickers and objects with geometric shapes and clear edges. Upscale ultra increases the quality and resolution of low quality photos by leveraging predictive and generative AI technology in order to "complete" missing pixels for a best in class smoothing and enhancement effect. It works especially good on small resolution images with faces. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageUltraUpscaleAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Ultra Upscale
/// *Upscale Ultra* is a new upscaling technique which does upscaling with noise suppression. It works well on images with faces, small resolution images, stickers and objects with geometric shapes and clear edges. Upscale ultra increases the quality and resolution of low quality photos by leveraging predictive and generative AI technology in order to "complete" missing pixels for a best in class smoothing and enhancement effect. It works especially good on small resolution images with faces. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageUltraUpscaleAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Ultra Upscale
/// *Upscale Ultra* is a new upscaling technique which does upscaling with noise suppression. It works well on images with faces, small resolution images, stickers and objects with geometric shapes and clear edges. Upscale ultra increases the quality and resolution of low quality photos by leveraging predictive and generative AI technology in order to "complete" missing pixels for a best in class smoothing and enhancement effect. It works especially good on small resolution images with faces. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageUltraUpscaleAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUltraUpscaleGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUltraUpscaleGetresult.g.cs index b2e3a0e..17626f1 100644 --- a/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUltraUpscaleGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUltraUpscaleGetresult.g.cs @@ -9,20 +9,24 @@ public partial interface IImagePhotoEnhancementClient /// Use this method, along with transaction_id, to retrieve the upscale ultra finished image if the transformation was done asynchronously. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageUltraUpscaleGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the Ultra Upscale result
/// Use this method, along with transaction_id, to retrieve the upscale ultra finished image if the transformation was done asynchronously. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageUltraUpscaleGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUpscale.g.cs b/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUpscale.g.cs index 8cdf0e1..b226c6f 100644 --- a/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUpscale.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.ImageUpscale.g.cs @@ -9,30 +9,36 @@ public partial interface IImagePhotoEnhancementClient /// The *upscale* service increases the resolutions of an image by a given upscale factor, without increasing its file size. Upscale increases the quality and resolution of your photos by leveraging predictive and generative AI to add pixels to your image. It works especially well on images without noise. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageUpscaleAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Upscale
/// The *upscale* service increases the resolutions of an image by a given upscale factor, without increasing its file size. Upscale increases the quality and resolution of your photos by leveraging predictive and generative AI to add pixels to your image. It works especially well on images without noise. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageUpscaleAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Upscale
/// The *upscale* service increases the resolutions of an image by a given upscale factor, without increasing its file size. Upscale increases the quality and resolution of your photos by leveraging predictive and generative AI to add pixels to your image. It works especially well on images without noise. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageUpscaleAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.g.cs b/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.g.cs index 91c45ff..5a13dfc 100644 --- a/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImagePhotoEnhancementClient.g.cs @@ -33,6 +33,11 @@ public partial interface IImagePhotoEnhancementClient : global::System.IDisposab /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IImageRemoveBackgroundClient.ImageRemoveBackground.g.cs b/src/libs/Picsart/Generated/Picsart.IImageRemoveBackgroundClient.ImageRemoveBackground.g.cs index c21a188..4523bb6 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageRemoveBackgroundClient.ImageRemoveBackground.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageRemoveBackgroundClient.ImageRemoveBackground.g.cs @@ -9,30 +9,36 @@ public partial interface IImageRemoveBackgroundClient /// Discover the magic of seamless background removal with our removebg service, powered by cutting-edge AI technology. Our sophisticated algorithm effortlessly identifies and isolates the foreground, ensuring every detail from the delicate intricacies of jewelry to the finest strands of hair is captured with unparalleled precision. Designed to excel across a vast array of use cases, our service guarantees immaculate cutouts, whether for professional product photos, dynamic campaign graphics, or personal images meant for creative exploration. Experience flawless edges and exceptional detail preservation every time, elevating your images beyond the ordinary. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageRemoveBackgroundAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Remove & Change Background
/// Discover the magic of seamless background removal with our removebg service, powered by cutting-edge AI technology. Our sophisticated algorithm effortlessly identifies and isolates the foreground, ensuring every detail from the delicate intricacies of jewelry to the finest strands of hair is captured with unparalleled precision. Designed to excel across a vast array of use cases, our service guarantees immaculate cutouts, whether for professional product photos, dynamic campaign graphics, or personal images meant for creative exploration. Experience flawless edges and exceptional detail preservation every time, elevating your images beyond the ordinary. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageRemoveBackgroundAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Remove & Change Background
/// Discover the magic of seamless background removal with our removebg service, powered by cutting-edge AI technology. Our sophisticated algorithm effortlessly identifies and isolates the foreground, ensuring every detail from the delicate intricacies of jewelry to the finest strands of hair is captured with unparalleled precision. Designed to excel across a vast array of use cases, our service guarantees immaculate cutouts, whether for professional product photos, dynamic campaign graphics, or personal images meant for creative exploration. Experience flawless edges and exceptional detail preservation every time, elevating your images beyond the ordinary. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageRemoveBackgroundAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageRemoveBackgroundClient.g.cs b/src/libs/Picsart/Generated/Picsart.IImageRemoveBackgroundClient.g.cs index f009e8c..05ca307 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageRemoveBackgroundClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageRemoveBackgroundClient.g.cs @@ -33,6 +33,11 @@ public partial interface IImageRemoveBackgroundClient : global::System.IDisposab /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IImageSurfacemapClient.ImageSurfacemap.g.cs b/src/libs/Picsart/Generated/Picsart.IImageSurfacemapClient.ImageSurfacemap.g.cs index 73bb40e..15fad1d 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageSurfacemapClient.ImageSurfacemap.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageSurfacemapClient.ImageSurfacemap.g.cs @@ -9,30 +9,36 @@ public partial interface IImageSurfacemapClient /// With the *surface map* tool you can "print" a sticker over an (target) image. Using a mask, the Surfacemap tool maps the sticker pixels using the texture and curves on the target image thus ultimately giving a live-print-preview effect. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageSurfacemapAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Surfacemap Image
/// With the *surface map* tool you can "print" a sticker over an (target) image. Using a mask, the Surfacemap tool maps the sticker pixels using the texture and curves on the target image thus ultimately giving a live-print-preview effect. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageSurfacemapAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Surfacemap Image
/// With the *surface map* tool you can "print" a sticker over an (target) image. Using a mask, the Surfacemap tool maps the sticker pixels using the texture and curves on the target image thus ultimately giving a live-print-preview effect. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageSurfacemapAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageSurfacemapClient.g.cs b/src/libs/Picsart/Generated/Picsart.IImageSurfacemapClient.g.cs index f18548f..6497d05 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageSurfacemapClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageSurfacemapClient.g.cs @@ -33,6 +33,11 @@ public partial interface IImageSurfacemapClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IImageUtilitiesClient.ImageCreditsBalance.g.cs b/src/libs/Picsart/Generated/Picsart.IImageUtilitiesClient.ImageCreditsBalance.g.cs index 7819848..87d3827 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageUtilitiesClient.ImageCreditsBalance.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageUtilitiesClient.ImageCreditsBalance.g.cs @@ -8,17 +8,21 @@ public partial interface IImageUtilitiesClient /// Credits Balance
/// Check your balance of credits. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageCreditsBalanceAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Credits Balance
/// Check your balance of credits. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageCreditsBalanceAsResponseAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageUtilitiesClient.ImageUpload.g.cs b/src/libs/Picsart/Generated/Picsart.IImageUtilitiesClient.ImageUpload.g.cs index 765ff6f..19a3612 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageUtilitiesClient.ImageUpload.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageUtilitiesClient.ImageUpload.g.cs @@ -14,11 +14,13 @@ public partial interface IImageUtilitiesClient /// You can source the image by providing a file or a URL to an online image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageUploadAsync( global::Picsart.ImageUploadParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Upload Image
@@ -30,11 +32,13 @@ public partial interface IImageUtilitiesClient /// You can source the image by providing a file or a URL to an online image. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageUploadAsResponseAsync( global::Picsart.ImageUploadParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Upload Image
@@ -54,12 +58,14 @@ public partial interface IImageUtilitiesClient /// /// Source image URL. (If this parameter is present, the other image source parameters must be empty.) /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageUploadAsync( byte[]? image = default, string? imagename = default, string? imageUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageUtilitiesClient.g.cs b/src/libs/Picsart/Generated/Picsart.IImageUtilitiesClient.g.cs index 0df0708..a8fb29b 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageUtilitiesClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageUtilitiesClient.g.cs @@ -33,6 +33,11 @@ public partial interface IImageUtilitiesClient : global::System.IDisposable ///
public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IImageWatermarkClient.ImageAddWatermark.g.cs b/src/libs/Picsart/Generated/Picsart.IImageWatermarkClient.ImageAddWatermark.g.cs index 2057472..d8e1d5d 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageWatermarkClient.ImageAddWatermark.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageWatermarkClient.ImageAddWatermark.g.cs @@ -9,30 +9,36 @@ public partial interface IImageWatermarkClient /// Add watermark to your image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageAddWatermarkAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Add Watermark
/// Add watermark to your image. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> ImageAddWatermarkAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Add Watermark
/// Add watermark to your image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ImageAddWatermarkAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IImageWatermarkClient.g.cs b/src/libs/Picsart/Generated/Picsart.IImageWatermarkClient.g.cs index 592cf53..36f104a 100644 --- a/src/libs/Picsart/Generated/Picsart.IImageWatermarkClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IImageWatermarkClient.g.cs @@ -33,6 +33,11 @@ public partial interface IImageWatermarkClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IPicsartClient.g.cs b/src/libs/Picsart/Generated/Picsart.IPicsartClient.g.cs index 67923a9..0776250 100644 --- a/src/libs/Picsart/Generated/Picsart.IPicsartClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IPicsartClient.g.cs @@ -36,6 +36,11 @@ public partial interface IPicsartClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IVdReplayClient.VdExportReplay.g.cs b/src/libs/Picsart/Generated/Picsart.IVdReplayClient.VdExportReplay.g.cs index c0f35aa..eda5029 100644 --- a/src/libs/Picsart/Generated/Picsart.IVdReplayClient.VdExportReplay.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVdReplayClient.VdExportReplay.g.cs @@ -9,30 +9,36 @@ public partial interface IVdReplayClient /// Export your Replays with async API in background to optimize for performance and improve your user experience. Now you can export Print-Ready PDF only, but later more formats will be added to the support list. Feel free to reach out to our support team if you need updates to this API. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VdExportReplayAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Export Replay
/// Export your Replays with async API in background to optimize for performance and improve your user experience. Now you can export Print-Ready PDF only, but later more formats will be added to the support list. Feel free to reach out to our support team if you need updates to this API. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VdExportReplayAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Export Replay
/// Export your Replays with async API in background to optimize for performance and improve your user experience. Now you can export Print-Ready PDF only, but later more formats will be added to the support list. Feel free to reach out to our support team if you need updates to this API. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VdExportReplayAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVdReplayClient.VdExportReplayGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.IVdReplayClient.VdExportReplayGetresult.g.cs index d96d498..b1d699e 100644 --- a/src/libs/Picsart/Generated/Picsart.IVdReplayClient.VdExportReplayGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVdReplayClient.VdExportReplayGetresult.g.cs @@ -9,20 +9,24 @@ public partial interface IVdReplayClient /// Use this method, along with transaction_id, to retrieve the export replay's finished result (e.g. PDF). /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VdExportReplayGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the Export Replay result
/// Use this method, along with transaction_id, to retrieve the export replay's finished result (e.g. PDF). ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VdExportReplayGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVdReplayClient.g.cs b/src/libs/Picsart/Generated/Picsart.IVdReplayClient.g.cs index 2d1e88c..cef86cd 100644 --- a/src/libs/Picsart/Generated/Picsart.IVdReplayClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVdReplayClient.g.cs @@ -33,6 +33,11 @@ public partial interface IVdReplayClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IVdUtilitiesClient.VdCreditsBalance.g.cs b/src/libs/Picsart/Generated/Picsart.IVdUtilitiesClient.VdCreditsBalance.g.cs index a9672ea..d3b4869 100644 --- a/src/libs/Picsart/Generated/Picsart.IVdUtilitiesClient.VdCreditsBalance.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVdUtilitiesClient.VdCreditsBalance.g.cs @@ -8,17 +8,21 @@ public partial interface IVdUtilitiesClient /// Credits Balance
/// Check your balance of credits. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VdCreditsBalanceAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Credits Balance
/// Check your balance of credits. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VdCreditsBalanceAsResponseAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVdUtilitiesClient.g.cs b/src/libs/Picsart/Generated/Picsart.IVdUtilitiesClient.g.cs index 556ad07..8c35931 100644 --- a/src/libs/Picsart/Generated/Picsart.IVdUtilitiesClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVdUtilitiesClient.g.cs @@ -33,6 +33,11 @@ public partial interface IVdUtilitiesClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.VdDescribeVariableDataContent.g.cs b/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.VdDescribeVariableDataContent.g.cs index 03600f3..f28bd5f 100644 --- a/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.VdDescribeVariableDataContent.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.VdDescribeVariableDataContent.g.cs @@ -9,22 +9,26 @@ public partial interface IVdVariableDataContentClient /// Describes the Replay. Lists all variable data fields and their types: image, text, etc. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VdDescribeVariableDataContentAsync( global::Picsart.VDTemplateParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Describe Replay's Variable Data
/// Describes the Replay. Lists all variable data fields and their types: image, text, etc. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VdDescribeVariableDataContentAsResponseAsync( global::Picsart.VDTemplateParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Describe Replay's Variable Data
@@ -42,6 +46,7 @@ public partial interface IVdVariableDataContentClient /// /// Source replay URL. (If this parameter is present, the other template source parameters must be empty.) /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VdDescribeVariableDataContentAsync( @@ -49,6 +54,7 @@ public partial interface IVdVariableDataContentClient byte[]? template = default, string? templatename = default, string? templateUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.VdExportVariableDataContent.g.cs b/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.VdExportVariableDataContent.g.cs index b48b01b..55fec13 100644 --- a/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.VdExportVariableDataContent.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.VdExportVariableDataContent.g.cs @@ -10,11 +10,13 @@ public partial interface IVdVariableDataContentClient /// Customize the output with your data. Here you can provide a CSV file with up to 50 rows and map your data to the variables in the Replay file. For each row in the data file, this service will export a file of the requested type. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VdExportVariableDataContentAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Export Variable Data Content
@@ -22,20 +24,24 @@ public partial interface IVdVariableDataContentClient /// Customize the output with your data. Here you can provide a CSV file with up to 50 rows and map your data to the variables in the Replay file. For each row in the data file, this service will export a file of the requested type. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VdExportVariableDataContentAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Export Variable Data Content
/// Export your Replays with async API in background to optimize for performance and improve your user experience.
/// Customize the output with your data. Here you can provide a CSV file with up to 50 rows and map your data to the variables in the Replay file. For each row in the data file, this service will export a file of the requested type. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VdExportVariableDataContentAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.VdExportVariableDataContentGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.VdExportVariableDataContentGetresult.g.cs index c14e37a..a61b0cc 100644 --- a/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.VdExportVariableDataContentGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.VdExportVariableDataContentGetresult.g.cs @@ -9,20 +9,24 @@ public partial interface IVdVariableDataContentClient /// Use this method, along with transaction_id, to retrieve the export variable data content's finished results (e.g. list of PDF file URLs). /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VdExportVariableDataContentGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the Export Variable Data Content result
/// Use this method, along with transaction_id, to retrieve the export variable data content's finished results (e.g. list of PDF file URLs). ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VdExportVariableDataContentGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.g.cs b/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.g.cs index 955bd54..42be80a 100644 --- a/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVdVariableDataContentClient.g.cs @@ -33,6 +33,11 @@ public partial interface IVdVariableDataContentClient : global::System.IDisposab /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IVideoAdsClient.VideoEncodeCtv.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoAdsClient.VideoEncodeCtv.g.cs index a575004..ee77e00 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoAdsClient.VideoEncodeCtv.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoAdsClient.VideoEncodeCtv.g.cs @@ -9,22 +9,26 @@ public partial interface IVideoAdsClient /// Converts your original video to meet <a href="https://docs.picsart.io/docs/ctv-ads-format-requirements/">CTV requirements</a>. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoEncodeCtvAsync( global::Picsart.VideoVideoParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Make Video CTV-Compatible
/// Converts your original video to meet <a href="https://docs.picsart.io/docs/ctv-ads-format-requirements/">CTV requirements</a>. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoEncodeCtvAsResponseAsync( global::Picsart.VideoVideoParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Make Video CTV-Compatible
@@ -33,10 +37,12 @@ public partial interface IVideoAdsClient /// /// Source video URL. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoEncodeCtvAsync( string? videoUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoAdsClient.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoAdsClient.g.cs index 5292a7e..66ad949 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoAdsClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoAdsClient.g.cs @@ -33,6 +33,11 @@ public partial interface IVideoAdsClient : global::System.IDisposable ///
public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IVideoAudioClient.VideoAdjustAudio.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoAudioClient.VideoAdjustAudio.g.cs index a930080..5801bc7 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoAudioClient.VideoAdjustAudio.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoAudioClient.VideoAdjustAudio.g.cs @@ -9,30 +9,36 @@ public partial interface IVideoAudioClient /// Adjusts the input video's audio volume, allows to add a new audio channel and control its volume. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoAdjustAudioAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Adjust Audio
/// Adjusts the input video's audio volume, allows to add a new audio channel and control its volume. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoAdjustAudioAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Adjust Audio
/// Adjusts the input video's audio volume, allows to add a new audio channel and control its volume. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoAdjustAudioAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoAudioClient.VideoExtractAudio.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoAudioClient.VideoExtractAudio.g.cs index 0de38b0..dd901df 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoAudioClient.VideoExtractAudio.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoAudioClient.VideoExtractAudio.g.cs @@ -9,30 +9,36 @@ public partial interface IVideoAudioClient /// Extract the input video's audio channel. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoExtractAudioAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Extract Audio
/// Extract the input video's audio channel. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoExtractAudioAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Extract Audio
/// Extract the input video's audio channel. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoExtractAudioAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoAudioClient.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoAudioClient.g.cs index d4d2dd4..a4e3f3d 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoAudioClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoAudioClient.g.cs @@ -33,6 +33,11 @@ public partial interface IVideoAudioClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoConcat.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoConcat.g.cs index 7e36d3d..89bc1b6 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoConcat.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoConcat.g.cs @@ -9,30 +9,36 @@ public partial interface IVideoEditClient /// Concatenate several videos clips and images with transitions into one timeline. Helpful when adding intro/outro- or creating slideshows. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoConcatAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Concatenate Videos and Images
/// Concatenate several videos clips and images with transitions into one timeline. Helpful when adding intro/outro- or creating slideshows. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoConcatAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Concatenate Videos and Images
/// Concatenate several videos clips and images with transitions into one timeline. Helpful when adding intro/outro- or creating slideshows. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoConcatAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoConcatHighlights.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoConcatHighlights.g.cs index 72d47eb..0db526e 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoConcatHighlights.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoConcatHighlights.g.cs @@ -8,28 +8,34 @@ public partial interface IVideoEditClient /// Create a highlights video from the original one. This picks highlight clips and concatenates them into one output video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoConcatHighlightsAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Create a highlights video from the original one. This picks highlight clips and concatenates them into one output video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoConcatHighlightsAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Create a highlights video from the original one. This picks highlight clips and concatenates them into one output video. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoConcatHighlightsAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoCrop.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoCrop.g.cs index bf49271..30a5537 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoCrop.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoCrop.g.cs @@ -9,30 +9,36 @@ public partial interface IVideoEditClient /// Crop the input video clip to the desired size. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoCropAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Crop Video
/// Crop the input video clip to the desired size. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoCropAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Crop Video
/// Crop the input video clip to the desired size. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoCropAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoEdit.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoEdit.g.cs index 3609d7a..6b1fdf8 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoEdit.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoEdit.g.cs @@ -9,30 +9,36 @@ public partial interface IVideoEditClient /// Comprehensive editing with one operation. Apply effect, adjust, trim, crop, resize, change codecs, compression, framerates, etc. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoEditAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Edit Video
/// Comprehensive editing with one operation. Apply effect, adjust, trim, crop, resize, change codecs, compression, framerates, etc. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoEditAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Edit Video
/// Comprehensive editing with one operation. Apply effect, adjust, trim, crop, resize, change codecs, compression, framerates, etc. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoEditAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoFit.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoFit.g.cs index 4c9b60c..62b1bc4 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoFit.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoFit.g.cs @@ -9,30 +9,36 @@ public partial interface IVideoEditClient /// Fit your original video to different ratios or width and height options. Apply fit when resizing and cropping is not an option. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoFitAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Fit Video
/// Fit your original video to different ratios or width and height options. Apply fit when resizing and cropping is not an option. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoFitAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Fit Video
/// Fit your original video to different ratios or width and height options. Apply fit when resizing and cropping is not an option. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoFitAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoTrim.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoTrim.g.cs index ac1399a..75007b4 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoTrim.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoEditClient.VideoTrim.g.cs @@ -9,30 +9,36 @@ public partial interface IVideoEditClient /// Trim the input video clip: pull a specific segment or trim to your desired video clip duration. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoTrimAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Trim Video
/// Trim the input video clip: pull a specific segment or trim to your desired video clip duration. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoTrimAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Trim Video
/// Trim the input video clip: pull a specific segment or trim to your desired video clip duration. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoTrimAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoEditClient.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoEditClient.g.cs index 705efe4..b37aec0 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoEditClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoEditClient.g.cs @@ -33,6 +33,11 @@ public partial interface IVideoEditClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IVideoEffectsClient.VideoAdjust.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoEffectsClient.VideoAdjust.g.cs index ff0462f..4a394ac 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoEffectsClient.VideoAdjust.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoEffectsClient.VideoAdjust.g.cs @@ -20,11 +20,13 @@ public partial interface IVideoEffectsClient /// If you choose an adjustment setting value out of the allowed range, the default value of 0 is used instead. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoAdjustAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Adjust Video
@@ -42,11 +44,13 @@ public partial interface IVideoEffectsClient /// If you choose an adjustment setting value out of the allowed range, the default value of 0 is used instead. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoAdjustAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Adjust Video
@@ -63,9 +67,11 @@ public partial interface IVideoEffectsClient /// * Adjust vignette
/// If you choose an adjustment setting value out of the allowed range, the default value of 0 is used instead. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoAdjustAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoEffectsClient.VideoApplyEffect.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoEffectsClient.VideoApplyEffect.g.cs index 3758c9b..89f3ae7 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoEffectsClient.VideoApplyEffect.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoEffectsClient.VideoApplyEffect.g.cs @@ -9,30 +9,36 @@ public partial interface IVideoEffectsClient /// Apply up to 24 different effects to a video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoApplyEffectAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Video Effects
/// Apply up to 24 different effects to a video. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoApplyEffectAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Video Effects
/// Apply up to 24 different effects to a video. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoApplyEffectAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoEffectsClient.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoEffectsClient.g.cs index b2cd320..e71ecb0 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoEffectsClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoEffectsClient.g.cs @@ -33,6 +33,11 @@ public partial interface IVideoEffectsClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoGetThumbnail.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoGetThumbnail.g.cs index f4fe577..b33fa35 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoGetThumbnail.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoGetThumbnail.g.cs @@ -9,30 +9,36 @@ public partial interface IVideoMetadataClient /// Extracts (reads) Video Thumbnail. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoGetThumbnailAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get Video Thumbnail
/// Extracts (reads) Video Thumbnail. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoGetThumbnailAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get Video Thumbnail
/// Extracts (reads) Video Thumbnail. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoGetThumbnailAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoMetadata.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoMetadata.g.cs index f7ee821..991b504 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoMetadata.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoMetadata.g.cs @@ -9,22 +9,26 @@ public partial interface IVideoMetadataClient /// Analysis the Video and provides the Metadata. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoMetadataAsync( global::Picsart.VideoVideoParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get Video Metadata
/// Analysis the Video and provides the Metadata. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoMetadataAsResponseAsync( global::Picsart.VideoVideoParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get Video Metadata
@@ -33,10 +37,12 @@ public partial interface IVideoMetadataClient /// /// Source video URL. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoMetadataAsync( string? videoUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoSetThumbnail.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoSetThumbnail.g.cs index 87c6a62..67de304 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoSetThumbnail.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoSetThumbnail.g.cs @@ -9,30 +9,36 @@ public partial interface IVideoMetadataClient /// Update/Set the Video Thumbnail. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoSetThumbnailAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Set Video Thumbnail
/// Update/Set the Video Thumbnail. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoSetThumbnailAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Set Video Thumbnail
/// Update/Set the Video Thumbnail. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoSetThumbnailAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoSetThumbnailGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoSetThumbnailGetresult.g.cs index 4dad6ab..b91c4bb 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoSetThumbnailGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.VideoSetThumbnailGetresult.g.cs @@ -9,20 +9,24 @@ public partial interface IVideoMetadataClient /// Use this method, along with transaction_id, to retrieve the updated video with the new thumbnail. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoSetThumbnailGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the Video with updated Thumbnail
/// Use this method, along with transaction_id, to retrieve the updated video with the new thumbnail. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoSetThumbnailGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.g.cs index f34e0da..d9c8198 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoMetadataClient.g.cs @@ -33,6 +33,11 @@ public partial interface IVideoMetadataClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IVideoRemoveBackgroundClient.VideoRemoveBackground.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoRemoveBackgroundClient.VideoRemoveBackground.g.cs index 13ba7ac..3070666 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoRemoveBackgroundClient.VideoRemoveBackground.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoRemoveBackgroundClient.VideoRemoveBackground.g.cs @@ -9,30 +9,36 @@ public partial interface IVideoRemoveBackgroundClient /// Remove Background from videos, or replace with custom backdrops. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoRemoveBackgroundAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Remove & Change Background from Videos
/// Remove Background from videos, or replace with custom backdrops. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoRemoveBackgroundAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Remove & Change Background from Videos
/// Remove Background from videos, or replace with custom backdrops. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoRemoveBackgroundAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoRemoveBackgroundClient.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoRemoveBackgroundClient.g.cs index 0f2c222..f5c5a92 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoRemoveBackgroundClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoRemoveBackgroundClient.g.cs @@ -33,6 +33,11 @@ public partial interface IVideoRemoveBackgroundClient : global::System.IDisposab /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IVideoTranscriptionsClient.VideoTranscribeAudio.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoTranscriptionsClient.VideoTranscribeAudio.g.cs index f83bc27..030edb5 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoTranscriptionsClient.VideoTranscribeAudio.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoTranscriptionsClient.VideoTranscribeAudio.g.cs @@ -18,11 +18,13 @@ public partial interface IVideoTranscriptionsClient /// Note, that the maximum audio/video file size supported is 25mb. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoTranscribeAudioAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Transcribe Audio
@@ -38,11 +40,13 @@ public partial interface IVideoTranscriptionsClient /// Note, that the maximum audio/video file size supported is 25mb. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoTranscribeAudioAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Transcribe Audio
@@ -57,9 +61,11 @@ public partial interface IVideoTranscriptionsClient /// * video/webm
/// Note, that the maximum audio/video file size supported is 25mb. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoTranscribeAudioAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoTranscriptionsClient.VideoTranscribeAudioGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoTranscriptionsClient.VideoTranscribeAudioGetresult.g.cs index 57d558a..f55f696 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoTranscriptionsClient.VideoTranscribeAudioGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoTranscriptionsClient.VideoTranscribeAudioGetresult.g.cs @@ -9,20 +9,24 @@ public partial interface IVideoTranscriptionsClient /// Use this method, along with transaction_id, to retrieve the audio transcription. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoTranscribeAudioGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the Transcribe Audio result
/// Use this method, along with transaction_id, to retrieve the audio transcription. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoTranscribeAudioGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoTranscriptionsClient.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoTranscriptionsClient.g.cs index 88b4ba9..64b5d5a 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoTranscriptionsClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoTranscriptionsClient.g.cs @@ -33,6 +33,11 @@ public partial interface IVideoTranscriptionsClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoCreditsBalance.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoCreditsBalance.g.cs index 34d83da..5f562d6 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoCreditsBalance.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoCreditsBalance.g.cs @@ -8,17 +8,21 @@ public partial interface IVideoUtilitiesClient /// Credits Balance
/// Check your balance of credits. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoCreditsBalanceAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Credits Balance
/// Check your balance of credits. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoCreditsBalanceAsResponseAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoGetaudioresult.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoGetaudioresult.g.cs index 2da255d..c970acd 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoGetaudioresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoGetaudioresult.g.cs @@ -9,20 +9,24 @@ public partial interface IVideoUtilitiesClient /// Use the video editing transaction ID to get the result audio file URL. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoGetaudioresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the Audio result
/// Use the video editing transaction ID to get the result audio file URL. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoGetaudioresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoGetresult.g.cs index 6973bdb..6fbff18 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoGetresult.g.cs @@ -9,20 +9,24 @@ public partial interface IVideoUtilitiesClient /// Use the video editing transaction ID to get the result video URL. This method works for effects, adjust, trim, crop, resize, fit, concatenation, highlights services. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the Video result
/// Use the video editing transaction ID to get the result video URL. This method works for effects, adjust, trim, crop, resize, fit, concatenation, highlights services. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoUpload.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoUpload.g.cs index 9a78215..3d955c7 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoUpload.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.VideoUpload.g.cs @@ -9,22 +9,26 @@ public partial interface IVideoUtilitiesClient /// Upload resources such as videos, audios or images. The provided URL can be passed as inputs to video operation. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoUploadAsync( global::Picsart.VideoUploadParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Upload files
/// Upload resources such as videos, audios or images. The provided URL can be passed as inputs to video operation. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoUploadAsResponseAsync( global::Picsart.VideoUploadParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Upload files
@@ -36,11 +40,13 @@ public partial interface IVideoUtilitiesClient /// /// Source file (binary). /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoUploadAsync( byte[]? file = default, string? filename = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.g.cs index 0135b60..bdcb86e 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoUtilitiesClient.g.cs @@ -33,6 +33,11 @@ public partial interface IVideoUtilitiesClient : global::System.IDisposable ///
public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IVideoVideoEnhancementClient.VideoUpscaleFps.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoVideoEnhancementClient.VideoUpscaleFps.g.cs index 22a3d56..ee2dff5 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoVideoEnhancementClient.VideoUpscaleFps.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoVideoEnhancementClient.VideoUpscaleFps.g.cs @@ -9,22 +9,26 @@ public partial interface IVideoVideoEnhancementClient /// Upscale your low FPS videos to 60FPS high-quality videos using Generative AI technology. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoUpscaleFpsAsync( global::Picsart.VideoVideoParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Video FPS Upscale
/// Upscale your low FPS videos to 60FPS high-quality videos using Generative AI technology. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoUpscaleFpsAsResponseAsync( global::Picsart.VideoVideoParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Video FPS Upscale
@@ -33,10 +37,12 @@ public partial interface IVideoVideoEnhancementClient /// /// Source video URL. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoUpscaleFpsAsync( string? videoUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoVideoEnhancementClient.VideoUpscaleFpsGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoVideoEnhancementClient.VideoUpscaleFpsGetresult.g.cs index 057f4d2..d454ae4 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoVideoEnhancementClient.VideoUpscaleFpsGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoVideoEnhancementClient.VideoUpscaleFpsGetresult.g.cs @@ -9,20 +9,24 @@ public partial interface IVideoVideoEnhancementClient /// Use this method, along with transaction_id, to retrieve the upscaled video. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoUpscaleFpsGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Get the Video FPS Upscale result
/// Use this method, along with transaction_id, to retrieve the upscaled video. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoUpscaleFpsGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoVideoEnhancementClient.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoVideoEnhancementClient.g.cs index a2f3653..e0edcdb 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoVideoEnhancementClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoVideoEnhancementClient.g.cs @@ -33,6 +33,11 @@ public partial interface IVideoVideoEnhancementClient : global::System.IDisposab /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.IVideoWatermarkClient.VideoAddWatermark.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoWatermarkClient.VideoAddWatermark.g.cs index ca934b8..7f35930 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoWatermarkClient.VideoAddWatermark.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoWatermarkClient.VideoAddWatermark.g.cs @@ -9,30 +9,36 @@ public partial interface IVideoWatermarkClient /// Add watermark to your video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoAddWatermarkAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Add Watermark
/// Add watermark to your video. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task> VideoAddWatermarkAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Add Watermark
/// Add watermark to your video. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task VideoAddWatermarkAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.IVideoWatermarkClient.g.cs b/src/libs/Picsart/Generated/Picsart.IVideoWatermarkClient.g.cs index 4544057..770c0da 100644 --- a/src/libs/Picsart/Generated/Picsart.IVideoWatermarkClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.IVideoWatermarkClient.g.cs @@ -33,6 +33,11 @@ public partial interface IVideoWatermarkClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Picsart.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageCarsClassifier.g.cs b/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageCarsClassifier.g.cs index 73684f5..4d8f37b 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageCarsClassifier.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageCarsClassifier.g.cs @@ -16,6 +16,7 @@ public partial class ImageClassificationClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -48,16 +49,19 @@ partial void ProcessImageCarsClassifierResponseContent( /// It is mandatory that the provided input image is a car image. If the image is not a car image, the service will not generate an error, and the result may not be relevant. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageCarsClassifierAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageCarsClassifierAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -69,11 +73,13 @@ partial void ProcessImageCarsClassifierResponseContent( /// It is mandatory that the provided input image is a car image. If the image is not a car image, the service will not generate an error, and the result may not be relevant. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageCarsClassifierAsResponseAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -90,22 +96,43 @@ partial void ProcessImageCarsClassifierResponseContent( securityRequirements: s_ImageCarsClassifierSecurityRequirements, operationName: "ImageCarsClassifierAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/cars/classify", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/cars/classify", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -115,640 +142,799 @@ partial void ProcessImageCarsClassifierResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - if (request.Image != default) - { - - var __contentImage = new global::System.Net.Http.ByteArrayContent(request.Image ?? global::System.Array.Empty()); - __httpRequestContent.Add( - content: __contentImage, - name: "\"image\"", - fileName: request.Imagename != null ? $"\"{request.Imagename}\"" : string.Empty); - if (__contentImage.Headers.ContentDisposition != null) - { - __contentImage.Headers.ContentDisposition.FileNameStar = null; - } - } - if (request.ImageUrl != default) - { - - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.ImageUrl}"), - name: "\"image_url\""); - } - if (request.ImageId != default) - { - - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.ImageId}"), - name: "\"image_id\""); - } - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageCarsClassifierRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageCarsClassifierResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (request.Image != default) + { + + var __contentImage = new global::System.Net.Http.ByteArrayContent(request.Image ?? global::System.Array.Empty()); + __httpRequestContent.Add( + content: __contentImage, + name: "\"image\"", + fileName: request.Imagename != null ? $"\"{request.Imagename}\"" : string.Empty); + if (__contentImage.Headers.ContentDisposition != null) + { + __contentImage.Headers.ContentDisposition.FileNameStar = null; + } + } + if (request.ImageUrl != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.ImageUrl}"), + name: "\"image_url\""); + } + if (request.ImageId != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.ImageId}"), + name: "\"image_id\""); + } + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageCarsClassifierRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCarsClassifier", + methodName: "ImageCarsClassifierAsync", + pathTemplate: "\"/image/cars/classify\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCarsClassifier", + methodName: "ImageCarsClassifierAsync", + pathTemplate: "\"/image/cars/classify\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCarsClassifier", + methodName: "ImageCarsClassifierAsync", + pathTemplate: "\"/image/cars/classify\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageCarsClassifierResponseContent( + response: __response); + ProcessImageCarsClassifierResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCarsClassifier", + methodName: "ImageCarsClassifierAsync", + pathTemplate: "\"/image/cars/classify\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCarsClassifier", + methodName: "ImageCarsClassifierAsync", + pathTemplate: "\"/image/cars/classify\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageCarsClassifierResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageCarsClassifierResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageCarsClassifierResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageCarsClassifierResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageCarsClassifierResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// @@ -765,12 +951,14 @@ partial void ProcessImageCarsClassifierResponseContent( /// /// Source image URL. (If this parameter is present, the other image source parameters must be empty.) /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageCarsClassifierAsync( byte[]? image = default, string? imagename = default, string? imageUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.ImageImageParameters @@ -782,6 +970,7 @@ partial void ProcessImageCarsClassifierResponseContent( return await ImageCarsClassifierAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageDescriber.g.cs b/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageDescriber.g.cs index 2701bff..2b4a717 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageDescriber.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageDescriber.g.cs @@ -16,6 +16,7 @@ public partial class ImageClassificationClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -47,16 +48,19 @@ partial void ProcessImageDescriberResponseContent( /// The image *Describer* service helps generate a detailed text description for the provided image (image2text). /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageDescriberAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageDescriberAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -67,11 +71,13 @@ partial void ProcessImageDescriberResponseContent( /// The image *Describer* service helps generate a detailed text description for the provided image (image2text). /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageDescriberAsResponseAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -88,22 +94,43 @@ partial void ProcessImageDescriberResponseContent( securityRequirements: s_ImageDescriberSecurityRequirements, operationName: "ImageDescriberAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/describe", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/describe", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -113,640 +140,799 @@ partial void ProcessImageDescriberResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - if (request.Image != default) - { - - var __contentImage = new global::System.Net.Http.ByteArrayContent(request.Image ?? global::System.Array.Empty()); - __httpRequestContent.Add( - content: __contentImage, - name: "\"image\"", - fileName: request.Imagename != null ? $"\"{request.Imagename}\"" : string.Empty); - if (__contentImage.Headers.ContentDisposition != null) - { - __contentImage.Headers.ContentDisposition.FileNameStar = null; - } - } - if (request.ImageUrl != default) - { - - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.ImageUrl}"), - name: "\"image_url\""); - } - if (request.ImageId != default) - { - - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.ImageId}"), - name: "\"image_id\""); - } - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageDescriberRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageDescriberResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (request.Image != default) + { + + var __contentImage = new global::System.Net.Http.ByteArrayContent(request.Image ?? global::System.Array.Empty()); + __httpRequestContent.Add( + content: __contentImage, + name: "\"image\"", + fileName: request.Imagename != null ? $"\"{request.Imagename}\"" : string.Empty); + if (__contentImage.Headers.ContentDisposition != null) + { + __contentImage.Headers.ContentDisposition.FileNameStar = null; + } + } + if (request.ImageUrl != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.ImageUrl}"), + name: "\"image_url\""); + } + if (request.ImageId != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.ImageId}"), + name: "\"image_id\""); + } + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageDescriberRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDescriber", + methodName: "ImageDescriberAsync", + pathTemplate: "\"/image/describe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDescriber", + methodName: "ImageDescriberAsync", + pathTemplate: "\"/image/describe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDescriber", + methodName: "ImageDescriberAsync", + pathTemplate: "\"/image/describe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageDescriberResponseContent( + response: __response); + ProcessImageDescriberResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDescriber", + methodName: "ImageDescriberAsync", + pathTemplate: "\"/image/describe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDescriber", + methodName: "ImageDescriberAsync", + pathTemplate: "\"/image/describe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageDescriberResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageDescriberResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageDescriberResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageDescriberResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageDescriberResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// @@ -762,12 +948,14 @@ partial void ProcessImageDescriberResponseContent( /// /// Source image URL. (If this parameter is present, the other image source parameters must be empty.) /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageDescriberAsync( byte[]? image = default, string? imagename = default, string? imageUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.ImageImageParameters @@ -779,6 +967,7 @@ partial void ProcessImageDescriberResponseContent( return await ImageDescriberAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageExtractColors.g.cs b/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageExtractColors.g.cs index 40602aa..330c5ab 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageExtractColors.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageExtractColors.g.cs @@ -16,6 +16,7 @@ public partial class ImageClassificationClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -48,16 +49,19 @@ partial void ProcessImageExtractColorsResponseContent( /// The service analyzes an image and returns up to five prominent colors, including dominant foreground and background tones. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageExtractColorsAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageExtractColorsAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -69,11 +73,13 @@ partial void ProcessImageExtractColorsResponseContent( /// The service analyzes an image and returns up to five prominent colors, including dominant foreground and background tones. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageExtractColorsAsResponseAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -90,22 +96,43 @@ partial void ProcessImageExtractColorsResponseContent( securityRequirements: s_ImageExtractColorsSecurityRequirements, operationName: "ImageExtractColorsAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/extract-colors", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/extract-colors", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -115,640 +142,799 @@ partial void ProcessImageExtractColorsResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - if (request.Image != default) - { - - var __contentImage = new global::System.Net.Http.ByteArrayContent(request.Image ?? global::System.Array.Empty()); - __httpRequestContent.Add( - content: __contentImage, - name: "\"image\"", - fileName: request.Imagename != null ? $"\"{request.Imagename}\"" : string.Empty); - if (__contentImage.Headers.ContentDisposition != null) - { - __contentImage.Headers.ContentDisposition.FileNameStar = null; - } - } - if (request.ImageUrl != default) - { - - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.ImageUrl}"), - name: "\"image_url\""); - } - if (request.ImageId != default) - { - - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.ImageId}"), - name: "\"image_id\""); - } - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageExtractColorsRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageExtractColorsResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (request.Image != default) + { + + var __contentImage = new global::System.Net.Http.ByteArrayContent(request.Image ?? global::System.Array.Empty()); + __httpRequestContent.Add( + content: __contentImage, + name: "\"image\"", + fileName: request.Imagename != null ? $"\"{request.Imagename}\"" : string.Empty); + if (__contentImage.Headers.ContentDisposition != null) + { + __contentImage.Headers.ContentDisposition.FileNameStar = null; + } + } + if (request.ImageUrl != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.ImageUrl}"), + name: "\"image_url\""); + } + if (request.ImageId != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.ImageId}"), + name: "\"image_id\""); + } + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageExtractColorsRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageExtractColors", + methodName: "ImageExtractColorsAsync", + pathTemplate: "\"/image/extract-colors\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageExtractColors", + methodName: "ImageExtractColorsAsync", + pathTemplate: "\"/image/extract-colors\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageExtractColors", + methodName: "ImageExtractColorsAsync", + pathTemplate: "\"/image/extract-colors\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageExtractColorsResponseContent( + response: __response); + ProcessImageExtractColorsResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageExtractColors", + methodName: "ImageExtractColorsAsync", + pathTemplate: "\"/image/extract-colors\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageExtractColors", + methodName: "ImageExtractColorsAsync", + pathTemplate: "\"/image/extract-colors\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageExtractColorsResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageExtractColorsResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageExtractColorsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageExtractColorsResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageExtractColorsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// @@ -765,12 +951,14 @@ partial void ProcessImageExtractColorsResponseContent( /// /// Source image URL. (If this parameter is present, the other image source parameters must be empty.) /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageExtractColorsAsync( byte[]? image = default, string? imagename = default, string? imageUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.ImageImageParameters @@ -782,6 +970,7 @@ partial void ProcessImageExtractColorsResponseContent( return await ImageExtractColorsAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageSegmentation.g.cs b/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageSegmentation.g.cs index 96bd777..6b661a2 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageSegmentation.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageSegmentation.g.cs @@ -14,6 +14,7 @@ public partial class ImageClassificationClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageSegmentationResponseContent( /// Performs multi-matting segmentation on the input image, identifying and isolating specific classes like hair, clothes, or sky. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageSegmentationAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageSegmentationAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageSegmentationResponseContent( /// Performs multi-matting segmentation on the input image, identifying and isolating specific classes like hair, clothes, or sky. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageSegmentationAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageSegmentationResponseContent( securityRequirements: s_ImageSegmentationSecurityRequirements, operationName: "ImageSegmentationAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/multi-matting", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/multi-matting", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageSegmentationResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageSegmentationRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageSegmentationResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageSegmentationRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSegmentation", + methodName: "ImageSegmentationAsync", + pathTemplate: "\"/image/multi-matting\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSegmentation", + methodName: "ImageSegmentationAsync", + pathTemplate: "\"/image/multi-matting\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSegmentation", + methodName: "ImageSegmentationAsync", + pathTemplate: "\"/image/multi-matting\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageSegmentationResponseContent( + response: __response); + ProcessImageSegmentationResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSegmentation", + methodName: "ImageSegmentationAsync", + pathTemplate: "\"/image/multi-matting\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSegmentation", + methodName: "ImageSegmentationAsync", + pathTemplate: "\"/image/multi-matting\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageSegmentationResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageSegmentationResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageSegmentationResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageSegmentationResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageSegmentationResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Image Segmentation
/// Performs multi-matting segmentation on the input image, identifying and isolating specific classes like hair, clothes, or sky. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageSegmentationAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageSegmentationResponseContent( return await ImageSegmentationAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageTagging.g.cs b/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageTagging.g.cs index 01df4aa..f5fdc09 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageTagging.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.ImageTagging.g.cs @@ -16,6 +16,7 @@ public partial class ImageClassificationClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -47,16 +48,19 @@ partial void ProcessImageTaggingResponseContent( /// This tagging service analyzes the image and suggests hashtags that are relevant to the content. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageTaggingAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageTaggingAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -67,11 +71,13 @@ partial void ProcessImageTaggingResponseContent( /// This tagging service analyzes the image and suggests hashtags that are relevant to the content. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageTaggingAsResponseAsync( global::Picsart.ImageImageParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -88,22 +94,43 @@ partial void ProcessImageTaggingResponseContent( securityRequirements: s_ImageTaggingSecurityRequirements, operationName: "ImageTaggingAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/tags", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/tags", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -113,640 +140,799 @@ partial void ProcessImageTaggingResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - if (request.Image != default) - { - - var __contentImage = new global::System.Net.Http.ByteArrayContent(request.Image ?? global::System.Array.Empty()); - __httpRequestContent.Add( - content: __contentImage, - name: "\"image\"", - fileName: request.Imagename != null ? $"\"{request.Imagename}\"" : string.Empty); - if (__contentImage.Headers.ContentDisposition != null) - { - __contentImage.Headers.ContentDisposition.FileNameStar = null; - } - } - if (request.ImageUrl != default) - { - - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.ImageUrl}"), - name: "\"image_url\""); - } - if (request.ImageId != default) - { - - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.ImageId}"), - name: "\"image_id\""); - } - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageTaggingRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageTaggingResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (request.Image != default) + { + + var __contentImage = new global::System.Net.Http.ByteArrayContent(request.Image ?? global::System.Array.Empty()); + __httpRequestContent.Add( + content: __contentImage, + name: "\"image\"", + fileName: request.Imagename != null ? $"\"{request.Imagename}\"" : string.Empty); + if (__contentImage.Headers.ContentDisposition != null) + { + __contentImage.Headers.ContentDisposition.FileNameStar = null; + } + } + if (request.ImageUrl != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.ImageUrl}"), + name: "\"image_url\""); + } + if (request.ImageId != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.ImageId}"), + name: "\"image_id\""); + } + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageTaggingRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTagging", + methodName: "ImageTaggingAsync", + pathTemplate: "\"/image/tags\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTagging", + methodName: "ImageTaggingAsync", + pathTemplate: "\"/image/tags\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTagging", + methodName: "ImageTaggingAsync", + pathTemplate: "\"/image/tags\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageTaggingResponseContent( + response: __response); + ProcessImageTaggingResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTagging", + methodName: "ImageTaggingAsync", + pathTemplate: "\"/image/tags\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTagging", + methodName: "ImageTaggingAsync", + pathTemplate: "\"/image/tags\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageTaggingResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageTaggingResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageTaggingResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageTaggingResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageTaggingResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// @@ -762,12 +948,14 @@ partial void ProcessImageTaggingResponseContent( /// /// Source image URL. (If this parameter is present, the other image source parameters must be empty.) /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageTaggingAsync( byte[]? image = default, string? imagename = default, string? imageUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.ImageImageParameters @@ -779,6 +967,7 @@ partial void ProcessImageTaggingResponseContent( return await ImageTaggingAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.g.cs b/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.g.cs index f714190..b7ba168 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageClassificationClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class ImageClassificationClient : global::Picsart.IImageCl #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public ImageClassificationClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the ImageClassificationClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public ImageClassificationClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.ImageContentGenerationClient.ImageGeneratePattern.g.cs b/src/libs/Picsart/Generated/Picsart.ImageContentGenerationClient.ImageGeneratePattern.g.cs index 5d57ce4..5af5cf8 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageContentGenerationClient.ImageGeneratePattern.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageContentGenerationClient.ImageGeneratePattern.g.cs @@ -14,6 +14,7 @@ public partial class ImageContentGenerationClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageGeneratePatternResponseContent( /// The *pattern generator* tool generates a background texture pattern for the input image. You can create unlimited patterns from the same source image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageGeneratePatternAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageGeneratePatternAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageGeneratePatternResponseContent( /// The *pattern generator* tool generates a background texture pattern for the input image. You can create unlimited patterns from the same source image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageGeneratePatternAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageGeneratePatternResponseContent( securityRequirements: s_ImageGeneratePatternSecurityRequirements, operationName: "ImageGeneratePatternAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/background/pattern", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/background/pattern", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageGeneratePatternResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageGeneratePatternRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageGeneratePatternResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageGeneratePatternRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageGeneratePattern", + methodName: "ImageGeneratePatternAsync", + pathTemplate: "\"/image/background/pattern\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageGeneratePattern", + methodName: "ImageGeneratePatternAsync", + pathTemplate: "\"/image/background/pattern\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageGeneratePattern", + methodName: "ImageGeneratePatternAsync", + pathTemplate: "\"/image/background/pattern\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageGeneratePatternResponseContent( + response: __response); + ProcessImageGeneratePatternResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageGeneratePattern", + methodName: "ImageGeneratePatternAsync", + pathTemplate: "\"/image/background/pattern\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageGeneratePattern", + methodName: "ImageGeneratePatternAsync", + pathTemplate: "\"/image/background/pattern\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageGeneratePatternResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageGeneratePatternResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageGeneratePatternResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageGeneratePatternResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageGeneratePatternResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Pattern Generator
/// The *pattern generator* tool generates a background texture pattern for the input image. You can create unlimited patterns from the same source image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageGeneratePatternAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageGeneratePatternResponseContent( return await ImageGeneratePatternAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageContentGenerationClient.g.cs b/src/libs/Picsart/Generated/Picsart.ImageContentGenerationClient.g.cs index efa53cd..a0100a1 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageContentGenerationClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageContentGenerationClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class ImageContentGenerationClient : global::Picsart.IImag #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public ImageContentGenerationClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the ImageContentGenerationClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public ImageContentGenerationClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.ImageConversionClient.ImageDesignImport.g.cs b/src/libs/Picsart/Generated/Picsart.ImageConversionClient.ImageDesignImport.g.cs index 8244fbf..bee8190 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageConversionClient.ImageDesignImport.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageConversionClient.ImageDesignImport.g.cs @@ -14,6 +14,7 @@ public partial class ImageConversionClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -50,16 +51,19 @@ partial void ProcessImageDesignImportResponseContent( /// * SVG (Scalable Vector Graphics) /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageDesignImportAsync( global::Picsart.ImageFileParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageDesignImportAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -75,11 +79,13 @@ partial void ProcessImageDesignImportResponseContent( /// * SVG (Scalable Vector Graphics) /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageDesignImportAsResponseAsync( global::Picsart.ImageFileParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -96,22 +102,43 @@ partial void ProcessImageDesignImportResponseContent( securityRequirements: s_ImageDesignImportSecurityRequirements, operationName: "ImageDesignImportAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/design2replay", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/design2replay", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -121,633 +148,792 @@ partial void ProcessImageDesignImportResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - if (request.File != default) - { - - var __contentFile = new global::System.Net.Http.ByteArrayContent(request.File ?? global::System.Array.Empty()); - __httpRequestContent.Add( - content: __contentFile, - name: "\"file\"", - fileName: request.Filename != null ? $"\"{request.Filename}\"" : string.Empty); - if (__contentFile.Headers.ContentDisposition != null) - { - __contentFile.Headers.ContentDisposition.FileNameStar = null; - } - } - if (request.FileUrl != default) - { - - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.FileUrl}"), - name: "\"file_url\""); - } - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageDesignImportRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageDesignImportResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (request.File != default) + { + + var __contentFile = new global::System.Net.Http.ByteArrayContent(request.File ?? global::System.Array.Empty()); + __httpRequestContent.Add( + content: __contentFile, + name: "\"file\"", + fileName: request.Filename != null ? $"\"{request.Filename}\"" : string.Empty); + if (__contentFile.Headers.ContentDisposition != null) + { + __contentFile.Headers.ContentDisposition.FileNameStar = null; + } + } + if (request.FileUrl != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.FileUrl}"), + name: "\"file_url\""); + } + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageDesignImportRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDesignImport", + methodName: "ImageDesignImportAsync", + pathTemplate: "\"/image/design2replay\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDesignImport", + methodName: "ImageDesignImportAsync", + pathTemplate: "\"/image/design2replay\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDesignImport", + methodName: "ImageDesignImportAsync", + pathTemplate: "\"/image/design2replay\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } + break; } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageDesignImportResponseContent( + response: __response); + ProcessImageDesignImportResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDesignImport", + methodName: "ImageDesignImportAsync", + pathTemplate: "\"/image/design2replay\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDesignImport", + methodName: "ImageDesignImportAsync", + pathTemplate: "\"/image/design2replay\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageDesignImportResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageDesignImportResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageDesignImportResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageDesignImportResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageDesignImportResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// @@ -768,12 +954,14 @@ partial void ProcessImageDesignImportResponseContent( /// /// Source file URL. (If this parameter is present, the other source parameters must be empty.) /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageDesignImportAsync( byte[]? file = default, string? filename = default, string? fileUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.ImageFileParameters @@ -785,6 +973,7 @@ partial void ProcessImageDesignImportResponseContent( return await ImageDesignImportAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageConversionClient.ImageDesignImportGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.ImageConversionClient.ImageDesignImportGetresult.g.cs index 10326bb..a1181b6 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageConversionClient.ImageDesignImportGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageConversionClient.ImageDesignImportGetresult.g.cs @@ -14,6 +14,7 @@ public partial class ImageConversionClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,14 +46,17 @@ partial void ProcessImageDesignImportGetresultResponseContent( /// Get the result of the Design Import. Use the inference identifier from the POST request to fetch the latest status and result here. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageDesignImportGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageDesignImportGetresultAsResponseAsync( transactionId: transactionId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,10 +67,12 @@ partial void ProcessImageDesignImportGetresultResponseContent( /// Get the result of the Design Import. Use the inference identifier from the POST request to fetch the latest status and result here. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageDesignImportGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -81,22 +87,43 @@ partial void ProcessImageDesignImportGetresultResponseContent( securityRequirements: s_ImageDesignImportGetresultSecurityRequirements, operationName: "ImageDesignImportGetresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/image/design2replay/{transactionId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/image/design2replay/{transactionId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -106,611 +133,770 @@ partial void ProcessImageDesignImportGetresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageDesignImportGetresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - transactionId: transactionId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageDesignImportGetresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageDesignImportGetresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + transactionId: transactionId); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDesignImportGetresult", + methodName: "ImageDesignImportGetresultAsync", + pathTemplate: "$\"/image/design2replay/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDesignImportGetresult", + methodName: "ImageDesignImportGetresultAsync", + pathTemplate: "$\"/image/design2replay/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDesignImportGetresult", + methodName: "ImageDesignImportGetresultAsync", + pathTemplate: "$\"/image/design2replay/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageDesignImportGetresultResponseContent( + response: __response); + ProcessImageDesignImportGetresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDesignImportGetresult", + methodName: "ImageDesignImportGetresultAsync", + pathTemplate: "$\"/image/design2replay/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageDesignImportGetresult", + methodName: "ImageDesignImportGetresultAsync", + pathTemplate: "$\"/image/design2replay/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageDesignImportGetresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageDesignImportGetresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageDesignImportGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageDesignImportGetresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageDesignImportGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageConversionClient.ImageVectorizeRasterToSvg.g.cs b/src/libs/Picsart/Generated/Picsart.ImageConversionClient.ImageVectorizeRasterToSvg.g.cs index e6a6065..3ddf026 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageConversionClient.ImageVectorizeRasterToSvg.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageConversionClient.ImageVectorizeRasterToSvg.g.cs @@ -14,6 +14,7 @@ public partial class ImageConversionClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageVectorizeRasterToSvgResponseContent( /// With the *vectorizer* tool you can instantly turn your raster image into high quality vector graphic as it converts a PNG image to a SVG image. Using geometric figures, like curves and lines, the vectorizer converts the pixel information of raster input into vector image, which can be enlarged and edited without quality loss. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageVectorizeRasterToSvgAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageVectorizeRasterToSvgAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageVectorizeRasterToSvgResponseContent( /// With the *vectorizer* tool you can instantly turn your raster image into high quality vector graphic as it converts a PNG image to a SVG image. Using geometric figures, like curves and lines, the vectorizer converts the pixel information of raster input into vector image, which can be enlarged and edited without quality loss. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageVectorizeRasterToSvgAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageVectorizeRasterToSvgResponseContent( securityRequirements: s_ImageVectorizeRasterToSvgSecurityRequirements, operationName: "ImageVectorizeRasterToSvgAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/vectorizer", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/vectorizer", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageVectorizeRasterToSvgResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageVectorizeRasterToSvgRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageVectorizeRasterToSvgResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageVectorizeRasterToSvgRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageVectorizeRasterToSvg", + methodName: "ImageVectorizeRasterToSvgAsync", + pathTemplate: "\"/image/vectorizer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageVectorizeRasterToSvg", + methodName: "ImageVectorizeRasterToSvgAsync", + pathTemplate: "\"/image/vectorizer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageVectorizeRasterToSvg", + methodName: "ImageVectorizeRasterToSvgAsync", + pathTemplate: "\"/image/vectorizer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageVectorizeRasterToSvgResponseContent( + response: __response); + ProcessImageVectorizeRasterToSvgResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageVectorizeRasterToSvg", + methodName: "ImageVectorizeRasterToSvgAsync", + pathTemplate: "\"/image/vectorizer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageVectorizeRasterToSvg", + methodName: "ImageVectorizeRasterToSvgAsync", + pathTemplate: "\"/image/vectorizer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageVectorizeRasterToSvgResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageVectorizeRasterToSvgResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageVectorizeRasterToSvgResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageVectorizeRasterToSvgResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageVectorizeRasterToSvgResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Image Vectorizer
/// With the *vectorizer* tool you can instantly turn your raster image into high quality vector graphic as it converts a PNG image to a SVG image. Using geometric figures, like curves and lines, the vectorizer converts the pixel information of raster input into vector image, which can be enlarged and edited without quality loss. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageVectorizeRasterToSvgAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageVectorizeRasterToSvgResponseContent( return await ImageVectorizeRasterToSvgAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageConversionClient.g.cs b/src/libs/Picsart/Generated/Picsart.ImageConversionClient.g.cs index 602b7e0..ffb14ab 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageConversionClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageConversionClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class ImageConversionClient : global::Picsart.IImageConver #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public ImageConversionClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the ImageConversionClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public ImageConversionClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageBlend.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageBlend.g.cs index 93f92cf..87225ed 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageBlend.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageBlend.g.cs @@ -14,6 +14,7 @@ public partial class ImageEditingClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -47,16 +48,19 @@ partial void ProcessImageBlendResponseContent( /// No need for manual edits or complex graphic design tools. With the blend API, your app or service can automate visually rich output that's both fast and fully customizable. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageBlendAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageBlendAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -69,11 +73,13 @@ partial void ProcessImageBlendResponseContent( /// No need for manual edits or complex graphic design tools. With the blend API, your app or service can automate visually rich output that's both fast and fully customizable. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageBlendAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -88,22 +94,43 @@ partial void ProcessImageBlendResponseContent( securityRequirements: s_ImageBlendSecurityRequirements, operationName: "ImageBlendAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/blend", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/blend", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -113,613 +140,772 @@ partial void ProcessImageBlendResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageBlendRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageBlendResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageBlendRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageBlend", + methodName: "ImageBlendAsync", + pathTemplate: "\"/image/blend\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageBlend", + methodName: "ImageBlendAsync", + pathTemplate: "\"/image/blend\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageBlend", + methodName: "ImageBlendAsync", + pathTemplate: "\"/image/blend\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageBlendResponseContent( + response: __response); + ProcessImageBlendResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageBlend", + methodName: "ImageBlendAsync", + pathTemplate: "\"/image/blend\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageBlend", + methodName: "ImageBlendAsync", + pathTemplate: "\"/image/blend\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageBlendResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageBlendResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageBlendResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageBlendResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageBlendResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// @@ -728,9 +914,11 @@ partial void ProcessImageBlendResponseContent( /// This endpoint lets you seamlessly combine a base image with another visual layer - like an overlay, mask, or logo - while giving you full control over how the two interact. Think of it as your virtual creative layer engine: the same power you'd expect from a professional design tool, now embedded into your workflow or platform.
/// No need for manual edits or complex graphic design tools. With the blend API, your app or service can automate visually rich output that's both fast and fully customizable. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageBlendAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -739,6 +927,7 @@ partial void ProcessImageBlendResponseContent( return await ImageBlendAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageEdit.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageEdit.g.cs index a2649d9..d760501 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageEdit.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageEdit.g.cs @@ -14,6 +14,7 @@ public partial class ImageEditingClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageEditResponseContent( /// The *Edit* service applies basic image editing to an input image. The basic editing operations are resize, crop, flip, rotate and perspective manipulation. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageEditAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageEditAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageEditResponseContent( /// The *Edit* service applies basic image editing to an input image. The basic editing operations are resize, crop, flip, rotate and perspective manipulation. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageEditAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageEditResponseContent( securityRequirements: s_ImageEditSecurityRequirements, operationName: "ImageEditAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/edit", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/edit", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageEditResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageEditRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageEditResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageEditRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageEdit", + methodName: "ImageEditAsync", + pathTemplate: "\"/image/edit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageEdit", + methodName: "ImageEditAsync", + pathTemplate: "\"/image/edit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageEdit", + methodName: "ImageEditAsync", + pathTemplate: "\"/image/edit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageEditResponseContent( + response: __response); + ProcessImageEditResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageEdit", + methodName: "ImageEditAsync", + pathTemplate: "\"/image/edit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageEdit", + methodName: "ImageEditAsync", + pathTemplate: "\"/image/edit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageEditResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageEditResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageEditResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageEditResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageEditResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Basic Editing
/// The *Edit* service applies basic image editing to an input image. The basic editing operations are resize, crop, flip, rotate and perspective manipulation. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageEditAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageEditResponseContent( return await ImageEditAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageSmartCrop.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageSmartCrop.g.cs index fab7274..39243b4 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageSmartCrop.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageSmartCrop.g.cs @@ -14,6 +14,7 @@ public partial class ImageEditingClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageSmartCropResponseContent( /// Use AI to define the segment that should be cropped, e.g. foreground or product name (e.g. hat, gloves, boots, etc). /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageSmartCropAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageSmartCropAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageSmartCropResponseContent( /// Use AI to define the segment that should be cropped, e.g. foreground or product name (e.g. hat, gloves, boots, etc). /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageSmartCropAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageSmartCropResponseContent( securityRequirements: s_ImageSmartCropSecurityRequirements, operationName: "ImageSmartCropAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/smart-crop", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/smart-crop", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageSmartCropResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageSmartCropRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageSmartCropResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageSmartCropRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSmartCrop", + methodName: "ImageSmartCropAsync", + pathTemplate: "\"/image/smart-crop\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSmartCrop", + methodName: "ImageSmartCropAsync", + pathTemplate: "\"/image/smart-crop\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSmartCrop", + methodName: "ImageSmartCropAsync", + pathTemplate: "\"/image/smart-crop\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageSmartCropResponseContent( + response: __response); + ProcessImageSmartCropResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSmartCrop", + methodName: "ImageSmartCropAsync", + pathTemplate: "\"/image/smart-crop\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSmartCrop", + methodName: "ImageSmartCropAsync", + pathTemplate: "\"/image/smart-crop\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageSmartCropResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageSmartCropResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageSmartCropResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageSmartCropResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageSmartCropResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Smart Crop
/// Use AI to define the segment that should be cropped, e.g. foreground or product name (e.g. hat, gloves, boots, etc). ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageSmartCropAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageSmartCropResponseContent( return await ImageSmartCropAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageZoom.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageZoom.g.cs index fd0e95c..b83c203 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageZoom.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEditingClient.ImageZoom.g.cs @@ -14,6 +14,7 @@ public partial class ImageEditingClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageZoomResponseContent( /// Zoom your images with 1-75 scale factors. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageZoomAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageZoomAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageZoomResponseContent( /// Zoom your images with 1-75 scale factors. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageZoomAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageZoomResponseContent( securityRequirements: s_ImageZoomSecurityRequirements, operationName: "ImageZoomAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/zoom", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/zoom", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageZoomResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageZoomRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageZoomResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageZoomRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageZoom", + methodName: "ImageZoomAsync", + pathTemplate: "\"/image/zoom\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageZoom", + methodName: "ImageZoomAsync", + pathTemplate: "\"/image/zoom\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageZoom", + methodName: "ImageZoomAsync", + pathTemplate: "\"/image/zoom\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageZoomResponseContent( + response: __response); + ProcessImageZoomResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageZoom", + methodName: "ImageZoomAsync", + pathTemplate: "\"/image/zoom\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageZoom", + methodName: "ImageZoomAsync", + pathTemplate: "\"/image/zoom\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageZoomResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageZoomResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageZoomResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageZoomResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageZoomResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Zoom
/// Zoom your images with 1-75 scale factors. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageZoomAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageZoomResponseContent( return await ImageZoomAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEditingClient.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEditingClient.g.cs index 589e790..4890c61 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEditingClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEditingClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class ImageEditingClient : global::Picsart.IImageEditingCl #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public ImageEditingClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the ImageEditingClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public ImageEditingClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageAdjust.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageAdjust.g.cs index a2bf704..7b714ba 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageAdjust.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageAdjust.g.cs @@ -14,6 +14,7 @@ public partial class ImageEffectsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageAdjustResponseContent( /// The *adjust* service applies adjustments to an input image. There are 11 different adjustments in all available. The adjust service can be used with all photo types. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageAdjustAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageAdjustAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageAdjustResponseContent( /// The *adjust* service applies adjustments to an input image. There are 11 different adjustments in all available. The adjust service can be used with all photo types. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageAdjustAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageAdjustResponseContent( securityRequirements: s_ImageAdjustSecurityRequirements, operationName: "ImageAdjustAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/adjust", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/adjust", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageAdjustResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageAdjustRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageAdjustResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageAdjustRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageAdjust", + methodName: "ImageAdjustAsync", + pathTemplate: "\"/image/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageAdjust", + methodName: "ImageAdjustAsync", + pathTemplate: "\"/image/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageAdjust", + methodName: "ImageAdjustAsync", + pathTemplate: "\"/image/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageAdjustResponseContent( + response: __response); + ProcessImageAdjustResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageAdjust", + methodName: "ImageAdjustAsync", + pathTemplate: "\"/image/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageAdjust", + methodName: "ImageAdjustAsync", + pathTemplate: "\"/image/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageAdjustResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageAdjustResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageAdjustResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageAdjustResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageAdjustResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Adjust
/// The *adjust* service applies adjustments to an input image. There are 11 different adjustments in all available. The adjust service can be used with all photo types. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageAdjustAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageAdjustResponseContent( return await ImageAdjustAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyAiEffect.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyAiEffect.g.cs index 470e919..672cf79 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyAiEffect.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyAiEffect.g.cs @@ -14,6 +14,7 @@ public partial class ImageEffectsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageApplyAiEffectResponseContent( /// With the *AI Effects* service you can apply up to 40+ different AI effects to an image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageApplyAiEffectAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageApplyAiEffectAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageApplyAiEffectResponseContent( /// With the *AI Effects* service you can apply up to 40+ different AI effects to an image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageApplyAiEffectAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageApplyAiEffectResponseContent( securityRequirements: s_ImageApplyAiEffectSecurityRequirements, operationName: "ImageApplyAiEffectAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/effects/ai", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/effects/ai", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageApplyAiEffectResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageApplyAiEffectRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageApplyAiEffectResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageApplyAiEffectRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyAiEffect", + methodName: "ImageApplyAiEffectAsync", + pathTemplate: "\"/image/effects/ai\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyAiEffect", + methodName: "ImageApplyAiEffectAsync", + pathTemplate: "\"/image/effects/ai\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyAiEffect", + methodName: "ImageApplyAiEffectAsync", + pathTemplate: "\"/image/effects/ai\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageApplyAiEffectResponseContent( + response: __response); + ProcessImageApplyAiEffectResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyAiEffect", + methodName: "ImageApplyAiEffectAsync", + pathTemplate: "\"/image/effects/ai\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyAiEffect", + methodName: "ImageApplyAiEffectAsync", + pathTemplate: "\"/image/effects/ai\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageApplyAiEffectResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageApplyAiEffectResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageApplyAiEffectResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageApplyAiEffectResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageApplyAiEffectResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// AI Effects
/// With the *AI Effects* service you can apply up to 40+ different AI effects to an image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageApplyAiEffectAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageApplyAiEffectResponseContent( return await ImageApplyAiEffectAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyEffect.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyEffect.g.cs index 8520afa..6545410 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyEffect.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyEffect.g.cs @@ -14,6 +14,7 @@ public partial class ImageEffectsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageApplyEffectResponseContent( /// With the *effects* service you can apply up to 24 different effects to an image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageApplyEffectAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageApplyEffectAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageApplyEffectResponseContent( /// With the *effects* service you can apply up to 24 different effects to an image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageApplyEffectAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageApplyEffectResponseContent( securityRequirements: s_ImageApplyEffectSecurityRequirements, operationName: "ImageApplyEffectAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/effects", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/effects", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageApplyEffectResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageApplyEffectRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageApplyEffectResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageApplyEffectRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyEffect", + methodName: "ImageApplyEffectAsync", + pathTemplate: "\"/image/effects\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyEffect", + methodName: "ImageApplyEffectAsync", + pathTemplate: "\"/image/effects\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyEffect", + methodName: "ImageApplyEffectAsync", + pathTemplate: "\"/image/effects\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageApplyEffectResponseContent( + response: __response); + ProcessImageApplyEffectResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyEffect", + methodName: "ImageApplyEffectAsync", + pathTemplate: "\"/image/effects\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyEffect", + methodName: "ImageApplyEffectAsync", + pathTemplate: "\"/image/effects\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageApplyEffectResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageApplyEffectResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageApplyEffectResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageApplyEffectResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageApplyEffectResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Effects
/// With the *effects* service you can apply up to 24 different effects to an image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageApplyEffectAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageApplyEffectResponseContent( return await ImageApplyEffectAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyLaserEngravingEffect.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyLaserEngravingEffect.g.cs index 1693685..906b1fb 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyLaserEngravingEffect.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyLaserEngravingEffect.g.cs @@ -14,6 +14,7 @@ public partial class ImageEffectsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageApplyLaserEngravingEffectResponseContent( /// Apply a laser engraving effect to your stickers. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageApplyLaserEngravingEffectAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageApplyLaserEngravingEffectAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageApplyLaserEngravingEffectResponseContent( /// Apply a laser engraving effect to your stickers. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageApplyLaserEngravingEffectAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageApplyLaserEngravingEffectResponseContent( securityRequirements: s_ImageApplyLaserEngravingEffectSecurityRequirements, operationName: "ImageApplyLaserEngravingEffectAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/effects/laserengraving", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/effects/laserengraving", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageApplyLaserEngravingEffectResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageApplyLaserEngravingEffectRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageApplyLaserEngravingEffectResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageApplyLaserEngravingEffectRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyLaserEngravingEffect", + methodName: "ImageApplyLaserEngravingEffectAsync", + pathTemplate: "\"/image/effects/laserengraving\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyLaserEngravingEffect", + methodName: "ImageApplyLaserEngravingEffectAsync", + pathTemplate: "\"/image/effects/laserengraving\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyLaserEngravingEffect", + methodName: "ImageApplyLaserEngravingEffectAsync", + pathTemplate: "\"/image/effects/laserengraving\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageApplyLaserEngravingEffectResponseContent( + response: __response); + ProcessImageApplyLaserEngravingEffectResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyLaserEngravingEffect", + methodName: "ImageApplyLaserEngravingEffectAsync", + pathTemplate: "\"/image/effects/laserengraving\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyLaserEngravingEffect", + methodName: "ImageApplyLaserEngravingEffectAsync", + pathTemplate: "\"/image/effects/laserengraving\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageApplyLaserEngravingEffectResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageApplyLaserEngravingEffectResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageApplyLaserEngravingEffectResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageApplyLaserEngravingEffectResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageApplyLaserEngravingEffectResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Laser Engraving Effect
/// Apply a laser engraving effect to your stickers. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageApplyLaserEngravingEffectAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageApplyLaserEngravingEffectResponseContent( return await ImageApplyLaserEngravingEffectAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyMask.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyMask.g.cs index 1e2258c..daa4f2d 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyMask.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageApplyMask.g.cs @@ -14,6 +14,7 @@ public partial class ImageEffectsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageApplyMaskResponseContent( /// The *masks* service applies a mask to an image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageApplyMaskAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageApplyMaskAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageApplyMaskResponseContent( /// The *masks* service applies a mask to an image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageApplyMaskAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageApplyMaskResponseContent( securityRequirements: s_ImageApplyMaskSecurityRequirements, operationName: "ImageApplyMaskAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/masks", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/masks", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageApplyMaskResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageApplyMaskRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageApplyMaskResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageApplyMaskRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyMask", + methodName: "ImageApplyMaskAsync", + pathTemplate: "\"/image/masks\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyMask", + methodName: "ImageApplyMaskAsync", + pathTemplate: "\"/image/masks\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyMask", + methodName: "ImageApplyMaskAsync", + pathTemplate: "\"/image/masks\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageApplyMaskResponseContent( + response: __response); + ProcessImageApplyMaskResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyMask", + methodName: "ImageApplyMaskAsync", + pathTemplate: "\"/image/masks\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageApplyMask", + methodName: "ImageApplyMaskAsync", + pathTemplate: "\"/image/masks\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageApplyMaskResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageApplyMaskResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageApplyMaskResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageApplyMaskResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageApplyMaskResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Masks
/// The *masks* service applies a mask to an image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageApplyMaskAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageApplyMaskResponseContent( return await ImageApplyMaskAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageCreateEffectPreviews.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageCreateEffectPreviews.g.cs index 731f32b..278ace0 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageCreateEffectPreviews.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageCreateEffectPreviews.g.cs @@ -14,6 +14,7 @@ public partial class ImageEffectsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageCreateEffectPreviewsResponseContent( /// The *effects previews* service applies an effect to a given input image and returns a preview (i.e., thumbnail) of the effect. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageCreateEffectPreviewsAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageCreateEffectPreviewsAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageCreateEffectPreviewsResponseContent( /// The *effects previews* service applies an effect to a given input image and returns a preview (i.e., thumbnail) of the effect. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageCreateEffectPreviewsAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageCreateEffectPreviewsResponseContent( securityRequirements: s_ImageCreateEffectPreviewsSecurityRequirements, operationName: "ImageCreateEffectPreviewsAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/effects/previews", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/effects/previews", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageCreateEffectPreviewsResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageCreateEffectPreviewsRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageCreateEffectPreviewsResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageCreateEffectPreviewsRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreateEffectPreviews", + methodName: "ImageCreateEffectPreviewsAsync", + pathTemplate: "\"/image/effects/previews\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreateEffectPreviews", + methodName: "ImageCreateEffectPreviewsAsync", + pathTemplate: "\"/image/effects/previews\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreateEffectPreviews", + methodName: "ImageCreateEffectPreviewsAsync", + pathTemplate: "\"/image/effects/previews\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageCreateEffectPreviewsResponseContent( + response: __response); + ProcessImageCreateEffectPreviewsResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreateEffectPreviews", + methodName: "ImageCreateEffectPreviewsAsync", + pathTemplate: "\"/image/effects/previews\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreateEffectPreviews", + methodName: "ImageCreateEffectPreviewsAsync", + pathTemplate: "\"/image/effects/previews\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageCreateEffectPreviewsResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageCreateEffectPreviewsResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageCreateEffectPreviewsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageCreateEffectPreviewsResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageCreateEffectPreviewsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Effect Previews
/// The *effects previews* service applies an effect to a given input image and returns a preview (i.e., thumbnail) of the effect. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageCreateEffectPreviewsAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageCreateEffectPreviewsResponseContent( return await ImageCreateEffectPreviewsAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageCreateMaskPreviews.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageCreateMaskPreviews.g.cs index c69b481..db6f046 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageCreateMaskPreviews.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageCreateMaskPreviews.g.cs @@ -14,6 +14,7 @@ public partial class ImageEffectsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageCreateMaskPreviewsResponseContent( /// The *masks previews* service applies mask effects to a given input image and returns a preview (i.e., thumbnail) of the effect. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageCreateMaskPreviewsAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageCreateMaskPreviewsAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageCreateMaskPreviewsResponseContent( /// The *masks previews* service applies mask effects to a given input image and returns a preview (i.e., thumbnail) of the effect. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageCreateMaskPreviewsAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageCreateMaskPreviewsResponseContent( securityRequirements: s_ImageCreateMaskPreviewsSecurityRequirements, operationName: "ImageCreateMaskPreviewsAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/masks/previews", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/masks/previews", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageCreateMaskPreviewsResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageCreateMaskPreviewsRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageCreateMaskPreviewsResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageCreateMaskPreviewsRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreateMaskPreviews", + methodName: "ImageCreateMaskPreviewsAsync", + pathTemplate: "\"/image/masks/previews\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreateMaskPreviews", + methodName: "ImageCreateMaskPreviewsAsync", + pathTemplate: "\"/image/masks/previews\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreateMaskPreviews", + methodName: "ImageCreateMaskPreviewsAsync", + pathTemplate: "\"/image/masks/previews\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageCreateMaskPreviewsResponseContent( + response: __response); + ProcessImageCreateMaskPreviewsResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreateMaskPreviews", + methodName: "ImageCreateMaskPreviewsAsync", + pathTemplate: "\"/image/masks/previews\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreateMaskPreviews", + methodName: "ImageCreateMaskPreviewsAsync", + pathTemplate: "\"/image/masks/previews\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageCreateMaskPreviewsResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageCreateMaskPreviewsResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageCreateMaskPreviewsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageCreateMaskPreviewsResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageCreateMaskPreviewsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Mask Previews
/// The *masks previews* service applies mask effects to a given input image and returns a preview (i.e., thumbnail) of the effect. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageCreateMaskPreviewsAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageCreateMaskPreviewsResponseContent( return await ImageCreateMaskPreviewsAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageListAiEffectNames.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageListAiEffectNames.g.cs index 2a6bad0..38c3f61 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageListAiEffectNames.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageListAiEffectNames.g.cs @@ -14,6 +14,7 @@ public partial class ImageEffectsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -42,12 +43,15 @@ partial void ProcessImageListAiEffectNamesResponseContent( /// AI Effect Names
/// This service retrieves the list of supported AI effects. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageListAiEffectNamesAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageListAiEffectNamesAsResponseAsync( + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -57,9 +61,11 @@ partial void ProcessImageListAiEffectNamesResponseContent( /// AI Effect Names
/// This service retrieves the list of supported AI effects. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageListAiEffectNamesAsResponseAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -73,22 +79,43 @@ partial void ProcessImageListAiEffectNamesResponseContent( securityRequirements: s_ImageListAiEffectNamesSecurityRequirements, operationName: "ImageListAiEffectNamesAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/effects/ai", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/effects/ai", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -98,610 +125,769 @@ partial void ProcessImageListAiEffectNamesResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageListAiEffectNamesRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageListAiEffectNamesResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageListAiEffectNamesRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageListAiEffectNames", + methodName: "ImageListAiEffectNamesAsync", + pathTemplate: "\"/image/effects/ai\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageListAiEffectNames", + methodName: "ImageListAiEffectNamesAsync", + pathTemplate: "\"/image/effects/ai\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageListAiEffectNames", + methodName: "ImageListAiEffectNamesAsync", + pathTemplate: "\"/image/effects/ai\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageListAiEffectNamesResponseContent( + response: __response); + ProcessImageListAiEffectNamesResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageListAiEffectNames", + methodName: "ImageListAiEffectNamesAsync", + pathTemplate: "\"/image/effects/ai\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageListAiEffectNames", + methodName: "ImageListAiEffectNamesAsync", + pathTemplate: "\"/image/effects/ai\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageListAiEffectNamesResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageListAiEffectNamesResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageListAiEffectNamesResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageListAiEffectNamesResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageListAiEffectNamesResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageListEffectNames.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageListEffectNames.g.cs index 45d3afa..6938b1d 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageListEffectNames.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageListEffectNames.g.cs @@ -14,6 +14,7 @@ public partial class ImageEffectsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -42,12 +43,15 @@ partial void ProcessImageListEffectNamesResponseContent( /// Effect Names
/// This service retrieves a list of supported effects. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageListEffectNamesAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageListEffectNamesAsResponseAsync( + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -57,9 +61,11 @@ partial void ProcessImageListEffectNamesResponseContent( /// Effect Names
/// This service retrieves a list of supported effects. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageListEffectNamesAsResponseAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -73,22 +79,43 @@ partial void ProcessImageListEffectNamesResponseContent( securityRequirements: s_ImageListEffectNamesSecurityRequirements, operationName: "ImageListEffectNamesAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/effects", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/effects", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -98,610 +125,769 @@ partial void ProcessImageListEffectNamesResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageListEffectNamesRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageListEffectNamesResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageListEffectNamesRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageListEffectNames", + methodName: "ImageListEffectNamesAsync", + pathTemplate: "\"/image/effects\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageListEffectNames", + methodName: "ImageListEffectNamesAsync", + pathTemplate: "\"/image/effects\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageListEffectNames", + methodName: "ImageListEffectNamesAsync", + pathTemplate: "\"/image/effects\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageListEffectNamesResponseContent( + response: __response); + ProcessImageListEffectNamesResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageListEffectNames", + methodName: "ImageListEffectNamesAsync", + pathTemplate: "\"/image/effects\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageListEffectNames", + methodName: "ImageListEffectNamesAsync", + pathTemplate: "\"/image/effects\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageListEffectNamesResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageListEffectNamesResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageListEffectNamesResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageListEffectNamesResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageListEffectNamesResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageSelectiveBlur.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageSelectiveBlur.g.cs index 9a1c0b6..67b18fc 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageSelectiveBlur.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageSelectiveBlur.g.cs @@ -14,6 +14,7 @@ public partial class ImageEffectsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageSelectiveBlurResponseContent( /// Use AI to define the segment that should be blurred, e.g. foreground or background, faces or car plates. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageSelectiveBlurAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageSelectiveBlurAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageSelectiveBlurResponseContent( /// Use AI to define the segment that should be blurred, e.g. foreground or background, faces or car plates. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageSelectiveBlurAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageSelectiveBlurResponseContent( securityRequirements: s_ImageSelectiveBlurSecurityRequirements, operationName: "ImageSelectiveBlurAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/selective-blur", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/selective-blur", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageSelectiveBlurResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageSelectiveBlurRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageSelectiveBlurResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageSelectiveBlurRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSelectiveBlur", + methodName: "ImageSelectiveBlurAsync", + pathTemplate: "\"/image/selective-blur\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSelectiveBlur", + methodName: "ImageSelectiveBlurAsync", + pathTemplate: "\"/image/selective-blur\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSelectiveBlur", + methodName: "ImageSelectiveBlurAsync", + pathTemplate: "\"/image/selective-blur\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageSelectiveBlurResponseContent( + response: __response); + ProcessImageSelectiveBlurResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSelectiveBlur", + methodName: "ImageSelectiveBlurAsync", + pathTemplate: "\"/image/selective-blur\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSelectiveBlur", + methodName: "ImageSelectiveBlurAsync", + pathTemplate: "\"/image/selective-blur\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageSelectiveBlurResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageSelectiveBlurResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageSelectiveBlurResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageSelectiveBlurResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageSelectiveBlurResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Selective Blur
/// Use AI to define the segment that should be blurred, e.g. foreground or background, faces or car plates. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageSelectiveBlurAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageSelectiveBlurResponseContent( return await ImageSelectiveBlurAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageTransferColor.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageTransferColor.g.cs index 1f9b0e5..fc2858b 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageTransferColor.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageTransferColor.g.cs @@ -14,6 +14,7 @@ public partial class ImageEffectsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageTransferColorResponseContent( /// The *color transfer* tool transfers the color style from a reference image to the target image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageTransferColorAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageTransferColorAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageTransferColorResponseContent( /// The *color transfer* tool transfers the color style from a reference image to the target image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageTransferColorAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageTransferColorResponseContent( securityRequirements: s_ImageTransferColorSecurityRequirements, operationName: "ImageTransferColorAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/color-transfer", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/color-transfer", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageTransferColorResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageTransferColorRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageTransferColorResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageTransferColorRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTransferColor", + methodName: "ImageTransferColorAsync", + pathTemplate: "\"/image/color-transfer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTransferColor", + methodName: "ImageTransferColorAsync", + pathTemplate: "\"/image/color-transfer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTransferColor", + methodName: "ImageTransferColorAsync", + pathTemplate: "\"/image/color-transfer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageTransferColorResponseContent( + response: __response); + ProcessImageTransferColorResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTransferColor", + methodName: "ImageTransferColorAsync", + pathTemplate: "\"/image/color-transfer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTransferColor", + methodName: "ImageTransferColorAsync", + pathTemplate: "\"/image/color-transfer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageTransferColorResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageTransferColorResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageTransferColorResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageTransferColorResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageTransferColorResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Color Transfer
/// The *color transfer* tool transfers the color style from a reference image to the target image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageTransferColorAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageTransferColorResponseContent( return await ImageTransferColorAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageTransferStyle.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageTransferStyle.g.cs index 5e62a23..e49810f 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageTransferStyle.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.ImageTransferStyle.g.cs @@ -14,6 +14,7 @@ public partial class ImageEffectsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageTransferStyleResponseContent( /// The *style transfer* tool transfers a style from a reference image to a content image. The smart algorithm blends the two images together so the output looks like the content image, but "painted" in the style of the reference image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageTransferStyleAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageTransferStyleAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageTransferStyleResponseContent( /// The *style transfer* tool transfers a style from a reference image to a content image. The smart algorithm blends the two images together so the output looks like the content image, but "painted" in the style of the reference image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageTransferStyleAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageTransferStyleResponseContent( securityRequirements: s_ImageTransferStyleSecurityRequirements, operationName: "ImageTransferStyleAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/styletransfer", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/styletransfer", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageTransferStyleResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageTransferStyleRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageTransferStyleResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageTransferStyleRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTransferStyle", + methodName: "ImageTransferStyleAsync", + pathTemplate: "\"/image/styletransfer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTransferStyle", + methodName: "ImageTransferStyleAsync", + pathTemplate: "\"/image/styletransfer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTransferStyle", + methodName: "ImageTransferStyleAsync", + pathTemplate: "\"/image/styletransfer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageTransferStyleResponseContent( + response: __response); + ProcessImageTransferStyleResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTransferStyle", + methodName: "ImageTransferStyleAsync", + pathTemplate: "\"/image/styletransfer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageTransferStyle", + methodName: "ImageTransferStyleAsync", + pathTemplate: "\"/image/styletransfer\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageTransferStyleResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageTransferStyleResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageTransferStyleResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageTransferStyleResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageTransferStyleResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Style Transfer
/// The *style transfer* tool transfers a style from a reference image to a content image. The smart algorithm blends the two images together so the output looks like the content image, but "painted" in the style of the reference image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageTransferStyleAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageTransferStyleResponseContent( return await ImageTransferStyleAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.g.cs b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.g.cs index 0426b14..d80e277 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageEffectsClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class ImageEffectsClient : global::Picsart.IImageEffectsCl #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public ImageEffectsClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the ImageEffectsClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public ImageEffectsClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageFaceEnhance.g.cs b/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageFaceEnhance.g.cs index 8a15bcc..aeb841c 100644 --- a/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageFaceEnhance.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageFaceEnhance.g.cs @@ -14,6 +14,7 @@ public partial class ImagePhotoEnhancementClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageFaceEnhanceResponseContent( /// With our *enhance face* tool, you can turn your old, blurry photos into clear portraits and selfies. ur AI technology will find faces, perform restoration and do color enhancement simultaneously. It will improve the skin texture and sharpen details while keeping a good balance of realness and fidelity with much less artifacts. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageFaceEnhanceAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageFaceEnhanceAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageFaceEnhanceResponseContent( /// With our *enhance face* tool, you can turn your old, blurry photos into clear portraits and selfies. ur AI technology will find faces, perform restoration and do color enhancement simultaneously. It will improve the skin texture and sharpen details while keeping a good balance of realness and fidelity with much less artifacts. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageFaceEnhanceAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageFaceEnhanceResponseContent( securityRequirements: s_ImageFaceEnhanceSecurityRequirements, operationName: "ImageFaceEnhanceAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/enhance/face", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/enhance/face", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageFaceEnhanceResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageFaceEnhanceRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageFaceEnhanceResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageFaceEnhanceRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageFaceEnhance", + methodName: "ImageFaceEnhanceAsync", + pathTemplate: "\"/image/enhance/face\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageFaceEnhance", + methodName: "ImageFaceEnhanceAsync", + pathTemplate: "\"/image/enhance/face\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageFaceEnhance", + methodName: "ImageFaceEnhanceAsync", + pathTemplate: "\"/image/enhance/face\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageFaceEnhanceResponseContent( + response: __response); + ProcessImageFaceEnhanceResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageFaceEnhance", + methodName: "ImageFaceEnhanceAsync", + pathTemplate: "\"/image/enhance/face\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageFaceEnhance", + methodName: "ImageFaceEnhanceAsync", + pathTemplate: "\"/image/enhance/face\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageFaceEnhanceResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageFaceEnhanceResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageFaceEnhanceResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageFaceEnhanceResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageFaceEnhanceResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Face Enhancement
/// With our *enhance face* tool, you can turn your old, blurry photos into clear portraits and selfies. ur AI technology will find faces, perform restoration and do color enhancement simultaneously. It will improve the skin texture and sharpen details while keeping a good balance of realness and fidelity with much less artifacts. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageFaceEnhanceAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageFaceEnhanceResponseContent( return await ImageFaceEnhanceAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUltraEnhance.g.cs b/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUltraEnhance.g.cs index 07c83be..2da009d 100644 --- a/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUltraEnhance.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUltraEnhance.g.cs @@ -14,6 +14,7 @@ public partial class ImagePhotoEnhancementClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -56,16 +57,19 @@ partial void ProcessImageUltraEnhanceResponseContent( /// If you plan to upscale enhance an image several times, we recommend you first upload the source image using the *Upload* method and then use the reference image ID. Otherwise, you can source the image by providing a file or a URL to an online image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageUltraEnhanceAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageUltraEnhanceAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -87,11 +91,13 @@ partial void ProcessImageUltraEnhanceResponseContent( /// If you plan to upscale enhance an image several times, we recommend you first upload the source image using the *Upload* method and then use the reference image ID. Otherwise, you can source the image by providing a file or a URL to an online image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageUltraEnhanceAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -106,22 +112,43 @@ partial void ProcessImageUltraEnhanceResponseContent( securityRequirements: s_ImageUltraEnhanceSecurityRequirements, operationName: "ImageUltraEnhanceAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/upscale/enhance", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/upscale/enhance", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -131,613 +158,772 @@ partial void ProcessImageUltraEnhanceResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageUltraEnhanceRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageUltraEnhanceResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageUltraEnhanceRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraEnhance", + methodName: "ImageUltraEnhanceAsync", + pathTemplate: "\"/image/upscale/enhance\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraEnhance", + methodName: "ImageUltraEnhanceAsync", + pathTemplate: "\"/image/upscale/enhance\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraEnhance", + methodName: "ImageUltraEnhanceAsync", + pathTemplate: "\"/image/upscale/enhance\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageUltraEnhanceResponseContent( + response: __response); + ProcessImageUltraEnhanceResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraEnhance", + methodName: "ImageUltraEnhanceAsync", + pathTemplate: "\"/image/upscale/enhance\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraEnhance", + methodName: "ImageUltraEnhanceAsync", + pathTemplate: "\"/image/upscale/enhance\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageUltraEnhanceResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageUltraEnhanceResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageUltraEnhanceResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageUltraEnhanceResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageUltraEnhanceResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// @@ -755,9 +941,11 @@ partial void ProcessImageUltraEnhanceResponseContent( /// **Source Image:**
/// If you plan to upscale enhance an image several times, we recommend you first upload the source image using the *Upload* method and then use the reference image ID. Otherwise, you can source the image by providing a file or a URL to an online image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageUltraEnhanceAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -766,6 +954,7 @@ partial void ProcessImageUltraEnhanceResponseContent( return await ImageUltraEnhanceAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUltraUpscale.g.cs b/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUltraUpscale.g.cs index e778c50..e729f53 100644 --- a/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUltraUpscale.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUltraUpscale.g.cs @@ -14,6 +14,7 @@ public partial class ImagePhotoEnhancementClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageUltraUpscaleResponseContent( /// *Upscale Ultra* is a new upscaling technique which does upscaling with noise suppression. It works well on images with faces, small resolution images, stickers and objects with geometric shapes and clear edges. Upscale ultra increases the quality and resolution of low quality photos by leveraging predictive and generative AI technology in order to "complete" missing pixels for a best in class smoothing and enhancement effect. It works especially good on small resolution images with faces. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageUltraUpscaleAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageUltraUpscaleAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageUltraUpscaleResponseContent( /// *Upscale Ultra* is a new upscaling technique which does upscaling with noise suppression. It works well on images with faces, small resolution images, stickers and objects with geometric shapes and clear edges. Upscale ultra increases the quality and resolution of low quality photos by leveraging predictive and generative AI technology in order to "complete" missing pixels for a best in class smoothing and enhancement effect. It works especially good on small resolution images with faces. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageUltraUpscaleAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageUltraUpscaleResponseContent( securityRequirements: s_ImageUltraUpscaleSecurityRequirements, operationName: "ImageUltraUpscaleAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/upscale/ultra", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/upscale/ultra", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageUltraUpscaleResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageUltraUpscaleRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageUltraUpscaleResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageUltraUpscaleRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraUpscale", + methodName: "ImageUltraUpscaleAsync", + pathTemplate: "\"/image/upscale/ultra\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraUpscale", + methodName: "ImageUltraUpscaleAsync", + pathTemplate: "\"/image/upscale/ultra\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraUpscale", + methodName: "ImageUltraUpscaleAsync", + pathTemplate: "\"/image/upscale/ultra\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageUltraUpscaleResponseContent( + response: __response); + ProcessImageUltraUpscaleResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraUpscale", + methodName: "ImageUltraUpscaleAsync", + pathTemplate: "\"/image/upscale/ultra\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraUpscale", + methodName: "ImageUltraUpscaleAsync", + pathTemplate: "\"/image/upscale/ultra\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageUltraUpscaleResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageUltraUpscaleResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageUltraUpscaleResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageUltraUpscaleResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageUltraUpscaleResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Ultra Upscale
/// *Upscale Ultra* is a new upscaling technique which does upscaling with noise suppression. It works well on images with faces, small resolution images, stickers and objects with geometric shapes and clear edges. Upscale ultra increases the quality and resolution of low quality photos by leveraging predictive and generative AI technology in order to "complete" missing pixels for a best in class smoothing and enhancement effect. It works especially good on small resolution images with faces. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageUltraUpscaleAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageUltraUpscaleResponseContent( return await ImageUltraUpscaleAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUltraUpscaleGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUltraUpscaleGetresult.g.cs index d0f3717..e83fefa 100644 --- a/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUltraUpscaleGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUltraUpscaleGetresult.g.cs @@ -14,6 +14,7 @@ public partial class ImagePhotoEnhancementClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,14 +46,17 @@ partial void ProcessImageUltraUpscaleGetresultResponseContent( /// Use this method, along with transaction_id, to retrieve the upscale ultra finished image if the transformation was done asynchronously. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageUltraUpscaleGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageUltraUpscaleGetresultAsResponseAsync( transactionId: transactionId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,10 +67,12 @@ partial void ProcessImageUltraUpscaleGetresultResponseContent( /// Use this method, along with transaction_id, to retrieve the upscale ultra finished image if the transformation was done asynchronously. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageUltraUpscaleGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -81,22 +87,43 @@ partial void ProcessImageUltraUpscaleGetresultResponseContent( securityRequirements: s_ImageUltraUpscaleGetresultSecurityRequirements, operationName: "ImageUltraUpscaleGetresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/image/upscale/ultra/{transactionId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/image/upscale/ultra/{transactionId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -106,611 +133,770 @@ partial void ProcessImageUltraUpscaleGetresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageUltraUpscaleGetresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - transactionId: transactionId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageUltraUpscaleGetresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageUltraUpscaleGetresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + transactionId: transactionId); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraUpscaleGetresult", + methodName: "ImageUltraUpscaleGetresultAsync", + pathTemplate: "$\"/image/upscale/ultra/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraUpscaleGetresult", + methodName: "ImageUltraUpscaleGetresultAsync", + pathTemplate: "$\"/image/upscale/ultra/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraUpscaleGetresult", + methodName: "ImageUltraUpscaleGetresultAsync", + pathTemplate: "$\"/image/upscale/ultra/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageUltraUpscaleGetresultResponseContent( + response: __response); + ProcessImageUltraUpscaleGetresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraUpscaleGetresult", + methodName: "ImageUltraUpscaleGetresultAsync", + pathTemplate: "$\"/image/upscale/ultra/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUltraUpscaleGetresult", + methodName: "ImageUltraUpscaleGetresultAsync", + pathTemplate: "$\"/image/upscale/ultra/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageUltraUpscaleGetresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageUltraUpscaleGetresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageUltraUpscaleGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageUltraUpscaleGetresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageUltraUpscaleGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUpscale.g.cs b/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUpscale.g.cs index a21f005..1e0b5ff 100644 --- a/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUpscale.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.ImageUpscale.g.cs @@ -14,6 +14,7 @@ public partial class ImagePhotoEnhancementClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageUpscaleResponseContent( /// The *upscale* service increases the resolutions of an image by a given upscale factor, without increasing its file size. Upscale increases the quality and resolution of your photos by leveraging predictive and generative AI to add pixels to your image. It works especially well on images without noise. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageUpscaleAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageUpscaleAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageUpscaleResponseContent( /// The *upscale* service increases the resolutions of an image by a given upscale factor, without increasing its file size. Upscale increases the quality and resolution of your photos by leveraging predictive and generative AI to add pixels to your image. It works especially well on images without noise. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageUpscaleAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageUpscaleResponseContent( securityRequirements: s_ImageUpscaleSecurityRequirements, operationName: "ImageUpscaleAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/upscale", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/upscale", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageUpscaleResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageUpscaleRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageUpscaleResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageUpscaleRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUpscale", + methodName: "ImageUpscaleAsync", + pathTemplate: "\"/image/upscale\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUpscale", + methodName: "ImageUpscaleAsync", + pathTemplate: "\"/image/upscale\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUpscale", + methodName: "ImageUpscaleAsync", + pathTemplate: "\"/image/upscale\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageUpscaleResponseContent( + response: __response); + ProcessImageUpscaleResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUpscale", + methodName: "ImageUpscaleAsync", + pathTemplate: "\"/image/upscale\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUpscale", + methodName: "ImageUpscaleAsync", + pathTemplate: "\"/image/upscale\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageUpscaleResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageUpscaleResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageUpscaleResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageUpscaleResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageUpscaleResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Upscale
/// The *upscale* service increases the resolutions of an image by a given upscale factor, without increasing its file size. Upscale increases the quality and resolution of your photos by leveraging predictive and generative AI to add pixels to your image. It works especially well on images without noise. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageUpscaleAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageUpscaleResponseContent( return await ImageUpscaleAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.g.cs b/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.g.cs index 5822de8..a9979b9 100644 --- a/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImagePhotoEnhancementClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class ImagePhotoEnhancementClient : global::Picsart.IImage #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public ImagePhotoEnhancementClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the ImagePhotoEnhancementClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public ImagePhotoEnhancementClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.ImageRemoveBackgroundClient.ImageRemoveBackground.g.cs b/src/libs/Picsart/Generated/Picsart.ImageRemoveBackgroundClient.ImageRemoveBackground.g.cs index ad13eda..8a2cf91 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageRemoveBackgroundClient.ImageRemoveBackground.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageRemoveBackgroundClient.ImageRemoveBackground.g.cs @@ -14,6 +14,7 @@ public partial class ImageRemoveBackgroundClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageRemoveBackgroundResponseContent( /// Discover the magic of seamless background removal with our removebg service, powered by cutting-edge AI technology. Our sophisticated algorithm effortlessly identifies and isolates the foreground, ensuring every detail from the delicate intricacies of jewelry to the finest strands of hair is captured with unparalleled precision. Designed to excel across a vast array of use cases, our service guarantees immaculate cutouts, whether for professional product photos, dynamic campaign graphics, or personal images meant for creative exploration. Experience flawless edges and exceptional detail preservation every time, elevating your images beyond the ordinary. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageRemoveBackgroundAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageRemoveBackgroundAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageRemoveBackgroundResponseContent( /// Discover the magic of seamless background removal with our removebg service, powered by cutting-edge AI technology. Our sophisticated algorithm effortlessly identifies and isolates the foreground, ensuring every detail from the delicate intricacies of jewelry to the finest strands of hair is captured with unparalleled precision. Designed to excel across a vast array of use cases, our service guarantees immaculate cutouts, whether for professional product photos, dynamic campaign graphics, or personal images meant for creative exploration. Experience flawless edges and exceptional detail preservation every time, elevating your images beyond the ordinary. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageRemoveBackgroundAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageRemoveBackgroundResponseContent( securityRequirements: s_ImageRemoveBackgroundSecurityRequirements, operationName: "ImageRemoveBackgroundAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/removebg", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/removebg", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageRemoveBackgroundResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageRemoveBackgroundRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageRemoveBackgroundResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageRemoveBackgroundRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageRemoveBackground", + methodName: "ImageRemoveBackgroundAsync", + pathTemplate: "\"/image/removebg\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageRemoveBackground", + methodName: "ImageRemoveBackgroundAsync", + pathTemplate: "\"/image/removebg\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageRemoveBackground", + methodName: "ImageRemoveBackgroundAsync", + pathTemplate: "\"/image/removebg\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageRemoveBackgroundResponseContent( + response: __response); + ProcessImageRemoveBackgroundResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageRemoveBackground", + methodName: "ImageRemoveBackgroundAsync", + pathTemplate: "\"/image/removebg\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageRemoveBackground", + methodName: "ImageRemoveBackgroundAsync", + pathTemplate: "\"/image/removebg\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageRemoveBackgroundResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageRemoveBackgroundResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageRemoveBackgroundResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageRemoveBackgroundResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageRemoveBackgroundResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Remove & Change Background
/// Discover the magic of seamless background removal with our removebg service, powered by cutting-edge AI technology. Our sophisticated algorithm effortlessly identifies and isolates the foreground, ensuring every detail from the delicate intricacies of jewelry to the finest strands of hair is captured with unparalleled precision. Designed to excel across a vast array of use cases, our service guarantees immaculate cutouts, whether for professional product photos, dynamic campaign graphics, or personal images meant for creative exploration. Experience flawless edges and exceptional detail preservation every time, elevating your images beyond the ordinary. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageRemoveBackgroundAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageRemoveBackgroundResponseContent( return await ImageRemoveBackgroundAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageRemoveBackgroundClient.g.cs b/src/libs/Picsart/Generated/Picsart.ImageRemoveBackgroundClient.g.cs index 4734bd9..fb1ebf9 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageRemoveBackgroundClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageRemoveBackgroundClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class ImageRemoveBackgroundClient : global::Picsart.IImage #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public ImageRemoveBackgroundClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the ImageRemoveBackgroundClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public ImageRemoveBackgroundClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.ImageSurfacemapClient.ImageSurfacemap.g.cs b/src/libs/Picsart/Generated/Picsart.ImageSurfacemapClient.ImageSurfacemap.g.cs index ca6c07c..736c120 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageSurfacemapClient.ImageSurfacemap.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageSurfacemapClient.ImageSurfacemap.g.cs @@ -14,6 +14,7 @@ public partial class ImageSurfacemapClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageSurfacemapResponseContent( /// With the *surface map* tool you can "print" a sticker over an (target) image. Using a mask, the Surfacemap tool maps the sticker pixels using the texture and curves on the target image thus ultimately giving a live-print-preview effect. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageSurfacemapAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageSurfacemapAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageSurfacemapResponseContent( /// With the *surface map* tool you can "print" a sticker over an (target) image. Using a mask, the Surfacemap tool maps the sticker pixels using the texture and curves on the target image thus ultimately giving a live-print-preview effect. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageSurfacemapAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageSurfacemapResponseContent( securityRequirements: s_ImageSurfacemapSecurityRequirements, operationName: "ImageSurfacemapAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/surfacemap", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/surfacemap", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessImageSurfacemapResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageSurfacemapRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageSurfacemapResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageSurfacemapRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSurfacemap", + methodName: "ImageSurfacemapAsync", + pathTemplate: "\"/image/surfacemap\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSurfacemap", + methodName: "ImageSurfacemapAsync", + pathTemplate: "\"/image/surfacemap\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSurfacemap", + methodName: "ImageSurfacemapAsync", + pathTemplate: "\"/image/surfacemap\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageSurfacemapResponseContent( + response: __response); + ProcessImageSurfacemapResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSurfacemap", + methodName: "ImageSurfacemapAsync", + pathTemplate: "\"/image/surfacemap\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageSurfacemap", + methodName: "ImageSurfacemapAsync", + pathTemplate: "\"/image/surfacemap\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageSurfacemapResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageSurfacemapResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageSurfacemapResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageSurfacemapResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageSurfacemapResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Surfacemap Image
/// With the *surface map* tool you can "print" a sticker over an (target) image. Using a mask, the Surfacemap tool maps the sticker pixels using the texture and curves on the target image thus ultimately giving a live-print-preview effect. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageSurfacemapAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessImageSurfacemapResponseContent( return await ImageSurfacemapAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageSurfacemapClient.g.cs b/src/libs/Picsart/Generated/Picsart.ImageSurfacemapClient.g.cs index a722b45..e22eaeb 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageSurfacemapClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageSurfacemapClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class ImageSurfacemapClient : global::Picsart.IImageSurfac #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public ImageSurfacemapClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the ImageSurfacemapClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public ImageSurfacemapClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.ImageUtilitiesClient.ImageCreditsBalance.g.cs b/src/libs/Picsart/Generated/Picsart.ImageUtilitiesClient.ImageCreditsBalance.g.cs index 061987d..ae260c7 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageUtilitiesClient.ImageCreditsBalance.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageUtilitiesClient.ImageCreditsBalance.g.cs @@ -14,6 +14,7 @@ public partial class ImageUtilitiesClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -42,12 +43,15 @@ partial void ProcessImageCreditsBalanceResponseContent( /// Credits Balance
/// Check your balance of credits. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageCreditsBalanceAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageCreditsBalanceAsResponseAsync( + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -57,9 +61,11 @@ partial void ProcessImageCreditsBalanceResponseContent( /// Credits Balance
/// Check your balance of credits. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageCreditsBalanceAsResponseAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -73,22 +79,43 @@ partial void ProcessImageCreditsBalanceResponseContent( securityRequirements: s_ImageCreditsBalanceSecurityRequirements, operationName: "ImageCreditsBalanceAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/balance", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/balance", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -98,610 +125,769 @@ partial void ProcessImageCreditsBalanceResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageCreditsBalanceRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageCreditsBalanceResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageCreditsBalanceRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreditsBalance", + methodName: "ImageCreditsBalanceAsync", + pathTemplate: "\"/image/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreditsBalance", + methodName: "ImageCreditsBalanceAsync", + pathTemplate: "\"/image/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreditsBalance", + methodName: "ImageCreditsBalanceAsync", + pathTemplate: "\"/image/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageCreditsBalanceResponseContent( + response: __response); + ProcessImageCreditsBalanceResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreditsBalance", + methodName: "ImageCreditsBalanceAsync", + pathTemplate: "\"/image/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageCreditsBalance", + methodName: "ImageCreditsBalanceAsync", + pathTemplate: "\"/image/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageCreditsBalanceResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageCreditsBalanceResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageCreditsBalanceResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageCreditsBalanceResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageCreditsBalanceResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageUtilitiesClient.ImageUpload.g.cs b/src/libs/Picsart/Generated/Picsart.ImageUtilitiesClient.ImageUpload.g.cs index f0c5054..e146ed8 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageUtilitiesClient.ImageUpload.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageUtilitiesClient.ImageUpload.g.cs @@ -14,6 +14,7 @@ public partial class ImageUtilitiesClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -50,16 +51,19 @@ partial void ProcessImageUploadResponseContent( /// You can source the image by providing a file or a URL to an online image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageUploadAsync( global::Picsart.ImageUploadParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageUploadAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -75,11 +79,13 @@ partial void ProcessImageUploadResponseContent( /// You can source the image by providing a file or a URL to an online image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageUploadAsResponseAsync( global::Picsart.ImageUploadParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -96,22 +102,43 @@ partial void ProcessImageUploadResponseContent( securityRequirements: s_ImageUploadSecurityRequirements, operationName: "ImageUploadAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/upload", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/upload", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -121,633 +148,792 @@ partial void ProcessImageUploadResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - if (request.Image != default) - { - - var __contentImage = new global::System.Net.Http.ByteArrayContent(request.Image ?? global::System.Array.Empty()); - __httpRequestContent.Add( - content: __contentImage, - name: "\"image\"", - fileName: request.Imagename != null ? $"\"{request.Imagename}\"" : string.Empty); - if (__contentImage.Headers.ContentDisposition != null) - { - __contentImage.Headers.ContentDisposition.FileNameStar = null; - } - } - if (request.ImageUrl != default) - { - - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.ImageUrl}"), - name: "\"image_url\""); - } - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageUploadRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageUploadResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (request.Image != default) + { + + var __contentImage = new global::System.Net.Http.ByteArrayContent(request.Image ?? global::System.Array.Empty()); + __httpRequestContent.Add( + content: __contentImage, + name: "\"image\"", + fileName: request.Imagename != null ? $"\"{request.Imagename}\"" : string.Empty); + if (__contentImage.Headers.ContentDisposition != null) + { + __contentImage.Headers.ContentDisposition.FileNameStar = null; + } + } + if (request.ImageUrl != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.ImageUrl}"), + name: "\"image_url\""); + } + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageUploadRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.ImageError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUpload", + methodName: "ImageUploadAsync", + pathTemplate: "\"/image/upload\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUpload", + methodName: "ImageUploadAsync", + pathTemplate: "\"/image/upload\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUpload", + methodName: "ImageUploadAsync", + pathTemplate: "\"/image/upload\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } + break; } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageUploadResponseContent( + response: __response); + ProcessImageUploadResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUpload", + methodName: "ImageUploadAsync", + pathTemplate: "\"/image/upload\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageUpload", + methodName: "ImageUploadAsync", + pathTemplate: "\"/image/upload\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.ImageError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.ImageError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageUploadResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageUploadResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageUploadResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageUploadResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageUploadResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// @@ -768,12 +954,14 @@ partial void ProcessImageUploadResponseContent( /// /// Source image URL. (If this parameter is present, the other image source parameters must be empty.) /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageUploadAsync( byte[]? image = default, string? imagename = default, string? imageUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.ImageUploadParameters @@ -785,6 +973,7 @@ partial void ProcessImageUploadResponseContent( return await ImageUploadAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageUtilitiesClient.g.cs b/src/libs/Picsart/Generated/Picsart.ImageUtilitiesClient.g.cs index 1281046..07de8d5 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageUtilitiesClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageUtilitiesClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class ImageUtilitiesClient : global::Picsart.IImageUtiliti #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public ImageUtilitiesClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the ImageUtilitiesClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public ImageUtilitiesClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.ImageWatermarkClient.ImageAddWatermark.g.cs b/src/libs/Picsart/Generated/Picsart.ImageWatermarkClient.ImageAddWatermark.g.cs index 28a7bcb..c22d3af 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageWatermarkClient.ImageAddWatermark.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageWatermarkClient.ImageAddWatermark.g.cs @@ -14,6 +14,7 @@ public partial class ImageWatermarkClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessImageAddWatermarkResponseContent( /// Add watermark to your image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageAddWatermarkAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await ImageAddWatermarkAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessImageAddWatermarkResponseContent( /// Add watermark to your image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> ImageAddWatermarkAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessImageAddWatermarkResponseContent( securityRequirements: s_ImageAddWatermarkSecurityRequirements, operationName: "ImageAddWatermarkAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/image/watermark", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/image/watermark", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,584 +136,745 @@ partial void ProcessImageAddWatermarkResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareImageAddWatermarkRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessImageAddWatermarkResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.ImageError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Image401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.ImageError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.ImageError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.ImageError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.ImageError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.ImageError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.ImageError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareImageAddWatermarkRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.ImageError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.ImageError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageAddWatermark", + methodName: "ImageAddWatermarkAsync", + pathTemplate: "\"/image/watermark\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageAddWatermark", + methodName: "ImageAddWatermarkAsync", + pathTemplate: "\"/image/watermark\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.ImageError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageAddWatermark", + methodName: "ImageAddWatermarkAsync", + pathTemplate: "\"/image/watermark\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + if (__response == null) { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.ImageError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessImageAddWatermarkResponseContent( + response: __response); + ProcessImageAddWatermarkResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.ImageAddWatermarkResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageAddWatermark", + methodName: "ImageAddWatermarkAsync", + pathTemplate: "\"/image/watermark\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.ImageAddWatermarkResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ImageAddWatermark", + methodName: "ImageAddWatermarkAsync", + pathTemplate: "\"/image/watermark\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.ImageError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.ImageError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Image401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Image401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.ImageError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.ImageError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.ImageError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.ImageError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.ImageError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.ImageError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.ImageError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.ImageError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.ImageError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.ImageError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.ImageError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.ImageError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.ImageError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.ImageError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.ImageError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.ImageError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.ImageError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.ImageError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.ImageError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.ImageError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessImageAddWatermarkResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.ImageAddWatermarkResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.ImageAddWatermarkResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Add Watermark
/// Add watermark to your image. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ImageAddWatermarkAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -695,6 +883,7 @@ partial void ProcessImageAddWatermarkResponseContent( return await ImageAddWatermarkAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.ImageWatermarkClient.g.cs b/src/libs/Picsart/Generated/Picsart.ImageWatermarkClient.g.cs index 0aa74c9..44c8e64 100644 --- a/src/libs/Picsart/Generated/Picsart.ImageWatermarkClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.ImageWatermarkClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class ImageWatermarkClient : global::Picsart.IImageWaterma #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public ImageWatermarkClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the ImageWatermarkClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public ImageWatermarkClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.OptionsSupport.g.cs b/src/libs/Picsart/Generated/Picsart.OptionsSupport.g.cs new file mode 100644 index 0000000..53bc6f9 --- /dev/null +++ b/src/libs/Picsart/Generated/Picsart.OptionsSupport.g.cs @@ -0,0 +1,460 @@ + +#nullable enable + +namespace Picsart +{ + /// + /// Global defaults applied to generated SDK requests. + /// + public sealed class AutoSDKClientOptions + { + /// + /// Additional headers applied to every request after generated headers are set. + /// Entries with the same key overwrite earlier header values. + /// + public global::System.Collections.Generic.Dictionary Headers { get; } = + new global::System.Collections.Generic.Dictionary(global::System.StringComparer.OrdinalIgnoreCase); + + /// + /// Additional query parameters appended to every request. + /// Request-level entries with the same key are appended after client defaults. + /// + public global::System.Collections.Generic.Dictionary QueryParameters { get; } = + new global::System.Collections.Generic.Dictionary(global::System.StringComparer.Ordinal); + + /// + /// Optional timeout applied to the full request execution. + /// + public global::System.TimeSpan? Timeout { get; set; } + + /// + /// Default retry behavior for generated HTTP requests. + /// + public global::Picsart.AutoSDKRetryOptions Retry { get; set; } = new global::Picsart.AutoSDKRetryOptions(); + + /// + /// Overrides the client-wide response buffering mode when set. + /// + public bool? ReadResponseAsString { get; set; } + + /// + /// Reusable hooks invoked for every generated SDK request. + /// + public global::System.Collections.Generic.List Hooks { get; } = + new global::System.Collections.Generic.List(); + + /// + /// Registers a hook for all requests issued by this client. + /// + /// + /// The current options instance. + public global::Picsart.AutoSDKClientOptions AddHook( + global::Picsart.IAutoSDKHook hook) + { + Hooks.Add(hook ?? throw new global::System.ArgumentNullException(nameof(hook))); + return this; + } + } + + /// + /// Per-request overrides applied on top of . + /// + public sealed class AutoSDKRequestOptions + { + /// + /// Additional headers applied after generated and client-level headers. + /// + public global::System.Collections.Generic.Dictionary Headers { get; } = + new global::System.Collections.Generic.Dictionary(global::System.StringComparer.OrdinalIgnoreCase); + + /// + /// Additional query parameters appended after generated and client-level query parameters. + /// + public global::System.Collections.Generic.Dictionary QueryParameters { get; } = + new global::System.Collections.Generic.Dictionary(global::System.StringComparer.Ordinal); + + /// + /// Optional timeout override for this request. + /// + public global::System.TimeSpan? Timeout { get; set; } + + /// + /// Optional retry override for this request. + /// + public global::Picsart.AutoSDKRetryOptions? Retry { get; set; } + + /// + /// Overrides response buffering for this request when set. + /// + public bool? ReadResponseAsString { get; set; } + } + + /// + /// Retry settings for generated HTTP requests. + /// + public sealed class AutoSDKRetryOptions + { + /// + /// Total number of attempts, including the initial request. + /// Values less than 1 are normalized to 1. + /// + public int MaxAttempts { get; set; } = 1; + + /// + /// Optional fixed delay between retry attempts. + /// + public global::System.TimeSpan? Delay { get; set; } + } + + /// + /// Runtime hook interface for generated SDK lifecycle events. + /// + public interface IAutoSDKHook + { + /// + /// Runs before a request is sent. + /// + /// + global::System.Threading.Tasks.Task OnBeforeRequestAsync( + global::Picsart.AutoSDKHookContext context); + + /// + /// Runs after a successful HTTP response is received. + /// + /// + global::System.Threading.Tasks.Task OnAfterSuccessAsync( + global::Picsart.AutoSDKHookContext context); + + /// + /// Runs after an error response or transport failure is observed. + /// + /// + global::System.Threading.Tasks.Task OnAfterErrorAsync( + global::Picsart.AutoSDKHookContext context); + } + + /// + /// Convenience base type for request hooks with no-op defaults. + /// + public abstract class AutoSDKHook : global::Picsart.IAutoSDKHook + { + /// + public virtual global::System.Threading.Tasks.Task OnBeforeRequestAsync( + global::Picsart.AutoSDKHookContext context) + { + return global::System.Threading.Tasks.Task.CompletedTask; + } + + /// + public virtual global::System.Threading.Tasks.Task OnAfterSuccessAsync( + global::Picsart.AutoSDKHookContext context) + { + return global::System.Threading.Tasks.Task.CompletedTask; + } + + /// + public virtual global::System.Threading.Tasks.Task OnAfterErrorAsync( + global::Picsart.AutoSDKHookContext context) + { + return global::System.Threading.Tasks.Task.CompletedTask; + } + } + + /// + /// Runtime metadata passed to generated SDK hooks. + /// + public sealed class AutoSDKHookContext + { + /// + /// The source OpenAPI operation id or generated fallback id. + /// + public string OperationId { get; set; } = string.Empty; + + /// + /// The generated C# method name. + /// + public string MethodName { get; set; } = string.Empty; + + /// + /// The OpenAPI path template for the operation. + /// + public string PathTemplate { get; set; } = string.Empty; + + /// + /// The HTTP method used for the request. + /// + public string HttpMethod { get; set; } = string.Empty; + + /// + /// The client's resolved base URI. + /// + public global::System.Uri? BaseUri { get; set; } + + /// + /// The outgoing HTTP request for the current attempt. + /// + public global::System.Net.Http.HttpRequestMessage Request { get; set; } = null!; + + /// + /// The HTTP response when one was received. + /// + public global::System.Net.Http.HttpResponseMessage? Response { get; set; } + + /// + /// The transport or processing exception when one was observed. + /// + public global::System.Exception? Exception { get; set; } + + /// + /// The client-wide runtime options. + /// + public global::Picsart.AutoSDKClientOptions ClientOptions { get; set; } = null!; + + /// + /// The per-request runtime options. + /// + public global::Picsart.AutoSDKRequestOptions? RequestOptions { get; set; } + + /// + /// The current attempt number, starting at 1. + /// + public int Attempt { get; set; } + + /// + /// The total number of attempts allowed for this request. + /// + public int MaxAttempts { get; set; } + + /// + /// Indicates whether the generated client will retry after this hook invocation. + /// + public bool WillRetry { get; set; } + + /// + /// The effective cancellation token for the current request attempt. + /// + public global::System.Threading.CancellationToken CancellationToken { get; set; } + } + + internal static class AutoSDKRequestOptionsSupport + { + internal static global::Picsart.AutoSDKHookContext CreateHookContext( + string operationId, + string methodName, + string pathTemplate, + string httpMethod, + global::System.Uri? baseUri, + global::System.Net.Http.HttpRequestMessage request, + global::System.Net.Http.HttpResponseMessage? response, + global::System.Exception? exception, + global::Picsart.AutoSDKClientOptions clientOptions, + global::Picsart.AutoSDKRequestOptions? requestOptions, + int attempt, + int maxAttempts, + bool willRetry, + global::System.Threading.CancellationToken cancellationToken) + { + return new global::Picsart.AutoSDKHookContext + { + OperationId = operationId ?? string.Empty, + MethodName = methodName ?? string.Empty, + PathTemplate = pathTemplate ?? string.Empty, + HttpMethod = httpMethod ?? string.Empty, + BaseUri = baseUri, + Request = request, + Response = response, + Exception = exception, + ClientOptions = clientOptions, + RequestOptions = requestOptions, + Attempt = attempt, + MaxAttempts = maxAttempts, + WillRetry = willRetry, + CancellationToken = cancellationToken, + }; + } + + internal static global::System.Threading.Tasks.Task OnBeforeRequestAsync( + global::Picsart.AutoSDKClientOptions clientOptions, + global::Picsart.AutoSDKHookContext context) + { + return InvokeHooksAsync(clientOptions, static (hook, hookContext) => hook.OnBeforeRequestAsync(hookContext), context); + } + + internal static global::System.Threading.Tasks.Task OnAfterSuccessAsync( + global::Picsart.AutoSDKClientOptions clientOptions, + global::Picsart.AutoSDKHookContext context) + { + return InvokeHooksAsync(clientOptions, static (hook, hookContext) => hook.OnAfterSuccessAsync(hookContext), context); + } + + internal static global::System.Threading.Tasks.Task OnAfterErrorAsync( + global::Picsart.AutoSDKClientOptions clientOptions, + global::Picsart.AutoSDKHookContext context) + { + return InvokeHooksAsync(clientOptions, static (hook, hookContext) => hook.OnAfterErrorAsync(hookContext), context); + } + + internal static bool GetReadResponseAsString( + global::Picsart.AutoSDKClientOptions clientOptions, + global::Picsart.AutoSDKRequestOptions? requestOptions, + bool fallbackValue) + { + return requestOptions?.ReadResponseAsString ?? + clientOptions.ReadResponseAsString ?? + fallbackValue; + } + + internal static global::System.Threading.CancellationTokenSource? CreateTimeoutCancellationTokenSource( + global::Picsart.AutoSDKClientOptions clientOptions, + global::Picsart.AutoSDKRequestOptions? requestOptions, + global::System.Threading.CancellationToken cancellationToken) + { + var timeout = requestOptions?.Timeout ?? clientOptions.Timeout; + if (!timeout.HasValue || timeout.Value <= global::System.TimeSpan.Zero) + { + return null; + } + + var cancellationTokenSource = global::System.Threading.CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); + cancellationTokenSource.CancelAfter(timeout.Value); + return cancellationTokenSource; + } + + internal static int GetMaxAttempts( + global::Picsart.AutoSDKClientOptions clientOptions, + global::Picsart.AutoSDKRequestOptions? requestOptions, + bool supportsRetry) + { + if (!supportsRetry) + { + return 1; + } + + var maxAttempts = requestOptions?.Retry?.MaxAttempts ?? + clientOptions.Retry?.MaxAttempts ?? + 1; + return maxAttempts < 1 ? 1 : maxAttempts; + } + + internal static async global::System.Threading.Tasks.Task DelayBeforeRetryAsync( + global::Picsart.AutoSDKClientOptions clientOptions, + global::Picsart.AutoSDKRequestOptions? requestOptions, + global::System.Threading.CancellationToken cancellationToken) + { + var delay = requestOptions?.Retry?.Delay ?? + clientOptions.Retry?.Delay; + if (!delay.HasValue || delay.Value <= global::System.TimeSpan.Zero) + { + return; + } + + await global::System.Threading.Tasks.Task.Delay(delay.Value, cancellationToken).ConfigureAwait(false); + } + + internal static bool ShouldRetryStatusCode( + global::System.Net.HttpStatusCode statusCode) + { + return (int)statusCode switch + { + 408 => true, + 429 => true, + 500 => true, + 502 => true, + 503 => true, + 504 => true, + _ => false, + }; + } + + internal static string AppendQueryParameters( + string path, + global::System.Collections.Generic.Dictionary clientParameters, + global::System.Collections.Generic.Dictionary? requestParameters) + { + var hasClientParameters = clientParameters != null && clientParameters.Count > 0; + var hasRequestParameters = requestParameters != null && requestParameters.Count > 0; + if (!hasClientParameters && !hasRequestParameters) + { + return path; + } + + var builder = new global::System.Text.StringBuilder(path ?? string.Empty); + var hasQuery = builder.ToString().Contains("?", global::System.StringComparison.Ordinal); + AppendParameters(builder, clientParameters, ref hasQuery); + AppendParameters(builder, requestParameters, ref hasQuery); + return builder.ToString(); + } + + internal static void ApplyHeaders( + global::System.Net.Http.HttpRequestMessage request, + global::System.Collections.Generic.Dictionary clientHeaders, + global::System.Collections.Generic.Dictionary? requestHeaders) + { + ApplyHeadersCore(request, clientHeaders); + ApplyHeadersCore(request, requestHeaders); + } + + private static void AppendParameters( + global::System.Text.StringBuilder builder, + global::System.Collections.Generic.Dictionary? parameters, + ref bool hasQuery) + { + if (parameters == null || parameters.Count == 0) + { + return; + } + + foreach (var parameter in parameters) + { + builder.Append(hasQuery ? '&' : '?'); + builder.Append(global::System.Uri.EscapeDataString(parameter.Key)); + builder.Append('='); + builder.Append(global::System.Uri.EscapeDataString(parameter.Value ?? string.Empty)); + hasQuery = true; + } + } + + private static void ApplyHeadersCore( + global::System.Net.Http.HttpRequestMessage request, + global::System.Collections.Generic.Dictionary? headers) + { + if (headers == null || headers.Count == 0) + { + return; + } + + foreach (var header in headers) + { + request.Headers.Remove(header.Key); + request.Content?.Headers.Remove(header.Key); + + if (!request.Headers.TryAddWithoutValidation(header.Key, header.Value ?? string.Empty) && + request.Content != null) + { + request.Content.Headers.TryAddWithoutValidation(header.Key, header.Value ?? string.Empty); + } + } + } + + private static async global::System.Threading.Tasks.Task InvokeHooksAsync( + global::Picsart.AutoSDKClientOptions clientOptions, + global::System.Func callback, + global::Picsart.AutoSDKHookContext context) + { + if (clientOptions.Hooks == null || clientOptions.Hooks.Count == 0) + { + return; + } + + foreach (var hook in clientOptions.Hooks) + { + if (hook == null) + { + continue; + } + + await callback(hook, context).ConfigureAwait(false); + } + } + } +} \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.PathBuilder.g.cs b/src/libs/Picsart/Generated/Picsart.PathBuilder.g.cs index 5183ff7..e3bd348 100644 --- a/src/libs/Picsart/Generated/Picsart.PathBuilder.g.cs +++ b/src/libs/Picsart/Generated/Picsart.PathBuilder.g.cs @@ -275,6 +275,11 @@ public class EndPointAuthorization /// public string Type { get; set; } = string.Empty; + /// + /// + /// + public string SchemeId { get; set; } = string.Empty; + /// /// /// diff --git a/src/libs/Picsart/Generated/Picsart.PicsartClient.Authorizations.ApiKeyInHeader.g.cs b/src/libs/Picsart/Generated/Picsart.PicsartClient.Authorizations.ApiKeyInHeader.g.cs index d3245b1..e52343d 100644 --- a/src/libs/Picsart/Generated/Picsart.PicsartClient.Authorizations.ApiKeyInHeader.g.cs +++ b/src/libs/Picsart/Generated/Picsart.PicsartClient.Authorizations.ApiKeyInHeader.g.cs @@ -26,6 +26,7 @@ public void AuthorizeUsingApiKeyInHeader( Authorizations.Add(new global::Picsart.EndPointAuthorization { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", Value = apiKey, diff --git a/src/libs/Picsart/Generated/Picsart.PicsartClient.g.cs b/src/libs/Picsart/Generated/Picsart.PicsartClient.g.cs index 3b13892..75f91e4 100644 --- a/src/libs/Picsart/Generated/Picsart.PicsartClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.PicsartClient.g.cs @@ -33,6 +33,9 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -42,7 +45,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public GenAIInpaintingImage2ImageClient GenAIInpaintingImage2Image => new GenAIInpaintingImage2ImageClient(HttpClient, authorizations: Authorizations) + public GenAIInpaintingImage2ImageClient GenAIInpaintingImage2Image => new GenAIInpaintingImage2ImageClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -51,7 +54,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public GenAIText2AudioClient GenAIText2Audio => new GenAIText2AudioClient(HttpClient, authorizations: Authorizations) + public GenAIText2AudioClient GenAIText2Audio => new GenAIText2AudioClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -60,7 +63,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public GenAIText2ImageClient GenAIText2Image => new GenAIText2ImageClient(HttpClient, authorizations: Authorizations) + public GenAIText2ImageClient GenAIText2Image => new GenAIText2ImageClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -69,7 +72,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public GenAIText2TextClient GenAIText2Text => new GenAIText2TextClient(HttpClient, authorizations: Authorizations) + public GenAIText2TextClient GenAIText2Text => new GenAIText2TextClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -78,7 +81,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public GenAIText2VideoImage2VideoClient GenAIText2VideoImage2Video => new GenAIText2VideoImage2VideoClient(HttpClient, authorizations: Authorizations) + public GenAIText2VideoImage2VideoClient GenAIText2VideoImage2Video => new GenAIText2VideoImage2VideoClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -87,7 +90,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public GenAIUtilitiesClient GenAIUtilities => new GenAIUtilitiesClient(HttpClient, authorizations: Authorizations) + public GenAIUtilitiesClient GenAIUtilities => new GenAIUtilitiesClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -96,7 +99,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public ImageClassificationClient ImageClassification => new ImageClassificationClient(HttpClient, authorizations: Authorizations) + public ImageClassificationClient ImageClassification => new ImageClassificationClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -105,7 +108,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public ImageContentGenerationClient ImageContentGeneration => new ImageContentGenerationClient(HttpClient, authorizations: Authorizations) + public ImageContentGenerationClient ImageContentGeneration => new ImageContentGenerationClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -114,7 +117,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public ImageConversionClient ImageConversion => new ImageConversionClient(HttpClient, authorizations: Authorizations) + public ImageConversionClient ImageConversion => new ImageConversionClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -123,7 +126,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public ImageEditingClient ImageEditing => new ImageEditingClient(HttpClient, authorizations: Authorizations) + public ImageEditingClient ImageEditing => new ImageEditingClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -132,7 +135,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public ImageEffectsClient ImageEffects => new ImageEffectsClient(HttpClient, authorizations: Authorizations) + public ImageEffectsClient ImageEffects => new ImageEffectsClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -141,7 +144,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public ImagePhotoEnhancementClient ImagePhotoEnhancement => new ImagePhotoEnhancementClient(HttpClient, authorizations: Authorizations) + public ImagePhotoEnhancementClient ImagePhotoEnhancement => new ImagePhotoEnhancementClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -150,7 +153,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public ImageRemoveBackgroundClient ImageRemoveBackground => new ImageRemoveBackgroundClient(HttpClient, authorizations: Authorizations) + public ImageRemoveBackgroundClient ImageRemoveBackground => new ImageRemoveBackgroundClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -159,7 +162,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public ImageSurfacemapClient ImageSurfacemap => new ImageSurfacemapClient(HttpClient, authorizations: Authorizations) + public ImageSurfacemapClient ImageSurfacemap => new ImageSurfacemapClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -168,7 +171,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public ImageUtilitiesClient ImageUtilities => new ImageUtilitiesClient(HttpClient, authorizations: Authorizations) + public ImageUtilitiesClient ImageUtilities => new ImageUtilitiesClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -177,7 +180,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public ImageWatermarkClient ImageWatermark => new ImageWatermarkClient(HttpClient, authorizations: Authorizations) + public ImageWatermarkClient ImageWatermark => new ImageWatermarkClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -186,7 +189,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public VdReplayClient VdReplay => new VdReplayClient(HttpClient, authorizations: Authorizations) + public VdReplayClient VdReplay => new VdReplayClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -195,7 +198,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public VdUtilitiesClient VdUtilities => new VdUtilitiesClient(HttpClient, authorizations: Authorizations) + public VdUtilitiesClient VdUtilities => new VdUtilitiesClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -204,7 +207,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public VdVariableDataContentClient VdVariableDataContent => new VdVariableDataContentClient(HttpClient, authorizations: Authorizations) + public VdVariableDataContentClient VdVariableDataContent => new VdVariableDataContentClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -213,7 +216,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public VideoAdsClient VideoAds => new VideoAdsClient(HttpClient, authorizations: Authorizations) + public VideoAdsClient VideoAds => new VideoAdsClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -222,7 +225,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public VideoAudioClient VideoAudio => new VideoAudioClient(HttpClient, authorizations: Authorizations) + public VideoAudioClient VideoAudio => new VideoAudioClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -231,7 +234,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public VideoEditClient VideoEdit => new VideoEditClient(HttpClient, authorizations: Authorizations) + public VideoEditClient VideoEdit => new VideoEditClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -240,7 +243,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public VideoEffectsClient VideoEffects => new VideoEffectsClient(HttpClient, authorizations: Authorizations) + public VideoEffectsClient VideoEffects => new VideoEffectsClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -249,7 +252,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public VideoMetadataClient VideoMetadata => new VideoMetadataClient(HttpClient, authorizations: Authorizations) + public VideoMetadataClient VideoMetadata => new VideoMetadataClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -258,7 +261,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public VideoRemoveBackgroundClient VideoRemoveBackground => new VideoRemoveBackgroundClient(HttpClient, authorizations: Authorizations) + public VideoRemoveBackgroundClient VideoRemoveBackground => new VideoRemoveBackgroundClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -267,7 +270,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public VideoTranscriptionsClient VideoTranscriptions => new VideoTranscriptionsClient(HttpClient, authorizations: Authorizations) + public VideoTranscriptionsClient VideoTranscriptions => new VideoTranscriptionsClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -276,7 +279,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public VideoUtilitiesClient VideoUtilities => new VideoUtilitiesClient(HttpClient, authorizations: Authorizations) + public VideoUtilitiesClient VideoUtilities => new VideoUtilitiesClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -285,7 +288,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public VideoVideoEnhancementClient VideoVideoEnhancement => new VideoVideoEnhancementClient(HttpClient, authorizations: Authorizations) + public VideoVideoEnhancementClient VideoVideoEnhancement => new VideoVideoEnhancementClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -294,7 +297,7 @@ public sealed partial class PicsartClient : global::Picsart.IPicsartClient, glob /// /// /// - public VideoWatermarkClient VideoWatermark => new VideoWatermarkClient(HttpClient, authorizations: Authorizations) + public VideoWatermarkClient VideoWatermark => new VideoWatermarkClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -313,11 +316,37 @@ public PicsartClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the PicsartClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public PicsartClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.Security.g.cs b/src/libs/Picsart/Generated/Picsart.Security.g.cs index 3d8fe77..56aece3 100644 --- a/src/libs/Picsart/Generated/Picsart.Security.g.cs +++ b/src/libs/Picsart/Generated/Picsart.Security.g.cs @@ -6,6 +6,8 @@ internal sealed class EndPointAuthorizationRequirement { internal string Type { get; set; } = string.Empty; + internal string SchemeId { get; set; } = string.Empty; + internal string Location { get; set; } = string.Empty; internal string Name { get; set; } = string.Empty; @@ -97,7 +99,18 @@ private static bool Matches( return requiredAuthorization.Type switch { - "OAuth2" => true, + "OAuth2" => string.Equals( + availableAuthorization.SchemeId, + requiredAuthorization.SchemeId, + global::System.StringComparison.Ordinal), + "OpenIdConnect" => string.Equals( + availableAuthorization.SchemeId, + requiredAuthorization.SchemeId, + global::System.StringComparison.Ordinal), + "MutualTLS" => string.Equals( + availableAuthorization.SchemeId, + requiredAuthorization.SchemeId, + global::System.StringComparison.Ordinal), "Http" => string.Equals( availableAuthorization.Name, requiredAuthorization.Name, diff --git a/src/libs/Picsart/Generated/Picsart.VdReplayClient.VdExportReplay.g.cs b/src/libs/Picsart/Generated/Picsart.VdReplayClient.VdExportReplay.g.cs index ad169e2..5a31e82 100644 --- a/src/libs/Picsart/Generated/Picsart.VdReplayClient.VdExportReplay.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VdReplayClient.VdExportReplay.g.cs @@ -14,6 +14,7 @@ public partial class VdReplayClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVdExportReplayResponseContent( /// Export your Replays with async API in background to optimize for performance and improve your user experience. Now you can export Print-Ready PDF only, but later more formats will be added to the support list. Feel free to reach out to our support team if you need updates to this API. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VdExportReplayAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VdExportReplayAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVdExportReplayResponseContent( /// Export your Replays with async API in background to optimize for performance and improve your user experience. Now you can export Print-Ready PDF only, but later more formats will be added to the support list. Feel free to reach out to our support team if you need updates to this API. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VdExportReplayAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessVdExportReplayResponseContent( securityRequirements: s_VdExportReplaySecurityRequirements, operationName: "VdExportReplayAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/vd/export/replay", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/vd/export/replay", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,622 +136,783 @@ partial void ProcessVdExportReplayResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVdExportReplayRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVdExportReplayResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VDError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Vd401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VDError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VDError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VDError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VDError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VDError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VDError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.VDError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVdExportReplayRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VDError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VDError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportReplay", + methodName: "VdExportReplayAsync", + pathTemplate: "\"/vd/export/replay\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportReplay", + methodName: "VdExportReplayAsync", + pathTemplate: "\"/vd/export/replay\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VDError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportReplay", + methodName: "VdExportReplayAsync", + pathTemplate: "\"/vd/export/replay\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VDError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVdExportReplayResponseContent( + response: __response); + ProcessVdExportReplayResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportReplay", + methodName: "VdExportReplayAsync", + pathTemplate: "\"/vd/export/replay\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportReplay", + methodName: "VdExportReplayAsync", + pathTemplate: "\"/vd/export/replay\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VDError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Vd401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VDError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VDError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VDError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VDError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VDError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VDError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.VDError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VDError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VDError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VDError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VDError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVdExportReplayResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VdExportReplayResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VdExportReplayResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VdExportReplayResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VdExportReplayResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// /// Export Replay
/// Export your Replays with async API in background to optimize for performance and improve your user experience. Now you can export Print-Ready PDF only, but later more formats will be added to the support list. Feel free to reach out to our support team if you need updates to this API. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VdExportReplayAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -733,6 +921,7 @@ partial void ProcessVdExportReplayResponseContent( return await VdExportReplayAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VdReplayClient.VdExportReplayGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.VdReplayClient.VdExportReplayGetresult.g.cs index 4b66c1a..724dab1 100644 --- a/src/libs/Picsart/Generated/Picsart.VdReplayClient.VdExportReplayGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VdReplayClient.VdExportReplayGetresult.g.cs @@ -14,6 +14,7 @@ public partial class VdReplayClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,14 +46,17 @@ partial void ProcessVdExportReplayGetresultResponseContent( /// Use this method, along with transaction_id, to retrieve the export replay's finished result (e.g. PDF). /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VdExportReplayGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VdExportReplayGetresultAsResponseAsync( transactionId: transactionId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,10 +67,12 @@ partial void ProcessVdExportReplayGetresultResponseContent( /// Use this method, along with transaction_id, to retrieve the export replay's finished result (e.g. PDF). /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VdExportReplayGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -81,22 +87,43 @@ partial void ProcessVdExportReplayGetresultResponseContent( securityRequirements: s_VdExportReplayGetresultSecurityRequirements, operationName: "VdExportReplayGetresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/vd/export/replay/{transactionId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/vd/export/replay/{transactionId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -106,611 +133,770 @@ partial void ProcessVdExportReplayGetresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVdExportReplayGetresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - transactionId: transactionId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVdExportReplayGetresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VDError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Vd401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VDError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VDError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VDError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VDError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VDError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.VDError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VDError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVdExportReplayGetresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + transactionId: transactionId); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VDError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VDError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportReplayGetresult", + methodName: "VdExportReplayGetresultAsync", + pathTemplate: "$\"/vd/export/replay/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportReplayGetresult", + methodName: "VdExportReplayGetresultAsync", + pathTemplate: "$\"/vd/export/replay/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VDError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportReplayGetresult", + methodName: "VdExportReplayGetresultAsync", + pathTemplate: "$\"/vd/export/replay/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VDError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVdExportReplayGetresultResponseContent( + response: __response); + ProcessVdExportReplayGetresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportReplayGetresult", + methodName: "VdExportReplayGetresultAsync", + pathTemplate: "$\"/vd/export/replay/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportReplayGetresult", + methodName: "VdExportReplayGetresultAsync", + pathTemplate: "$\"/vd/export/replay/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VDError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Vd401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VDError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VDError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VDError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VDError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VDError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.VDError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VDError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VDError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VDError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VDError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VDError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVdExportReplayGetresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VdExportReplayGetresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VdExportReplayGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VdExportReplayGetresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VdExportReplayGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Picsart/Generated/Picsart.VdReplayClient.g.cs b/src/libs/Picsart/Generated/Picsart.VdReplayClient.g.cs index 91352a5..31eaa15 100644 --- a/src/libs/Picsart/Generated/Picsart.VdReplayClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VdReplayClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class VdReplayClient : global::Picsart.IVdReplayClient, gl #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public VdReplayClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the VdReplayClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public VdReplayClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.VdUtilitiesClient.VdCreditsBalance.g.cs b/src/libs/Picsart/Generated/Picsart.VdUtilitiesClient.VdCreditsBalance.g.cs index 98f209b..2c78ebd 100644 --- a/src/libs/Picsart/Generated/Picsart.VdUtilitiesClient.VdCreditsBalance.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VdUtilitiesClient.VdCreditsBalance.g.cs @@ -14,6 +14,7 @@ public partial class VdUtilitiesClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -42,12 +43,15 @@ partial void ProcessVdCreditsBalanceResponseContent( /// Credits Balance
/// Check your balance of credits. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VdCreditsBalanceAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VdCreditsBalanceAsResponseAsync( + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -57,9 +61,11 @@ partial void ProcessVdCreditsBalanceResponseContent( /// Credits Balance
/// Check your balance of credits. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VdCreditsBalanceAsResponseAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -73,22 +79,43 @@ partial void ProcessVdCreditsBalanceResponseContent( securityRequirements: s_VdCreditsBalanceSecurityRequirements, operationName: "VdCreditsBalanceAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/vd/balance", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/vd/balance", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -98,610 +125,769 @@ partial void ProcessVdCreditsBalanceResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVdCreditsBalanceRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVdCreditsBalanceResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VDError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Vd401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VDError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VDError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VDError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VDError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VDError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VDError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.VDError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVdCreditsBalanceRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VDError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VDError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdCreditsBalance", + methodName: "VdCreditsBalanceAsync", + pathTemplate: "\"/vd/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdCreditsBalance", + methodName: "VdCreditsBalanceAsync", + pathTemplate: "\"/vd/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VDError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdCreditsBalance", + methodName: "VdCreditsBalanceAsync", + pathTemplate: "\"/vd/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VDError? __value_503 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVdCreditsBalanceResponseContent( + response: __response); + ProcessVdCreditsBalanceResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdCreditsBalance", + methodName: "VdCreditsBalanceAsync", + pathTemplate: "\"/vd/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdCreditsBalance", + methodName: "VdCreditsBalanceAsync", + pathTemplate: "\"/vd/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VDError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Vd401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VDError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VDError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VDError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VDError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VDError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VDError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.VDError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VDError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VDError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VDError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VDError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVdCreditsBalanceResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VdCreditsBalanceResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VdCreditsBalanceResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VdCreditsBalanceResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VdCreditsBalanceResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Picsart/Generated/Picsart.VdUtilitiesClient.g.cs b/src/libs/Picsart/Generated/Picsart.VdUtilitiesClient.g.cs index 80065e1..d567c8c 100644 --- a/src/libs/Picsart/Generated/Picsart.VdUtilitiesClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VdUtilitiesClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class VdUtilitiesClient : global::Picsart.IVdUtilitiesClie #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public VdUtilitiesClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the VdUtilitiesClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public VdUtilitiesClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.VdDescribeVariableDataContent.g.cs b/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.VdDescribeVariableDataContent.g.cs index 179e282..d9f1c21 100644 --- a/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.VdDescribeVariableDataContent.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.VdDescribeVariableDataContent.g.cs @@ -14,6 +14,7 @@ public partial class VdVariableDataContentClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVdDescribeVariableDataContentResponseContent( /// Describes the Replay. Lists all variable data fields and their types: image, text, etc. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VdDescribeVariableDataContentAsync( global::Picsart.VDTemplateParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VdDescribeVariableDataContentAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVdDescribeVariableDataContentResponseContent( /// Describes the Replay. Lists all variable data fields and their types: image, text, etc. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VdDescribeVariableDataContentAsResponseAsync( global::Picsart.VDTemplateParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -86,22 +92,43 @@ partial void ProcessVdDescribeVariableDataContentResponseContent( securityRequirements: s_VdDescribeVariableDataContentSecurityRequirements, operationName: "VdDescribeVariableDataContentAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/vd/variable-data-content/describe", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/vd/variable-data-content/describe", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -111,640 +138,799 @@ partial void ProcessVdDescribeVariableDataContentResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - if (request.TemplateId != default) - { - - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.TemplateId}"), - name: "\"template_id\""); - } - if (request.Template != default) - { - - var __contentTemplate = new global::System.Net.Http.ByteArrayContent(request.Template ?? global::System.Array.Empty()); - __httpRequestContent.Add( - content: __contentTemplate, - name: "\"template\"", - fileName: request.Templatename != null ? $"\"{request.Templatename}\"" : string.Empty); - if (__contentTemplate.Headers.ContentDisposition != null) - { - __contentTemplate.Headers.ContentDisposition.FileNameStar = null; - } - } - if (request.TemplateUrl != default) - { - - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.TemplateUrl}"), - name: "\"template_url\""); - } - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVdDescribeVariableDataContentRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVdDescribeVariableDataContentResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VDError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Vd401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VDError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VDError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VDError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VDError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VDError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VDError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.VDError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (request.TemplateId != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.TemplateId}"), + name: "\"template_id\""); + } + if (request.Template != default) + { + + var __contentTemplate = new global::System.Net.Http.ByteArrayContent(request.Template ?? global::System.Array.Empty()); + __httpRequestContent.Add( + content: __contentTemplate, + name: "\"template\"", + fileName: request.Templatename != null ? $"\"{request.Templatename}\"" : string.Empty); + if (__contentTemplate.Headers.ContentDisposition != null) + { + __contentTemplate.Headers.ContentDisposition.FileNameStar = null; + } + } + if (request.TemplateUrl != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.TemplateUrl}"), + name: "\"template_url\""); + } + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVdDescribeVariableDataContentRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VDError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VDError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdDescribeVariableDataContent", + methodName: "VdDescribeVariableDataContentAsync", + pathTemplate: "\"/vd/variable-data-content/describe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdDescribeVariableDataContent", + methodName: "VdDescribeVariableDataContentAsync", + pathTemplate: "\"/vd/variable-data-content/describe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VDError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdDescribeVariableDataContent", + methodName: "VdDescribeVariableDataContentAsync", + pathTemplate: "\"/vd/variable-data-content/describe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VDError? __value_503 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVdDescribeVariableDataContentResponseContent( + response: __response); + ProcessVdDescribeVariableDataContentResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdDescribeVariableDataContent", + methodName: "VdDescribeVariableDataContentAsync", + pathTemplate: "\"/vd/variable-data-content/describe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdDescribeVariableDataContent", + methodName: "VdDescribeVariableDataContentAsync", + pathTemplate: "\"/vd/variable-data-content/describe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VDError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Vd401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VDError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VDError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VDError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VDError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VDError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VDError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.VDError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VDError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VDError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VDError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VDError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVdDescribeVariableDataContentResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VdDescribeVariableDataContentResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VdDescribeVariableDataContentResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VdDescribeVariableDataContentResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VdDescribeVariableDataContentResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// @@ -763,6 +949,7 @@ partial void ProcessVdDescribeVariableDataContentResponseContent( /// /// Source replay URL. (If this parameter is present, the other template source parameters must be empty.) /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VdDescribeVariableDataContentAsync( @@ -770,6 +957,7 @@ partial void ProcessVdDescribeVariableDataContentResponseContent( byte[]? template = default, string? templatename = default, string? templateUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.VDTemplateParameters @@ -782,6 +970,7 @@ partial void ProcessVdDescribeVariableDataContentResponseContent( return await VdDescribeVariableDataContentAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.VdExportVariableDataContent.g.cs b/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.VdExportVariableDataContent.g.cs index 5205909..8c04bc3 100644 --- a/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.VdExportVariableDataContent.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.VdExportVariableDataContent.g.cs @@ -14,6 +14,7 @@ public partial class VdVariableDataContentClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -46,16 +47,19 @@ partial void ProcessVdExportVariableDataContentResponseContent( /// Customize the output with your data. Here you can provide a CSV file with up to 50 rows and map your data to the variables in the Replay file. For each row in the data file, this service will export a file of the requested type. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VdExportVariableDataContentAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VdExportVariableDataContentAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -67,11 +71,13 @@ partial void ProcessVdExportVariableDataContentResponseContent( /// Customize the output with your data. Here you can provide a CSV file with up to 50 rows and map your data to the variables in the Replay file. For each row in the data file, this service will export a file of the requested type. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VdExportVariableDataContentAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -86,22 +92,43 @@ partial void ProcessVdExportVariableDataContentResponseContent( securityRequirements: s_VdExportVariableDataContentSecurityRequirements, operationName: "VdExportVariableDataContentAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/vd/export/variable-data-content", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/vd/export/variable-data-content", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -111,613 +138,772 @@ partial void ProcessVdExportVariableDataContentResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVdExportVariableDataContentRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVdExportVariableDataContentResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VDError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Vd401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VDError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VDError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VDError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VDError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VDError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VDError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.VDError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVdExportVariableDataContentRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VDError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VDError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportVariableDataContent", + methodName: "VdExportVariableDataContentAsync", + pathTemplate: "\"/vd/export/variable-data-content\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportVariableDataContent", + methodName: "VdExportVariableDataContentAsync", + pathTemplate: "\"/vd/export/variable-data-content\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VDError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportVariableDataContent", + methodName: "VdExportVariableDataContentAsync", + pathTemplate: "\"/vd/export/variable-data-content\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VDError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVdExportVariableDataContentResponseContent( + response: __response); + ProcessVdExportVariableDataContentResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportVariableDataContent", + methodName: "VdExportVariableDataContentAsync", + pathTemplate: "\"/vd/export/variable-data-content\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportVariableDataContent", + methodName: "VdExportVariableDataContentAsync", + pathTemplate: "\"/vd/export/variable-data-content\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VDError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Vd401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VDError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VDError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VDError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VDError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VDError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VDError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.VDError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VDError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VDError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VDError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VDError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVdExportVariableDataContentResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VdExportVariableDataContentResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VdExportVariableDataContentResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VdExportVariableDataContentResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VdExportVariableDataContentResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// @@ -725,9 +911,11 @@ partial void ProcessVdExportVariableDataContentResponseContent( /// Export your Replays with async API in background to optimize for performance and improve your user experience.
/// Customize the output with your data. Here you can provide a CSV file with up to 50 rows and map your data to the variables in the Replay file. For each row in the data file, this service will export a file of the requested type. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VdExportVariableDataContentAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -736,6 +924,7 @@ partial void ProcessVdExportVariableDataContentResponseContent( return await VdExportVariableDataContentAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.VdExportVariableDataContentGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.VdExportVariableDataContentGetresult.g.cs index 565750f..f81b161 100644 --- a/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.VdExportVariableDataContentGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.VdExportVariableDataContentGetresult.g.cs @@ -14,6 +14,7 @@ public partial class VdVariableDataContentClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,14 +46,17 @@ partial void ProcessVdExportVariableDataContentGetresultResponseContent( /// Use this method, along with transaction_id, to retrieve the export variable data content's finished results (e.g. list of PDF file URLs). /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VdExportVariableDataContentGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VdExportVariableDataContentGetresultAsResponseAsync( transactionId: transactionId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,10 +67,12 @@ partial void ProcessVdExportVariableDataContentGetresultResponseContent( /// Use this method, along with transaction_id, to retrieve the export variable data content's finished results (e.g. list of PDF file URLs). /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VdExportVariableDataContentGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -81,22 +87,43 @@ partial void ProcessVdExportVariableDataContentGetresultResponseContent( securityRequirements: s_VdExportVariableDataContentGetresultSecurityRequirements, operationName: "VdExportVariableDataContentGetresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/vd/export/variable-data-content/{transactionId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/vd/export/variable-data-content/{transactionId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -106,611 +133,770 @@ partial void ProcessVdExportVariableDataContentGetresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVdExportVariableDataContentGetresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - transactionId: transactionId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVdExportVariableDataContentGetresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VDError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Vd401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VDError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VDError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VDError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VDError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VDError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.VDError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VDError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVdExportVariableDataContentGetresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + transactionId: transactionId); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VDError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VDError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportVariableDataContentGetresult", + methodName: "VdExportVariableDataContentGetresultAsync", + pathTemplate: "$\"/vd/export/variable-data-content/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportVariableDataContentGetresult", + methodName: "VdExportVariableDataContentGetresultAsync", + pathTemplate: "$\"/vd/export/variable-data-content/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VDError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportVariableDataContentGetresult", + methodName: "VdExportVariableDataContentGetresultAsync", + pathTemplate: "$\"/vd/export/variable-data-content/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VDError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVdExportVariableDataContentGetresultResponseContent( + response: __response); + ProcessVdExportVariableDataContentGetresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportVariableDataContentGetresult", + methodName: "VdExportVariableDataContentGetresultAsync", + pathTemplate: "$\"/vd/export/variable-data-content/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VdExportVariableDataContentGetresult", + methodName: "VdExportVariableDataContentGetresultAsync", + pathTemplate: "$\"/vd/export/variable-data-content/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VDError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VDError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Vd401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Vd401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VDError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VDError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VDError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VDError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VDError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VDError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VDError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VDError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VDError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VDError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.VDError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.VDError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VDError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VDError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VDError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VDError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VDError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VDError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VDError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VDError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VDError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VDError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVdExportVariableDataContentGetresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VdExportVariableDataContentGetresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VdExportVariableDataContentGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VdExportVariableDataContentGetresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VdExportVariableDataContentGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.g.cs b/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.g.cs index ab2d338..2a146fe 100644 --- a/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VdVariableDataContentClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class VdVariableDataContentClient : global::Picsart.IVdVar #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public VdVariableDataContentClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the VdVariableDataContentClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public VdVariableDataContentClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.VideoAdsClient.VideoEncodeCtv.g.cs b/src/libs/Picsart/Generated/Picsart.VideoAdsClient.VideoEncodeCtv.g.cs index df8e010..c930f02 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoAdsClient.VideoEncodeCtv.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoAdsClient.VideoEncodeCtv.g.cs @@ -14,6 +14,7 @@ public partial class VideoAdsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoEncodeCtvResponseContent( /// Converts your original video to meet <a href="https://docs.picsart.io/docs/ctv-ads-format-requirements/">CTV requirements</a>. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoEncodeCtvAsync( global::Picsart.VideoVideoParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoEncodeCtvAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoEncodeCtvResponseContent( /// Converts your original video to meet <a href="https://docs.picsart.io/docs/ctv-ads-format-requirements/">CTV requirements</a>. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoEncodeCtvAsResponseAsync( global::Picsart.VideoVideoParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -86,22 +92,43 @@ partial void ProcessVideoEncodeCtvResponseContent( securityRequirements: s_VideoEncodeCtvSecurityRequirements, operationName: "VideoEncodeCtvAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/encode/ctv", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/encode/ctv", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -111,580 +138,739 @@ partial void ProcessVideoEncodeCtvResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoEncodeCtvRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoEncodeCtvResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoEncodeCtvRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoEncodeCtv", + methodName: "VideoEncodeCtvAsync", + pathTemplate: "\"/video/encode/ctv\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoEncodeCtv", + methodName: "VideoEncodeCtvAsync", + pathTemplate: "\"/video/encode/ctv\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoEncodeCtv", + methodName: "VideoEncodeCtvAsync", + pathTemplate: "\"/video/encode/ctv\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoEncodeCtvResponseContent( + response: __response); + ProcessVideoEncodeCtvResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoEncodeCtvResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoEncodeCtv", + methodName: "VideoEncodeCtvAsync", + pathTemplate: "\"/video/encode/ctv\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoEncodeCtvResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoEncodeCtv", + methodName: "VideoEncodeCtvAsync", + pathTemplate: "\"/video/encode/ctv\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoEncodeCtvResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoEncodeCtvResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoEncodeCtvResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Make Video CTV-Compatible
@@ -693,10 +879,12 @@ partial void ProcessVideoEncodeCtvResponseContent( /// /// Source video URL. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoEncodeCtvAsync( string? videoUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.VideoVideoParameters @@ -706,6 +894,7 @@ partial void ProcessVideoEncodeCtvResponseContent( return await VideoEncodeCtvAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoAdsClient.g.cs b/src/libs/Picsart/Generated/Picsart.VideoAdsClient.g.cs index b68fa94..d37144f 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoAdsClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoAdsClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class VideoAdsClient : global::Picsart.IVideoAdsClient, gl #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public VideoAdsClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the VideoAdsClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public VideoAdsClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.VideoAudioClient.VideoAdjustAudio.g.cs b/src/libs/Picsart/Generated/Picsart.VideoAudioClient.VideoAdjustAudio.g.cs index 00a93a7..bcd44c3 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoAudioClient.VideoAdjustAudio.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoAudioClient.VideoAdjustAudio.g.cs @@ -14,6 +14,7 @@ public partial class VideoAudioClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoAdjustAudioResponseContent( /// Adjusts the input video's audio volume, allows to add a new audio channel and control its volume. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoAdjustAudioAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoAdjustAudioAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoAdjustAudioResponseContent( /// Adjusts the input video's audio volume, allows to add a new audio channel and control its volume. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoAdjustAudioAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessVideoAdjustAudioResponseContent( securityRequirements: s_VideoAdjustAudioSecurityRequirements, operationName: "VideoAdjustAudioAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/audio/adjust", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/audio/adjust", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,588 +136,749 @@ partial void ProcessVideoAdjustAudioResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoAdjustAudioRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoAdjustAudioResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoAdjustAudioRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAdjustAudio", + methodName: "VideoAdjustAudioAsync", + pathTemplate: "\"/video/audio/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAdjustAudio", + methodName: "VideoAdjustAudioAsync", + pathTemplate: "\"/video/audio/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAdjustAudio", + methodName: "VideoAdjustAudioAsync", + pathTemplate: "\"/video/audio/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoAdjustAudioResponseContent( + response: __response); + ProcessVideoAdjustAudioResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoAdjustAudioResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAdjustAudio", + methodName: "VideoAdjustAudioAsync", + pathTemplate: "\"/video/audio/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoAdjustAudioResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAdjustAudio", + methodName: "VideoAdjustAudioAsync", + pathTemplate: "\"/video/audio/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoAdjustAudioResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoAdjustAudioResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoAdjustAudioResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Adjust Audio
/// Adjusts the input video's audio volume, allows to add a new audio channel and control its volume. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoAdjustAudioAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -699,6 +887,7 @@ partial void ProcessVideoAdjustAudioResponseContent( return await VideoAdjustAudioAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoAudioClient.VideoExtractAudio.g.cs b/src/libs/Picsart/Generated/Picsart.VideoAudioClient.VideoExtractAudio.g.cs index 3abb0d1..d47d5ed 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoAudioClient.VideoExtractAudio.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoAudioClient.VideoExtractAudio.g.cs @@ -14,6 +14,7 @@ public partial class VideoAudioClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoExtractAudioResponseContent( /// Extract the input video's audio channel. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoExtractAudioAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoExtractAudioAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoExtractAudioResponseContent( /// Extract the input video's audio channel. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoExtractAudioAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessVideoExtractAudioResponseContent( securityRequirements: s_VideoExtractAudioSecurityRequirements, operationName: "VideoExtractAudioAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/export/audio", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/export/audio", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,588 +136,749 @@ partial void ProcessVideoExtractAudioResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoExtractAudioRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoExtractAudioResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoExtractAudioRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoExtractAudio", + methodName: "VideoExtractAudioAsync", + pathTemplate: "\"/video/export/audio\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoExtractAudio", + methodName: "VideoExtractAudioAsync", + pathTemplate: "\"/video/export/audio\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoExtractAudio", + methodName: "VideoExtractAudioAsync", + pathTemplate: "\"/video/export/audio\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoExtractAudioResponseContent( + response: __response); + ProcessVideoExtractAudioResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoExtractAudioResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoExtractAudio", + methodName: "VideoExtractAudioAsync", + pathTemplate: "\"/video/export/audio\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoExtractAudioResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoExtractAudio", + methodName: "VideoExtractAudioAsync", + pathTemplate: "\"/video/export/audio\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoExtractAudioResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoExtractAudioResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoExtractAudioResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Extract Audio
/// Extract the input video's audio channel. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoExtractAudioAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -699,6 +887,7 @@ partial void ProcessVideoExtractAudioResponseContent( return await VideoExtractAudioAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoAudioClient.g.cs b/src/libs/Picsart/Generated/Picsart.VideoAudioClient.g.cs index 3969a39..ae82b43 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoAudioClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoAudioClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class VideoAudioClient : global::Picsart.IVideoAudioClient #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public VideoAudioClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the VideoAudioClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public VideoAudioClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoConcat.g.cs b/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoConcat.g.cs index 867d706..9605d6d 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoConcat.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoConcat.g.cs @@ -14,6 +14,7 @@ public partial class VideoEditClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoConcatResponseContent( /// Concatenate several videos clips and images with transitions into one timeline. Helpful when adding intro/outro- or creating slideshows. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoConcatAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoConcatAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoConcatResponseContent( /// Concatenate several videos clips and images with transitions into one timeline. Helpful when adding intro/outro- or creating slideshows. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoConcatAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessVideoConcatResponseContent( securityRequirements: s_VideoConcatSecurityRequirements, operationName: "VideoConcatAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/concat", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/concat", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,588 +136,749 @@ partial void ProcessVideoConcatResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoConcatRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoConcatResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoConcatRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoConcat", + methodName: "VideoConcatAsync", + pathTemplate: "\"/video/concat\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoConcat", + methodName: "VideoConcatAsync", + pathTemplate: "\"/video/concat\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoConcat", + methodName: "VideoConcatAsync", + pathTemplate: "\"/video/concat\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoConcatResponseContent( + response: __response); + ProcessVideoConcatResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoConcatResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoConcat", + methodName: "VideoConcatAsync", + pathTemplate: "\"/video/concat\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoConcatResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoConcat", + methodName: "VideoConcatAsync", + pathTemplate: "\"/video/concat\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoConcatResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoConcatResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoConcatResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Concatenate Videos and Images
/// Concatenate several videos clips and images with transitions into one timeline. Helpful when adding intro/outro- or creating slideshows. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoConcatAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -699,6 +887,7 @@ partial void ProcessVideoConcatResponseContent( return await VideoConcatAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoConcatHighlights.g.cs b/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoConcatHighlights.g.cs index e058a79..d872c73 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoConcatHighlights.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoConcatHighlights.g.cs @@ -14,6 +14,7 @@ public partial class VideoEditClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -44,16 +45,19 @@ partial void ProcessVideoConcatHighlightsResponseContent( /// Create a highlights video from the original one. This picks highlight clips and concatenates them into one output video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoConcatHighlightsAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoConcatHighlightsAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,11 +67,13 @@ partial void ProcessVideoConcatHighlightsResponseContent( /// Create a highlights video from the original one. This picks highlight clips and concatenates them into one output video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoConcatHighlightsAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -82,22 +88,43 @@ partial void ProcessVideoConcatHighlightsResponseContent( securityRequirements: s_VideoConcatHighlightsSecurityRequirements, operationName: "VideoConcatHighlightsAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/concat/highlights", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/concat/highlights", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -107,587 +134,748 @@ partial void ProcessVideoConcatHighlightsResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoConcatHighlightsRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoConcatHighlightsResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoConcatHighlightsRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoConcatHighlights", + methodName: "VideoConcatHighlightsAsync", + pathTemplate: "\"/video/concat/highlights\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoConcatHighlights", + methodName: "VideoConcatHighlightsAsync", + pathTemplate: "\"/video/concat/highlights\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoConcatHighlights", + methodName: "VideoConcatHighlightsAsync", + pathTemplate: "\"/video/concat/highlights\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoConcatHighlightsResponseContent( + response: __response); + ProcessVideoConcatHighlightsResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoConcatHighlightsResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoConcatHighlights", + methodName: "VideoConcatHighlightsAsync", + pathTemplate: "\"/video/concat/highlights\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoConcatHighlightsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoConcatHighlights", + methodName: "VideoConcatHighlightsAsync", + pathTemplate: "\"/video/concat/highlights\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoConcatHighlightsResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoConcatHighlightsResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoConcatHighlightsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Create a highlights video from the original one. This picks highlight clips and concatenates them into one output video. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoConcatHighlightsAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -696,6 +884,7 @@ partial void ProcessVideoConcatHighlightsResponseContent( return await VideoConcatHighlightsAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoCrop.g.cs b/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoCrop.g.cs index 7ef4927..8dc3f98 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoCrop.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoCrop.g.cs @@ -14,6 +14,7 @@ public partial class VideoEditClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoCropResponseContent( /// Crop the input video clip to the desired size. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoCropAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoCropAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoCropResponseContent( /// Crop the input video clip to the desired size. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoCropAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessVideoCropResponseContent( securityRequirements: s_VideoCropSecurityRequirements, operationName: "VideoCropAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/crop", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/crop", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,588 +136,749 @@ partial void ProcessVideoCropResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoCropRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoCropResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoCropRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoCrop", + methodName: "VideoCropAsync", + pathTemplate: "\"/video/crop\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoCrop", + methodName: "VideoCropAsync", + pathTemplate: "\"/video/crop\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoCrop", + methodName: "VideoCropAsync", + pathTemplate: "\"/video/crop\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoCropResponseContent( + response: __response); + ProcessVideoCropResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoCropResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoCrop", + methodName: "VideoCropAsync", + pathTemplate: "\"/video/crop\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoCropResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoCrop", + methodName: "VideoCropAsync", + pathTemplate: "\"/video/crop\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoCropResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoCropResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoCropResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Crop Video
/// Crop the input video clip to the desired size. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoCropAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -699,6 +887,7 @@ partial void ProcessVideoCropResponseContent( return await VideoCropAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoEdit.g.cs b/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoEdit.g.cs index ac97fd6..f490bf3 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoEdit.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoEdit.g.cs @@ -14,6 +14,7 @@ public partial class VideoEditClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoEditResponseContent( /// Comprehensive editing with one operation. Apply effect, adjust, trim, crop, resize, change codecs, compression, framerates, etc. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoEditAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoEditAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoEditResponseContent( /// Comprehensive editing with one operation. Apply effect, adjust, trim, crop, resize, change codecs, compression, framerates, etc. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoEditAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessVideoEditResponseContent( securityRequirements: s_VideoEditSecurityRequirements, operationName: "VideoEditAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/edit", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/edit", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,588 +136,749 @@ partial void ProcessVideoEditResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoEditRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoEditResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoEditRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoEdit", + methodName: "VideoEditAsync", + pathTemplate: "\"/video/edit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoEdit", + methodName: "VideoEditAsync", + pathTemplate: "\"/video/edit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoEdit", + methodName: "VideoEditAsync", + pathTemplate: "\"/video/edit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoEditResponseContent( + response: __response); + ProcessVideoEditResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoEditResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoEdit", + methodName: "VideoEditAsync", + pathTemplate: "\"/video/edit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoEditResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoEdit", + methodName: "VideoEditAsync", + pathTemplate: "\"/video/edit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoEditResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoEditResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoEditResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Edit Video
/// Comprehensive editing with one operation. Apply effect, adjust, trim, crop, resize, change codecs, compression, framerates, etc. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoEditAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -699,6 +887,7 @@ partial void ProcessVideoEditResponseContent( return await VideoEditAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoFit.g.cs b/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoFit.g.cs index 0d8e3ea..f8ac298 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoFit.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoFit.g.cs @@ -14,6 +14,7 @@ public partial class VideoEditClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoFitResponseContent( /// Fit your original video to different ratios or width and height options. Apply fit when resizing and cropping is not an option. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoFitAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoFitAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoFitResponseContent( /// Fit your original video to different ratios or width and height options. Apply fit when resizing and cropping is not an option. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoFitAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessVideoFitResponseContent( securityRequirements: s_VideoFitSecurityRequirements, operationName: "VideoFitAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/fit", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/fit", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,588 +136,749 @@ partial void ProcessVideoFitResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoFitRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoFitResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoFitRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoFit", + methodName: "VideoFitAsync", + pathTemplate: "\"/video/fit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoFit", + methodName: "VideoFitAsync", + pathTemplate: "\"/video/fit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoFit", + methodName: "VideoFitAsync", + pathTemplate: "\"/video/fit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoFitResponseContent( + response: __response); + ProcessVideoFitResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoFitResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoFit", + methodName: "VideoFitAsync", + pathTemplate: "\"/video/fit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoFitResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoFit", + methodName: "VideoFitAsync", + pathTemplate: "\"/video/fit\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoFitResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoFitResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoFitResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Fit Video
/// Fit your original video to different ratios or width and height options. Apply fit when resizing and cropping is not an option. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoFitAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -699,6 +887,7 @@ partial void ProcessVideoFitResponseContent( return await VideoFitAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoTrim.g.cs b/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoTrim.g.cs index 4124024..7608413 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoTrim.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoEditClient.VideoTrim.g.cs @@ -14,6 +14,7 @@ public partial class VideoEditClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoTrimResponseContent( /// Trim the input video clip: pull a specific segment or trim to your desired video clip duration. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoTrimAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoTrimAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoTrimResponseContent( /// Trim the input video clip: pull a specific segment or trim to your desired video clip duration. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoTrimAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessVideoTrimResponseContent( securityRequirements: s_VideoTrimSecurityRequirements, operationName: "VideoTrimAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/trim", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/trim", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,588 +136,749 @@ partial void ProcessVideoTrimResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoTrimRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoTrimResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoTrimRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTrim", + methodName: "VideoTrimAsync", + pathTemplate: "\"/video/trim\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTrim", + methodName: "VideoTrimAsync", + pathTemplate: "\"/video/trim\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTrim", + methodName: "VideoTrimAsync", + pathTemplate: "\"/video/trim\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoTrimResponseContent( + response: __response); + ProcessVideoTrimResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoTrimResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTrim", + methodName: "VideoTrimAsync", + pathTemplate: "\"/video/trim\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoTrimResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTrim", + methodName: "VideoTrimAsync", + pathTemplate: "\"/video/trim\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoTrimResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoTrimResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoTrimResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Trim Video
/// Trim the input video clip: pull a specific segment or trim to your desired video clip duration. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoTrimAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -699,6 +887,7 @@ partial void ProcessVideoTrimResponseContent( return await VideoTrimAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoEditClient.g.cs b/src/libs/Picsart/Generated/Picsart.VideoEditClient.g.cs index f28f204..34402c4 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoEditClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoEditClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class VideoEditClient : global::Picsart.IVideoEditClient, #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public VideoEditClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the VideoEditClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public VideoEditClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.VideoEffectsClient.VideoAdjust.g.cs b/src/libs/Picsart/Generated/Picsart.VideoEffectsClient.VideoAdjust.g.cs index 89c4fc9..079b6d7 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoEffectsClient.VideoAdjust.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoEffectsClient.VideoAdjust.g.cs @@ -14,6 +14,7 @@ public partial class VideoEffectsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -56,16 +57,19 @@ partial void ProcessVideoAdjustResponseContent( /// If you choose an adjustment setting value out of the allowed range, the default value of 0 is used instead. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoAdjustAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoAdjustAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -87,11 +91,13 @@ partial void ProcessVideoAdjustResponseContent( /// If you choose an adjustment setting value out of the allowed range, the default value of 0 is used instead. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoAdjustAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -106,22 +112,43 @@ partial void ProcessVideoAdjustResponseContent( securityRequirements: s_VideoAdjustSecurityRequirements, operationName: "VideoAdjustAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/adjust", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/adjust", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -131,580 +158,739 @@ partial void ProcessVideoAdjustResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoAdjustRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoAdjustResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoAdjustRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAdjust", + methodName: "VideoAdjustAsync", + pathTemplate: "\"/video/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAdjust", + methodName: "VideoAdjustAsync", + pathTemplate: "\"/video/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAdjust", + methodName: "VideoAdjustAsync", + pathTemplate: "\"/video/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoAdjustResponseContent( + response: __response); + ProcessVideoAdjustResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoAdjustResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAdjust", + methodName: "VideoAdjustAsync", + pathTemplate: "\"/video/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoAdjustResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAdjust", + methodName: "VideoAdjustAsync", + pathTemplate: "\"/video/adjust\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoAdjustResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoAdjustResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoAdjustResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Adjust Video
@@ -721,9 +907,11 @@ partial void ProcessVideoAdjustResponseContent( /// * Adjust vignette
/// If you choose an adjustment setting value out of the allowed range, the default value of 0 is used instead. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoAdjustAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -732,6 +920,7 @@ partial void ProcessVideoAdjustResponseContent( return await VideoAdjustAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoEffectsClient.VideoApplyEffect.g.cs b/src/libs/Picsart/Generated/Picsart.VideoEffectsClient.VideoApplyEffect.g.cs index 4ff65b8..0e49397 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoEffectsClient.VideoApplyEffect.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoEffectsClient.VideoApplyEffect.g.cs @@ -14,6 +14,7 @@ public partial class VideoEffectsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoApplyEffectResponseContent( /// Apply up to 24 different effects to a video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoApplyEffectAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoApplyEffectAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoApplyEffectResponseContent( /// Apply up to 24 different effects to a video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoApplyEffectAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessVideoApplyEffectResponseContent( securityRequirements: s_VideoApplyEffectSecurityRequirements, operationName: "VideoApplyEffectAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/effects", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/effects", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,588 +136,749 @@ partial void ProcessVideoApplyEffectResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoApplyEffectRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoApplyEffectResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoApplyEffectRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoApplyEffect", + methodName: "VideoApplyEffectAsync", + pathTemplate: "\"/video/effects\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoApplyEffect", + methodName: "VideoApplyEffectAsync", + pathTemplate: "\"/video/effects\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoApplyEffect", + methodName: "VideoApplyEffectAsync", + pathTemplate: "\"/video/effects\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoApplyEffectResponseContent( + response: __response); + ProcessVideoApplyEffectResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoApplyEffectResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoApplyEffect", + methodName: "VideoApplyEffectAsync", + pathTemplate: "\"/video/effects\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoApplyEffectResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoApplyEffect", + methodName: "VideoApplyEffectAsync", + pathTemplate: "\"/video/effects\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoApplyEffectResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoApplyEffectResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoApplyEffectResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Video Effects
/// Apply up to 24 different effects to a video. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoApplyEffectAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -699,6 +887,7 @@ partial void ProcessVideoApplyEffectResponseContent( return await VideoApplyEffectAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoEffectsClient.g.cs b/src/libs/Picsart/Generated/Picsart.VideoEffectsClient.g.cs index fea882f..f64d404 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoEffectsClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoEffectsClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class VideoEffectsClient : global::Picsart.IVideoEffectsCl #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public VideoEffectsClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the VideoEffectsClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public VideoEffectsClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoGetThumbnail.g.cs b/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoGetThumbnail.g.cs index cd61d88..0b83d7a 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoGetThumbnail.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoGetThumbnail.g.cs @@ -14,6 +14,7 @@ public partial class VideoMetadataClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoGetThumbnailResponseContent( /// Extracts (reads) Video Thumbnail. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoGetThumbnailAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoGetThumbnailAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoGetThumbnailResponseContent( /// Extracts (reads) Video Thumbnail. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoGetThumbnailAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessVideoGetThumbnailResponseContent( securityRequirements: s_VideoGetThumbnailSecurityRequirements, operationName: "VideoGetThumbnailAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/metadata/thumbnail/extract", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/metadata/thumbnail/extract", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,588 +136,749 @@ partial void ProcessVideoGetThumbnailResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoGetThumbnailRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoGetThumbnailResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoGetThumbnailRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetThumbnail", + methodName: "VideoGetThumbnailAsync", + pathTemplate: "\"/video/metadata/thumbnail/extract\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetThumbnail", + methodName: "VideoGetThumbnailAsync", + pathTemplate: "\"/video/metadata/thumbnail/extract\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetThumbnail", + methodName: "VideoGetThumbnailAsync", + pathTemplate: "\"/video/metadata/thumbnail/extract\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoGetThumbnailResponseContent( + response: __response); + ProcessVideoGetThumbnailResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoGetThumbnailResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetThumbnail", + methodName: "VideoGetThumbnailAsync", + pathTemplate: "\"/video/metadata/thumbnail/extract\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoGetThumbnailResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetThumbnail", + methodName: "VideoGetThumbnailAsync", + pathTemplate: "\"/video/metadata/thumbnail/extract\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoGetThumbnailResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoGetThumbnailResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoGetThumbnailResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Get Video Thumbnail
/// Extracts (reads) Video Thumbnail. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoGetThumbnailAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -699,6 +887,7 @@ partial void ProcessVideoGetThumbnailResponseContent( return await VideoGetThumbnailAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoMetadata.g.cs b/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoMetadata.g.cs index 9859bf0..aba7307 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoMetadata.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoMetadata.g.cs @@ -14,6 +14,7 @@ public partial class VideoMetadataClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoMetadataResponseContent( /// Analysis the Video and provides the Metadata. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoMetadataAsync( global::Picsart.VideoVideoParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoMetadataAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoMetadataResponseContent( /// Analysis the Video and provides the Metadata. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoMetadataAsResponseAsync( global::Picsart.VideoVideoParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -86,22 +92,43 @@ partial void ProcessVideoMetadataResponseContent( securityRequirements: s_VideoMetadataSecurityRequirements, operationName: "VideoMetadataAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/metadata", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/metadata", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -111,580 +138,739 @@ partial void ProcessVideoMetadataResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoMetadataRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoMetadataResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoMetadataRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoMetadata", + methodName: "VideoMetadataAsync", + pathTemplate: "\"/video/metadata\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoMetadata", + methodName: "VideoMetadataAsync", + pathTemplate: "\"/video/metadata\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoMetadata", + methodName: "VideoMetadataAsync", + pathTemplate: "\"/video/metadata\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoMetadataResponseContent( + response: __response); + ProcessVideoMetadataResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoMetadataResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoMetadata", + methodName: "VideoMetadataAsync", + pathTemplate: "\"/video/metadata\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoMetadataResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoMetadata", + methodName: "VideoMetadataAsync", + pathTemplate: "\"/video/metadata\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoMetadataResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoMetadataResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoMetadataResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Get Video Metadata
@@ -693,10 +879,12 @@ partial void ProcessVideoMetadataResponseContent( /// /// Source video URL. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoMetadataAsync( string? videoUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.VideoVideoParameters @@ -706,6 +894,7 @@ partial void ProcessVideoMetadataResponseContent( return await VideoMetadataAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoSetThumbnail.g.cs b/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoSetThumbnail.g.cs index 54f3840..6d94905 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoSetThumbnail.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoSetThumbnail.g.cs @@ -14,6 +14,7 @@ public partial class VideoMetadataClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoSetThumbnailResponseContent( /// Update/Set the Video Thumbnail. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoSetThumbnailAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoSetThumbnailAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoSetThumbnailResponseContent( /// Update/Set the Video Thumbnail. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoSetThumbnailAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessVideoSetThumbnailResponseContent( securityRequirements: s_VideoSetThumbnailSecurityRequirements, operationName: "VideoSetThumbnailAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/metadata/thumbnail", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/metadata/thumbnail", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,588 +136,749 @@ partial void ProcessVideoSetThumbnailResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoSetThumbnailRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoSetThumbnailResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoSetThumbnailRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoSetThumbnail", + methodName: "VideoSetThumbnailAsync", + pathTemplate: "\"/video/metadata/thumbnail\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoSetThumbnail", + methodName: "VideoSetThumbnailAsync", + pathTemplate: "\"/video/metadata/thumbnail\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoSetThumbnail", + methodName: "VideoSetThumbnailAsync", + pathTemplate: "\"/video/metadata/thumbnail\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoSetThumbnailResponseContent( + response: __response); + ProcessVideoSetThumbnailResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoSetThumbnailResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoSetThumbnail", + methodName: "VideoSetThumbnailAsync", + pathTemplate: "\"/video/metadata/thumbnail\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoSetThumbnailResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoSetThumbnail", + methodName: "VideoSetThumbnailAsync", + pathTemplate: "\"/video/metadata/thumbnail\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoSetThumbnailResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoSetThumbnailResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoSetThumbnailResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Set Video Thumbnail
/// Update/Set the Video Thumbnail. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoSetThumbnailAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -699,6 +887,7 @@ partial void ProcessVideoSetThumbnailResponseContent( return await VideoSetThumbnailAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoSetThumbnailGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoSetThumbnailGetresult.g.cs index abdcdeb..7d42ce7 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoSetThumbnailGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.VideoSetThumbnailGetresult.g.cs @@ -14,6 +14,7 @@ public partial class VideoMetadataClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,14 +46,17 @@ partial void ProcessVideoSetThumbnailGetresultResponseContent( /// Use this method, along with transaction_id, to retrieve the updated video with the new thumbnail. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoSetThumbnailGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoSetThumbnailGetresultAsResponseAsync( transactionId: transactionId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,10 +67,12 @@ partial void ProcessVideoSetThumbnailGetresultResponseContent( /// Use this method, along with transaction_id, to retrieve the updated video with the new thumbnail. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoSetThumbnailGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -81,22 +87,43 @@ partial void ProcessVideoSetThumbnailGetresultResponseContent( securityRequirements: s_VideoSetThumbnailGetresultSecurityRequirements, operationName: "VideoSetThumbnailGetresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/video/metadata/thumbnail/{transactionId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/video/metadata/thumbnail/{transactionId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -106,574 +133,733 @@ partial void ProcessVideoSetThumbnailGetresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoSetThumbnailGetresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - transactionId: transactionId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoSetThumbnailGetresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoSetThumbnailGetresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + transactionId: transactionId); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoSetThumbnailGetresult", + methodName: "VideoSetThumbnailGetresultAsync", + pathTemplate: "$\"/video/metadata/thumbnail/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoSetThumbnailGetresult", + methodName: "VideoSetThumbnailGetresultAsync", + pathTemplate: "$\"/video/metadata/thumbnail/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoSetThumbnailGetresult", + methodName: "VideoSetThumbnailGetresultAsync", + pathTemplate: "$\"/video/metadata/thumbnail/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } + break; } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoSetThumbnailGetresultResponseContent( + response: __response); + ProcessVideoSetThumbnailGetresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoSetThumbnailGetresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoSetThumbnailGetresult", + methodName: "VideoSetThumbnailGetresultAsync", + pathTemplate: "$\"/video/metadata/thumbnail/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoSetThumbnailGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoSetThumbnailGetresult", + methodName: "VideoSetThumbnailGetresultAsync", + pathTemplate: "$\"/video/metadata/thumbnail/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoSetThumbnailGetresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoSetThumbnailGetresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoSetThumbnailGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.g.cs b/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.g.cs index 51566b7..fa342ba 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoMetadataClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class VideoMetadataClient : global::Picsart.IVideoMetadata #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public VideoMetadataClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the VideoMetadataClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public VideoMetadataClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.VideoRemoveBackgroundClient.VideoRemoveBackground.g.cs b/src/libs/Picsart/Generated/Picsart.VideoRemoveBackgroundClient.VideoRemoveBackground.g.cs index 75d1a5f..21acf6d 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoRemoveBackgroundClient.VideoRemoveBackground.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoRemoveBackgroundClient.VideoRemoveBackground.g.cs @@ -14,6 +14,7 @@ public partial class VideoRemoveBackgroundClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoRemoveBackgroundResponseContent( /// Remove Background from videos, or replace with custom backdrops. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoRemoveBackgroundAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoRemoveBackgroundAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoRemoveBackgroundResponseContent( /// Remove Background from videos, or replace with custom backdrops. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoRemoveBackgroundAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessVideoRemoveBackgroundResponseContent( securityRequirements: s_VideoRemoveBackgroundSecurityRequirements, operationName: "VideoRemoveBackgroundAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/remove-background", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/remove-background", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,546 +136,707 @@ partial void ProcessVideoRemoveBackgroundResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoRemoveBackgroundRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoRemoveBackgroundResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoRemoveBackgroundRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoRemoveBackground", + methodName: "VideoRemoveBackgroundAsync", + pathTemplate: "\"/video/remove-background\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoRemoveBackground", + methodName: "VideoRemoveBackgroundAsync", + pathTemplate: "\"/video/remove-background\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoRemoveBackground", + methodName: "VideoRemoveBackgroundAsync", + pathTemplate: "\"/video/remove-background\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoRemoveBackgroundResponseContent( + response: __response); + ProcessVideoRemoveBackgroundResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoRemoveBackgroundResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoRemoveBackground", + methodName: "VideoRemoveBackgroundAsync", + pathTemplate: "\"/video/remove-background\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoRemoveBackgroundResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoRemoveBackground", + methodName: "VideoRemoveBackgroundAsync", + pathTemplate: "\"/video/remove-background\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoRemoveBackgroundResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoRemoveBackgroundResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoRemoveBackgroundResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Remove & Change Background from Videos
/// Remove Background from videos, or replace with custom backdrops. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoRemoveBackgroundAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -657,6 +845,7 @@ partial void ProcessVideoRemoveBackgroundResponseContent( return await VideoRemoveBackgroundAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoRemoveBackgroundClient.g.cs b/src/libs/Picsart/Generated/Picsart.VideoRemoveBackgroundClient.g.cs index 297093e..d11d37c 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoRemoveBackgroundClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoRemoveBackgroundClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class VideoRemoveBackgroundClient : global::Picsart.IVideo #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public VideoRemoveBackgroundClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the VideoRemoveBackgroundClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public VideoRemoveBackgroundClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.VideoTranscriptionsClient.VideoTranscribeAudio.g.cs b/src/libs/Picsart/Generated/Picsart.VideoTranscriptionsClient.VideoTranscribeAudio.g.cs index d2329b4..ddcbe6c 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoTranscriptionsClient.VideoTranscribeAudio.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoTranscriptionsClient.VideoTranscribeAudio.g.cs @@ -14,6 +14,7 @@ public partial class VideoTranscriptionsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -54,16 +55,19 @@ partial void ProcessVideoTranscribeAudioResponseContent( /// Note, that the maximum audio/video file size supported is 25mb. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoTranscribeAudioAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoTranscribeAudioAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -83,11 +87,13 @@ partial void ProcessVideoTranscribeAudioResponseContent( /// Note, that the maximum audio/video file size supported is 25mb. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoTranscribeAudioAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -102,22 +108,43 @@ partial void ProcessVideoTranscribeAudioResponseContent( securityRequirements: s_VideoTranscribeAudioSecurityRequirements, operationName: "VideoTranscribeAudioAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/audio/transcribe", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/audio/transcribe", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -127,580 +154,739 @@ partial void ProcessVideoTranscribeAudioResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoTranscribeAudioRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoTranscribeAudioResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoTranscribeAudioRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Too Many Requests - if ((int)__response.StatusCode == 429) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTranscribeAudio", + methodName: "VideoTranscribeAudioAsync", + pathTemplate: "\"/video/audio/transcribe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTranscribeAudio", + methodName: "VideoTranscribeAudioAsync", + pathTemplate: "\"/video/audio/transcribe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) - { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTranscribeAudio", + methodName: "VideoTranscribeAudioAsync", + pathTemplate: "\"/video/audio/transcribe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoTranscribeAudioResponseContent( + response: __response); + ProcessVideoTranscribeAudioResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoTranscribeAudioResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTranscribeAudio", + methodName: "VideoTranscribeAudioAsync", + pathTemplate: "\"/video/audio/transcribe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoTranscribeAudioResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTranscribeAudio", + methodName: "VideoTranscribeAudioAsync", + pathTemplate: "\"/video/audio/transcribe\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoTranscribeAudioResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoTranscribeAudioResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoTranscribeAudioResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Transcribe Audio
@@ -715,9 +901,11 @@ partial void ProcessVideoTranscribeAudioResponseContent( /// * video/webm
/// Note, that the maximum audio/video file size supported is 25mb. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoTranscribeAudioAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -726,6 +914,7 @@ partial void ProcessVideoTranscribeAudioResponseContent( return await VideoTranscribeAudioAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoTranscriptionsClient.VideoTranscribeAudioGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.VideoTranscriptionsClient.VideoTranscribeAudioGetresult.g.cs index 68086e8..37f05f8 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoTranscriptionsClient.VideoTranscribeAudioGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoTranscriptionsClient.VideoTranscribeAudioGetresult.g.cs @@ -14,6 +14,7 @@ public partial class VideoTranscriptionsClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,14 +46,17 @@ partial void ProcessVideoTranscribeAudioGetresultResponseContent( /// Use this method, along with transaction_id, to retrieve the audio transcription. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoTranscribeAudioGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoTranscribeAudioGetresultAsResponseAsync( transactionId: transactionId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,10 +67,12 @@ partial void ProcessVideoTranscribeAudioGetresultResponseContent( /// Use this method, along with transaction_id, to retrieve the audio transcription. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoTranscribeAudioGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -81,22 +87,43 @@ partial void ProcessVideoTranscribeAudioGetresultResponseContent( securityRequirements: s_VideoTranscribeAudioGetresultSecurityRequirements, operationName: "VideoTranscribeAudioGetresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/video/audio/transcribe/{transactionId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/video/audio/transcribe/{transactionId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -106,611 +133,770 @@ partial void ProcessVideoTranscribeAudioGetresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoTranscribeAudioGetresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - transactionId: transactionId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoTranscribeAudioGetresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.VideoError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.VideoError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.VideoError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoTranscribeAudioGetresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + transactionId: transactionId); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTranscribeAudioGetresult", + methodName: "VideoTranscribeAudioGetresultAsync", + pathTemplate: "$\"/video/audio/transcribe/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTranscribeAudioGetresult", + methodName: "VideoTranscribeAudioGetresultAsync", + pathTemplate: "$\"/video/audio/transcribe/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTranscribeAudioGetresult", + methodName: "VideoTranscribeAudioGetresultAsync", + pathTemplate: "$\"/video/audio/transcribe/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoTranscribeAudioGetresultResponseContent( + response: __response); + ProcessVideoTranscribeAudioGetresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTranscribeAudioGetresult", + methodName: "VideoTranscribeAudioGetresultAsync", + pathTemplate: "$\"/video/audio/transcribe/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoTranscribeAudioGetresult", + methodName: "VideoTranscribeAudioGetresultAsync", + pathTemplate: "$\"/video/audio/transcribe/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.VideoError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.VideoError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.VideoError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoTranscribeAudioGetresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoTranscribeAudioGetresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoTranscribeAudioGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoTranscribeAudioGetresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoTranscribeAudioGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoTranscriptionsClient.g.cs b/src/libs/Picsart/Generated/Picsart.VideoTranscriptionsClient.g.cs index e6f2db6..c4629bd 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoTranscriptionsClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoTranscriptionsClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class VideoTranscriptionsClient : global::Picsart.IVideoTr #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public VideoTranscriptionsClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the VideoTranscriptionsClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public VideoTranscriptionsClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoCreditsBalance.g.cs b/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoCreditsBalance.g.cs index c6eeba6..167f2e9 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoCreditsBalance.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoCreditsBalance.g.cs @@ -14,6 +14,7 @@ public partial class VideoUtilitiesClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -42,12 +43,15 @@ partial void ProcessVideoCreditsBalanceResponseContent( /// Credits Balance
/// Check your balance of credits. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoCreditsBalanceAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoCreditsBalanceAsResponseAsync( + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -57,9 +61,11 @@ partial void ProcessVideoCreditsBalanceResponseContent( /// Credits Balance
/// Check your balance of credits. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoCreditsBalanceAsResponseAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -73,22 +79,43 @@ partial void ProcessVideoCreditsBalanceResponseContent( securityRequirements: s_VideoCreditsBalanceSecurityRequirements, operationName: "VideoCreditsBalanceAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/balance", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/balance", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -98,610 +125,769 @@ partial void ProcessVideoCreditsBalanceResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoCreditsBalanceRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoCreditsBalanceResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.VideoError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.VideoError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.VideoError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoCreditsBalanceRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoCreditsBalance", + methodName: "VideoCreditsBalanceAsync", + pathTemplate: "\"/video/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoCreditsBalance", + methodName: "VideoCreditsBalanceAsync", + pathTemplate: "\"/video/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoCreditsBalance", + methodName: "VideoCreditsBalanceAsync", + pathTemplate: "\"/video/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoCreditsBalanceResponseContent( + response: __response); + ProcessVideoCreditsBalanceResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoCreditsBalance", + methodName: "VideoCreditsBalanceAsync", + pathTemplate: "\"/video/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoCreditsBalance", + methodName: "VideoCreditsBalanceAsync", + pathTemplate: "\"/video/balance\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.VideoError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.VideoError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.VideoError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoCreditsBalanceResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoCreditsBalanceResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoCreditsBalanceResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoCreditsBalanceResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoCreditsBalanceResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoGetaudioresult.g.cs b/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoGetaudioresult.g.cs index 13c1d98..10e4d6f 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoGetaudioresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoGetaudioresult.g.cs @@ -14,6 +14,7 @@ public partial class VideoUtilitiesClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,14 +46,17 @@ partial void ProcessVideoGetaudioresultResponseContent( /// Use the video editing transaction ID to get the result audio file URL. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoGetaudioresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoGetaudioresultAsResponseAsync( transactionId: transactionId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,10 +67,12 @@ partial void ProcessVideoGetaudioresultResponseContent( /// Use the video editing transaction ID to get the result audio file URL. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoGetaudioresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -81,22 +87,43 @@ partial void ProcessVideoGetaudioresultResponseContent( securityRequirements: s_VideoGetaudioresultSecurityRequirements, operationName: "VideoGetaudioresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/video/audio/{transactionId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/video/audio/{transactionId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -106,536 +133,695 @@ partial void ProcessVideoGetaudioresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoGetaudioresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - transactionId: transactionId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoGetaudioresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoGetaudioresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + transactionId: transactionId); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetaudioresult", + methodName: "VideoGetaudioresultAsync", + pathTemplate: "$\"/video/audio/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetaudioresult", + methodName: "VideoGetaudioresultAsync", + pathTemplate: "$\"/video/audio/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetaudioresult", + methodName: "VideoGetaudioresultAsync", + pathTemplate: "$\"/video/audio/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } + break; } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoGetaudioresultResponseContent( + response: __response); + ProcessVideoGetaudioresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoGetaudioresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetaudioresult", + methodName: "VideoGetaudioresultAsync", + pathTemplate: "$\"/video/audio/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoGetaudioresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetaudioresult", + methodName: "VideoGetaudioresultAsync", + pathTemplate: "$\"/video/audio/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoGetaudioresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoGetaudioresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoGetaudioresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoGetresult.g.cs index 678f012..10084dd 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoGetresult.g.cs @@ -14,6 +14,7 @@ public partial class VideoUtilitiesClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,14 +46,17 @@ partial void ProcessVideoGetresultResponseContent( /// Use the video editing transaction ID to get the result video URL. This method works for effects, adjust, trim, crop, resize, fit, concatenation, highlights services. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoGetresultAsResponseAsync( transactionId: transactionId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,10 +67,12 @@ partial void ProcessVideoGetresultResponseContent( /// Use the video editing transaction ID to get the result video URL. This method works for effects, adjust, trim, crop, resize, fit, concatenation, highlights services. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -81,22 +87,43 @@ partial void ProcessVideoGetresultResponseContent( securityRequirements: s_VideoGetresultSecurityRequirements, operationName: "VideoGetresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/video/video/{transactionId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/video/video/{transactionId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -106,536 +133,695 @@ partial void ProcessVideoGetresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoGetresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - transactionId: transactionId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoGetresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoGetresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + transactionId: transactionId); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetresult", + methodName: "VideoGetresultAsync", + pathTemplate: "$\"/video/video/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetresult", + methodName: "VideoGetresultAsync", + pathTemplate: "$\"/video/video/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetresult", + methodName: "VideoGetresultAsync", + pathTemplate: "$\"/video/video/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } + break; } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoGetresultResponseContent( + response: __response); + ProcessVideoGetresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoGetresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetresult", + methodName: "VideoGetresultAsync", + pathTemplate: "$\"/video/video/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoGetresult", + methodName: "VideoGetresultAsync", + pathTemplate: "$\"/video/video/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoGetresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoGetresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoUpload.g.cs b/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoUpload.g.cs index 143ffcd..f75ef62 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoUpload.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.VideoUpload.g.cs @@ -14,6 +14,7 @@ public partial class VideoUtilitiesClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoUploadResponseContent( /// Upload resources such as videos, audios or images. The provided URL can be passed as inputs to video operation. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoUploadAsync( global::Picsart.VideoUploadParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoUploadAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoUploadResponseContent( /// Upload resources such as videos, audios or images. The provided URL can be passed as inputs to video operation. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoUploadAsResponseAsync( global::Picsart.VideoUploadParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -86,22 +92,43 @@ partial void ProcessVideoUploadResponseContent( securityRequirements: s_VideoUploadSecurityRequirements, operationName: "VideoUploadAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/upload", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/upload", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -111,551 +138,710 @@ partial void ProcessVideoUploadResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - if (request.File != default) - { - - var __contentFile = new global::System.Net.Http.ByteArrayContent(request.File ?? global::System.Array.Empty()); - __httpRequestContent.Add( - content: __contentFile, - name: "\"file\"", - fileName: request.Filename != null ? $"\"{request.Filename}\"" : string.Empty); - if (__contentFile.Headers.ContentDisposition != null) - { - __contentFile.Headers.ContentDisposition.FileNameStar = null; - } - } - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoUploadRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoUploadResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (request.File != default) + { + + var __contentFile = new global::System.Net.Http.ByteArrayContent(request.File ?? global::System.Array.Empty()); + __httpRequestContent.Add( + content: __contentFile, + name: "\"file\"", + fileName: request.Filename != null ? $"\"{request.Filename}\"" : string.Empty); + if (__contentFile.Headers.ContentDisposition != null) + { + __contentFile.Headers.ContentDisposition.FileNameStar = null; + } + } + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoUploadRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpload", + methodName: "VideoUploadAsync", + pathTemplate: "\"/video/upload\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpload", + methodName: "VideoUploadAsync", + pathTemplate: "\"/video/upload\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpload", + methodName: "VideoUploadAsync", + pathTemplate: "\"/video/upload\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + if (__response == null) { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoUploadResponseContent( + response: __response); + ProcessVideoUploadResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoUploadResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpload", + methodName: "VideoUploadAsync", + pathTemplate: "\"/video/upload\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoUploadResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpload", + methodName: "VideoUploadAsync", + pathTemplate: "\"/video/upload\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoUploadResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoUploadResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoUploadResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Upload files
@@ -667,11 +853,13 @@ partial void ProcessVideoUploadResponseContent( /// /// Source file (binary). /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoUploadAsync( byte[]? file = default, string? filename = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.VideoUploadParameters @@ -682,6 +870,7 @@ partial void ProcessVideoUploadResponseContent( return await VideoUploadAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.g.cs b/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.g.cs index 838f3d8..cda2234 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoUtilitiesClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class VideoUtilitiesClient : global::Picsart.IVideoUtiliti #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public VideoUtilitiesClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the VideoUtilitiesClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public VideoUtilitiesClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.VideoVideoEnhancementClient.VideoUpscaleFps.g.cs b/src/libs/Picsart/Generated/Picsart.VideoVideoEnhancementClient.VideoUpscaleFps.g.cs index d48db9b..244eeca 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoVideoEnhancementClient.VideoUpscaleFps.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoVideoEnhancementClient.VideoUpscaleFps.g.cs @@ -14,6 +14,7 @@ public partial class VideoVideoEnhancementClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoUpscaleFpsResponseContent( /// Upscale your low FPS videos to 60FPS high-quality videos using Generative AI technology. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoUpscaleFpsAsync( global::Picsart.VideoVideoParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoUpscaleFpsAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoUpscaleFpsResponseContent( /// Upscale your low FPS videos to 60FPS high-quality videos using Generative AI technology. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoUpscaleFpsAsResponseAsync( global::Picsart.VideoVideoParameters request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -86,22 +92,43 @@ partial void ProcessVideoUpscaleFpsResponseContent( securityRequirements: s_VideoUpscaleFpsSecurityRequirements, operationName: "VideoUpscaleFpsAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/upscale/fps", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/upscale/fps", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -111,620 +138,779 @@ partial void ProcessVideoUpscaleFpsResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - if (request.VideoUrl != default) - { - - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.VideoUrl}"), - name: "\"video_url\""); - } - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoUpscaleFpsRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoUpscaleFpsResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unprocessable Entity - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - global::Picsart.VideoError? __value_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_422 = global::Picsart.VideoError.FromJson(__content_422, JsonSerializerContext); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_422 = global::Picsart.VideoError.FromJson(__content_422, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_422 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + if (request.VideoUrl != default) + { + + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.VideoUrl}"), + name: "\"video_url\""); + } + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoUpscaleFpsRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) - { - ResponseBody = __content_422, - ResponseObject = __value_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpscaleFps", + methodName: "VideoUpscaleFpsAsync", + pathTemplate: "\"/video/upscale/fps\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpscaleFps", + methodName: "VideoUpscaleFpsAsync", + pathTemplate: "\"/video/upscale/fps\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpscaleFps", + methodName: "VideoUpscaleFpsAsync", + pathTemplate: "\"/video/upscale/fps\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try + if (__response == null) { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoUpscaleFpsResponseContent( + response: __response); + ProcessVideoUpscaleFpsResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpscaleFps", + methodName: "VideoUpscaleFpsAsync", + pathTemplate: "\"/video/upscale/fps\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpscaleFps", + methodName: "VideoUpscaleFpsAsync", + pathTemplate: "\"/video/upscale/fps\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unprocessable Entity + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + global::Picsart.VideoError? __value_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_422 = global::Picsart.VideoError.FromJson(__content_422, JsonSerializerContext); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_422 = global::Picsart.VideoError.FromJson(__content_422, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseObject = __value_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoUpscaleFpsResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoUpscaleFpsResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoUpscaleFpsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoUpscaleFpsResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoUpscaleFpsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } /// @@ -734,10 +920,12 @@ partial void ProcessVideoUpscaleFpsResponseContent( /// /// Source video URL. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoUpscaleFpsAsync( string? videoUrl = default, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.VideoVideoParameters @@ -747,6 +935,7 @@ partial void ProcessVideoUpscaleFpsResponseContent( return await VideoUpscaleFpsAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoVideoEnhancementClient.VideoUpscaleFpsGetresult.g.cs b/src/libs/Picsart/Generated/Picsart.VideoVideoEnhancementClient.VideoUpscaleFpsGetresult.g.cs index ee31e4c..38e78d0 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoVideoEnhancementClient.VideoUpscaleFpsGetresult.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoVideoEnhancementClient.VideoUpscaleFpsGetresult.g.cs @@ -14,6 +14,7 @@ public partial class VideoVideoEnhancementClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,14 +46,17 @@ partial void ProcessVideoUpscaleFpsGetresultResponseContent( /// Use this method, along with transaction_id, to retrieve the upscaled video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoUpscaleFpsGetresultAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoUpscaleFpsGetresultAsResponseAsync( transactionId: transactionId, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -63,10 +67,12 @@ partial void ProcessVideoUpscaleFpsGetresultResponseContent( /// Use this method, along with transaction_id, to retrieve the upscaled video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoUpscaleFpsGetresultAsResponseAsync( string transactionId, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -81,22 +87,43 @@ partial void ProcessVideoUpscaleFpsGetresultResponseContent( securityRequirements: s_VideoUpscaleFpsGetresultSecurityRequirements, operationName: "VideoUpscaleFpsGetresultAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: $"/video/upscale/fps/{transactionId}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: $"/video/upscale/fps/{transactionId}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -106,574 +133,733 @@ partial void ProcessVideoUpscaleFpsGetresultResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoUpscaleFpsGetresultRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - transactionId: transactionId); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoUpscaleFpsGetresultResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoUpscaleFpsGetresultRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + transactionId: transactionId); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpscaleFpsGetresult", + methodName: "VideoUpscaleFpsGetresultAsync", + pathTemplate: "$\"/video/upscale/fps/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpscaleFpsGetresult", + methodName: "VideoUpscaleFpsGetresultAsync", + pathTemplate: "$\"/video/upscale/fps/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpscaleFpsGetresult", + methodName: "VideoUpscaleFpsGetresultAsync", + pathTemplate: "$\"/video/upscale/fps/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } + break; } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) + if (__response == null) { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoUpscaleFpsGetresultResponseContent( + response: __response); + ProcessVideoUpscaleFpsGetresultResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoUpscaleFpsGetresultResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpscaleFpsGetresult", + methodName: "VideoUpscaleFpsGetresultAsync", + pathTemplate: "$\"/video/upscale/fps/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoUpscaleFpsGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoUpscaleFpsGetresult", + methodName: "VideoUpscaleFpsGetresultAsync", + pathTemplate: "$\"/video/upscale/fps/{transactionId}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoUpscaleFpsGetresultResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoUpscaleFpsGetresultResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoUpscaleFpsGetresultResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Picsart/Generated/Picsart.VideoVideoEnhancementClient.g.cs b/src/libs/Picsart/Generated/Picsart.VideoVideoEnhancementClient.g.cs index 583e94e..851711d 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoVideoEnhancementClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoVideoEnhancementClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class VideoVideoEnhancementClient : global::Picsart.IVideo #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public VideoVideoEnhancementClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the VideoVideoEnhancementClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public VideoVideoEnhancementClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Picsart/Generated/Picsart.VideoWatermarkClient.VideoAddWatermark.g.cs b/src/libs/Picsart/Generated/Picsart.VideoWatermarkClient.VideoAddWatermark.g.cs index 9a0e805..86c9fed 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoWatermarkClient.VideoAddWatermark.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoWatermarkClient.VideoAddWatermark.g.cs @@ -14,6 +14,7 @@ public partial class VideoWatermarkClient { new global::Picsart.EndPointAuthorizationRequirement { Type = "ApiKey", + SchemeId = "ApikeyXPicsartApiKey", Location = "Header", Name = "X-Picsart-API-Key", FriendlyName = "ApiKeyInHeader", @@ -45,16 +46,19 @@ partial void ProcessVideoAddWatermarkResponseContent( /// Add watermark to your video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoAddWatermarkAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __response = await VideoAddWatermarkAsResponseAsync( request: request, + requestOptions: requestOptions, cancellationToken: cancellationToken ).ConfigureAwait(false); @@ -65,11 +69,13 @@ partial void ProcessVideoAddWatermarkResponseContent( /// Add watermark to your video. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task> VideoAddWatermarkAsResponseAsync( global::Picsart.AllOf request, + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,22 +90,43 @@ partial void ProcessVideoAddWatermarkResponseContent( securityRequirements: s_VideoAddWatermarkSecurityRequirements, operationName: "VideoAddWatermarkAsync"); - var __pathBuilder = new global::Picsart.PathBuilder( - path: "/video/watermark", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Picsart.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Picsart.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Picsart.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Picsart.PathBuilder( + path: "/video/watermark", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Picsart.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,584 +136,745 @@ partial void ProcessVideoAddWatermarkResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } - } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareVideoAddWatermarkRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessVideoAddWatermarkResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // Bad Request - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - global::Picsart.VideoError? __value_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseObject = __value_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Unauthorized - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - global::Picsart.Video401Error? __value_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseObject = __value_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Payment Required - if ((int)__response.StatusCode == 402) - { - string? __content_402 = null; - global::System.Exception? __exception_402 = null; - global::Picsart.VideoError? __value_402 = null; - try - { - if (ReadResponseAsString) - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - else - { - __content_402 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_402 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_402, - statusCode: __response.StatusCode) - { - ResponseBody = __content_402, - ResponseObject = __value_402, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Forbidden - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - global::Picsart.VideoError? __value_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseObject = __value_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Not Found - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - global::Picsart.VideoError? __value_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_404 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) - { - ResponseBody = __content_404, - ResponseObject = __value_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Method Not Allowed - if ((int)__response.StatusCode == 405) - { - string? __content_405 = null; - global::System.Exception? __exception_405 = null; - global::Picsart.VideoError? __value_405 = null; - try - { - if (ReadResponseAsString) - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - else - { - __content_405 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_405 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_405, - statusCode: __response.StatusCode) - { - ResponseBody = __content_405, - ResponseObject = __value_405, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Entity Too Large - if ((int)__response.StatusCode == 413) - { - string? __content_413 = null; - global::System.Exception? __exception_413 = null; - global::Picsart.VideoError? __value_413 = null; - try - { - if (ReadResponseAsString) - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - else - { - __content_413 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_413 = __ex; - } - - throw new global::Picsart.ApiException( - message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_413, - statusCode: __response.StatusCode) - { - ResponseBody = __content_413, - ResponseObject = __value_413, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + } } - // Unsupported Media Type - if ((int)__response.StatusCode == 415) - { - string? __content_415 = null; - global::System.Exception? __exception_415 = null; - global::Picsart.VideoError? __value_415 = null; - try - { - if (ReadResponseAsString) - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - else - { - __content_415 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_415 = __ex; - } + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequest.Content = __httpRequestContent; + global::Picsart.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); + + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareVideoAddWatermarkRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Picsart.ApiException( - message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_415, - statusCode: __response.StatusCode) - { - ResponseBody = __content_415, - ResponseObject = __value_415, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // Too Many Requests - if ((int)__response.StatusCode == 429) - { - string? __content_429 = null; - global::System.Exception? __exception_429 = null; - global::Picsart.VideoError? __value_429 = null; - try - { - if (ReadResponseAsString) - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - else - { - __content_429 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_429 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_429, - statusCode: __response.StatusCode) - { - ResponseBody = __content_429, - ResponseObject = __value_429, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Request Header Fields Too Large - if ((int)__response.StatusCode == 431) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_431 = null; - global::System.Exception? __exception_431 = null; - global::Picsart.VideoError? __value_431 = null; - try - { - if (ReadResponseAsString) + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) + { + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Picsart.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAddWatermark", + methodName: "VideoAddWatermarkAsync", + pathTemplate: "\"/video/watermark\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_431 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAddWatermark", + methodName: "VideoAddWatermarkAsync", + pathTemplate: "\"/video/watermark\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } + + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_431 = __ex; - } - throw new global::Picsart.ApiException( - message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_431, - statusCode: __response.StatusCode) - { - ResponseBody = __content_431, - ResponseObject = __value_431, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Internal Server Error - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - global::Picsart.VideoError? __value_500 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Picsart.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAddWatermark", + methodName: "VideoAddWatermarkAsync", + pathTemplate: "\"/video/watermark\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Picsart.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_500 = __ex; + break; } - throw new global::Picsart.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + if (__response == null) { - ResponseBody = __content_500, - ResponseObject = __value_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // Service Unavailable - if ((int)__response.StatusCode == 503) - { - string? __content_503 = null; - global::System.Exception? __exception_503 = null; - global::Picsart.VideoError? __value_503 = null; - try - { - if (ReadResponseAsString) - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - else - { - __content_503 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - - __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); - } - } - catch (global::System.Exception __ex) - { - __exception_503 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Picsart.ApiException( - message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_503, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_503, - ResponseObject = __value_503, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessVideoAddWatermarkResponseContent( + response: __response); + ProcessVideoAddWatermarkResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try - { - __response.EnsureSuccessStatusCode(); - - var __value = global::Picsart.VideoAddWatermarkResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAddWatermark", + methodName: "VideoAddWatermarkAsync", + pathTemplate: "\"/video/watermark\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - - var __value = await global::Picsart.VideoAddWatermarkResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - return new global::Picsart.AutoSDKHttpResponse( - statusCode: __response.StatusCode, - headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), - body: __value); + else + { + await global::Picsart.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Picsart.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "VideoAddWatermark", + methodName: "VideoAddWatermarkAsync", + pathTemplate: "\"/video/watermark\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + // Bad Request + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + global::Picsart.VideoError? __value_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_400 = global::Picsart.VideoError.FromJson(__content_400, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseObject = __value_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unauthorized + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + global::Picsart.Video401Error? __value_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_401 = global::Picsart.Video401Error.FromJson(__content_401, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseObject = __value_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Payment Required + if ((int)__response.StatusCode == 402) + { + string? __content_402 = null; + global::System.Exception? __exception_402 = null; + global::Picsart.VideoError? __value_402 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + else + { + __content_402 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_402 = global::Picsart.VideoError.FromJson(__content_402, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_402 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_402 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_402, + statusCode: __response.StatusCode) + { + ResponseBody = __content_402, + ResponseObject = __value_402, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Forbidden + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + global::Picsart.VideoError? __value_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_403 = global::Picsart.VideoError.FromJson(__content_403, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseObject = __value_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Not Found + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + global::Picsart.VideoError? __value_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_404 = global::Picsart.VideoError.FromJson(__content_404, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseObject = __value_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Method Not Allowed + if ((int)__response.StatusCode == 405) + { + string? __content_405 = null; + global::System.Exception? __exception_405 = null; + global::Picsart.VideoError? __value_405 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + else + { + __content_405 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_405 = global::Picsart.VideoError.FromJson(__content_405, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_405 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_405 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_405, + statusCode: __response.StatusCode) + { + ResponseBody = __content_405, + ResponseObject = __value_405, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Entity Too Large + if ((int)__response.StatusCode == 413) + { + string? __content_413 = null; + global::System.Exception? __exception_413 = null; + global::Picsart.VideoError? __value_413 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + else + { + __content_413 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_413 = global::Picsart.VideoError.FromJson(__content_413, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_413 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_413 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_413, + statusCode: __response.StatusCode) + { + ResponseBody = __content_413, + ResponseObject = __value_413, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Unsupported Media Type + if ((int)__response.StatusCode == 415) + { + string? __content_415 = null; + global::System.Exception? __exception_415 = null; + global::Picsart.VideoError? __value_415 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + else + { + __content_415 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_415 = global::Picsart.VideoError.FromJson(__content_415, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_415 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_415 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_415, + statusCode: __response.StatusCode) + { + ResponseBody = __content_415, + ResponseObject = __value_415, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Too Many Requests + if ((int)__response.StatusCode == 429) + { + string? __content_429 = null; + global::System.Exception? __exception_429 = null; + global::Picsart.VideoError? __value_429 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + else + { + __content_429 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_429 = global::Picsart.VideoError.FromJson(__content_429, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_429 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_429 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_429, + statusCode: __response.StatusCode) + { + ResponseBody = __content_429, + ResponseObject = __value_429, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Request Header Fields Too Large + if ((int)__response.StatusCode == 431) + { + string? __content_431 = null; + global::System.Exception? __exception_431 = null; + global::Picsart.VideoError? __value_431 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + else + { + __content_431 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_431 = global::Picsart.VideoError.FromJson(__content_431, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_431 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_431 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_431, + statusCode: __response.StatusCode) + { + ResponseBody = __content_431, + ResponseObject = __value_431, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Internal Server Error + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + global::Picsart.VideoError? __value_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_500 = global::Picsart.VideoError.FromJson(__content_500, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseObject = __value_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // Service Unavailable + if ((int)__response.StatusCode == 503) + { + string? __content_503 = null; + global::System.Exception? __exception_503 = null; + global::Picsart.VideoError? __value_503 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + else + { + __content_503 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + + __value_503 = global::Picsart.VideoError.FromJson(__content_503, JsonSerializerContext); + } + } + catch (global::System.Exception __ex) + { + __exception_503 = __ex; + } + + throw new global::Picsart.ApiException( + message: __content_503 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_503, + statusCode: __response.StatusCode) + { + ResponseBody = __content_503, + ResponseObject = __value_503, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessVideoAddWatermarkResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + var __value = global::Picsart.VideoAddWatermarkResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + var __value = await global::Picsart.VideoAddWatermarkResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + return new global::Picsart.AutoSDKHttpResponse( + statusCode: __response.StatusCode, + headers: global::Picsart.AutoSDKHttpResponse.CreateHeaders(__response), + body: __value); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Picsart.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Picsart.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Add Watermark
/// Add watermark to your video. ///
+ /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task VideoAddWatermarkAsync( + global::Picsart.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Picsart.AllOf @@ -695,6 +883,7 @@ partial void ProcessVideoAddWatermarkResponseContent( return await VideoAddWatermarkAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Picsart/Generated/Picsart.VideoWatermarkClient.g.cs b/src/libs/Picsart/Generated/Picsart.VideoWatermarkClient.g.cs index f170fb2..5331c02 100644 --- a/src/libs/Picsart/Generated/Picsart.VideoWatermarkClient.g.cs +++ b/src/libs/Picsart/Generated/Picsart.VideoWatermarkClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class VideoWatermarkClient : global::Picsart.IVideoWaterma #if DEBUG = true; #endif + + /// + public global::Picsart.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public VideoWatermarkClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the VideoWatermarkClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public VideoWatermarkClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Picsart.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Picsart.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient);