예제 #1
0
            public async Task <Stream> DownloadAsync()
            {
                var client = _helper.GetNewHttpClient();
                HttpResponseMessage response = await client.GetAsync(DownloadUri, HttpCompletionOption.ResponseHeadersRead);

                response.EnsureSuccessStatusCode();

                return(await response.Content.ReadAsStreamAsync());;
            }
            /// <summary>
            /// Downloads a stream from the GitHub provider with an optional retry logic
            /// </summary>
            /// <param name="retryCount">The number of retries</param>
            /// <param name="delay">The delay between retries, with exponential back-off</param>
            /// <returns>The resulting Stream</returns>
            public async Task <Stream> DownloadAsync(int retryCount = 10, int delay = 500)
            {
                var client = _helper.GetNewHttpClient();

                for (Int32 c = 0; c < retryCount; c++)
                {
                    HttpResponseMessage response = await client.GetAsync(DownloadUri, HttpCompletionOption.ResponseHeadersRead);

                    if (response.IsSuccessStatusCode)
                    {
                        return(await response.Content.ReadAsStreamAsync());;
                    }

                    // Exponential back-off
                    await Task.Delay(delay *retryCount);
                }

                return(null);
            }