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