/// <summary> /// Implementation of the *RequestWithRetry methods. /// </summary> /// <typeparam name="TResult">The result type of the task.</typeparam> /// <param name="retryOracle">The retry oracle.</param> /// <param name="syncTask">The task implementation.</param> /// <returns>A <see cref="TaskSequence"/> that performs the request with retries.</returns> internal static TResult RequestWithRetrySyncImpl <TResult>(ShouldRetry retryOracle, SynchronousTask <TResult> syncTask) { int retryCount = 0; bool shouldRetry = false; do { TimeSpan delay = TimeSpan.FromMilliseconds(-1); try { return(syncTask.Execute()); } catch (TimeoutException e) { shouldRetry = retryOracle != null?retryOracle(retryCount ++, e, out delay) : false; // We should just throw out the exception if we are not retrying if (!shouldRetry) { throw; } } catch (StorageServerException e) { if (e.StatusCode == HttpStatusCode.NotImplemented || e.StatusCode == HttpStatusCode.HttpVersionNotSupported) { throw; } shouldRetry = retryOracle != null?retryOracle(retryCount ++, e, out delay) : false; // We should just throw out the exception if we are not retrying if (!shouldRetry) { throw; } } catch (InvalidOperationException e) {/* * DataServiceClientException dsce = CommonUtils.FindInnerDataServiceClientException(e); * * // rethrow 400 class errors immediately as they can't be retried * // 501 (Not Implemented) and 505 (HTTP Version Not Supported) shouldn't be retried either. * if (dsce != null && * ((dsce.StatusCode >= 400 && dsce.StatusCode < 500) || dsce.StatusCode == (int)HttpStatusCode.NotImplemented || dsce.StatusCode == (int)HttpStatusCode.HttpVersionNotSupported)) ||{ || throw; ||} */ // If it is BlobTypeMismatchExceptionMessage, we should throw without retry if (e.Message == SR.BlobTypeMismatchExceptionMessage) { throw; } shouldRetry = retryOracle != null?retryOracle(retryCount ++, e, out delay) : false; // We should just throw out the exception if we are not retrying if (!shouldRetry) { throw; } } if (shouldRetry && delay > TimeSpan.Zero) { Thread.Sleep(delay); } }while (shouldRetry); throw new StorageClientException( StorageErrorCode.None, "Unexpected internal storage client error.", System.Net.HttpStatusCode.Unused, null, null) { HelpLink = "http://go.microsoft.com/fwlink/?LinkID=182765" }; }
internal static TResult ExecuteSyncTask <TResult>(SynchronousTask <TResult> syncTask) { CommonUtils.AssertNotNull("syncTask", syncTask); return(syncTask.Execute()); }