private T DownloadData <T> (string url) where T : BasicModel { int triesLeft = RetryTimes + 1; Error lastError; Tuple <ResponseInfo, T> response = null; do { if (response != null) { Thread.Sleep(RetryAfter); } response = DownloadDataAlt <T> (url); response.Item2.AddResponseInfo(response.Item1); lastError = response.Item2.Error; triesLeft -= 1; } while (UseAutoRetry && triesLeft > 0 && lastError != null && RetryErrorCodes.Contains(lastError.Status)); return(response.Item2); }
public async Task <T> DownloadDataAsync <T>(string url) where T : BasicModel { int triesLeft = RetryTimes + 1; Error lastError; Tuple <ResponseInfo, T> response = null; do { if (response != null) { int msToWait = RetryAfter; int secondsToWait = GetTooManyRequests(response.Item1); if (secondsToWait > 0) { msToWait = secondsToWait * 1000; } await Task.Delay(msToWait).ConfigureAwait(false); } response = await DownloadDataAltAsync <T>(url).ConfigureAwait(false); response.Item2.AddResponseInfo(response.Item1); lastError = response.Item2.Error; if (TooManyRequestsConsumesARetry || GetTooManyRequests(response.Item1) == -1) { triesLeft -= 1; } } while (UseAutoRetry && triesLeft > 0 && (GetTooManyRequests(response.Item1) != -1 || lastError != null && RetryErrorCodes.Contains(lastError.Status))); return(response.Item2); }