/// <summary>Waits until the business process is completed or the timeout is reached.</summary> /// <param name="processId">The process ID.</param> /// <param name="timeout">The timeout wait for completion.</param> /// <returns>The wait result.</returns> /// <exception cref="ApiException">A server side error occurred.</exception> /// <exception cref="PictureparkException">Internal server error</exception> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> public async Task <BusinessProcessWaitResult> WaitForCompletionAsync(string processId, TimeSpan?timeout = null, CancellationToken cancellationToken = default(CancellationToken)) { return(await _httpClient.Poll(timeout, cancellationToken, async() => { var waitResult = await WaitForCompletionCoreAsync(processId, timeout, cancellationToken).ConfigureAwait(false); if (waitResult.HasLifeCycleHit && waitResult.BusinessProcess.LifeCycle == BusinessProcessLifeCycle.Succeeded) { return waitResult; } var errors = waitResult.BusinessProcess.StateHistory? .Where(i => i.Error != null) .Select(i => i.Error) .ToList(); if (errors != null && errors.Any()) { if (errors.Count == 1) { throw PictureparkException.FromJson(errors.First().Exception); } var exceptions = errors.Select(error => PictureparkException.FromJson(error.Exception)); throw new AggregateException(exceptions); } throw new TimeoutException($"Wait for business process on completion timed out after {timeout?.TotalSeconds} seconds"); })); }
/// <summary>Waits until the business process transitioned into one of the given states or the timeout is reached.</summary> /// <param name="processId">The process ID.</param> /// <param name="states">The states to wait for.</param> /// <param name="timeout">The timeout in ms to wait for completion.</param> /// <returns>The wait result.</returns> /// <exception cref="ApiException">A server side error occurred.</exception> /// <exception cref="PictureparkException">Internal server error</exception> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> public async Task <BusinessProcessWaitResult> WaitForStatesAsync(string processId, IEnumerable <string> states, TimeSpan?timeout = null, CancellationToken cancellationToken = default(CancellationToken)) { return(await _httpClient.Poll(timeout, cancellationToken, async() => { var waitResult = await WaitCoreAsync(processId, states, null, timeout, cancellationToken).ConfigureAwait(false); var errors = waitResult.BusinessProcess.StateHistory? .Where(i => i.Error != null) .Select(i => i.Error) .ToList(); if (errors != null && errors.Any()) { if (errors.Count == 1) { throw PictureparkException.FromJson(errors.First().Exception); } var exceptions = errors.Select(error => PictureparkException.FromJson(error.Exception)); throw new AggregateException(exceptions); } return waitResult; })); }
/// <summary>Gets the localized error message for the given exception.</summary> /// <param name="exception">The exception.</param> /// <param name="language">The language.</param> /// <returns>The localized error message.</returns> public static string GetLocalizedErrorCode(PictureparkException exception, string language) { var errorAsString = exception.GetType().Name; return(GetLocalizedText(errorAsString, language, Hash.FromAnonymousObject(exception))); }
/// <summary>Gets the localized error message for the given exception.</summary> /// <param name="exception">The exception.</param> /// <param name="language">The language.</param> /// <returns>The localized error message.</returns> public static string GetLocalizedErrorCode(this PictureparkException exception, string language) { return(LocalizationService.GetLocalizedErrorCode(exception, language)); }