private IEnumerable <RestResponse> Raw(Task <HttpResponseMessage> func, RestSettings restSettings) { Contract.EnsureWebhookIsNotBroken(_webhook.Status); var currentAttempts = 0U; // Used to prevent calls if something went wrong var forceStop = false; var lastResponse = default(RestResponse); do { if (lastResponse.IsValid()) { _webhook.ActionManager.FollowRateLimit(lastResponse.RateLimit).ConfigureAwait(false).GetAwaiter().GetResult(); } using var response = func.ConfigureAwait(false).GetAwaiter().GetResult(); var rateLimitInfo = RateLimitInfo.Get(response.Headers); using var responseStream = response.Content.ReadAsStreamAsync().ConfigureAwait(false).GetAwaiter().GetResult(); lastResponse = new RestResponse(response.StatusCode, rateLimitInfo, responseStream, currentAttempts); // Processing the necessary status codes ProcessStatusCode(response.StatusCode, ref forceStop); yield return(lastResponse); } while (!forceStop && !lastResponse.IsSuccessful && (restSettings.Attempts == 0 || ++currentAttempts <= restSettings.Attempts)); }
public RestResponse(HttpStatusCode statusCode, RateLimitInfo rateLimit, Stream stream, uint attempts) { StatusCode = statusCode; RateLimit = rateLimit; Attempts = attempts; Data = stream.ReadAsByteArray(); }