aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Reed <ebr@mediabrowser3.com>2013-03-14 11:19:13 -0400
committerEric Reed <ebr@mediabrowser3.com>2013-03-14 11:19:13 -0400
commitce014b1f14b3d20fb30b2c6784f4c04eb422a99b (patch)
tree042a5b0d986c8cd035c685a5ed07362687213603
parent178859e0bdc450f7d91e0ce0123971c96bbd69c5 (diff)
Implement retries on package download in installer
-rw-r--r--MediaBrowser.Installer/MainWindow.xaml.cs41
1 files changed, 29 insertions, 12 deletions
diff --git a/MediaBrowser.Installer/MainWindow.xaml.cs b/MediaBrowser.Installer/MainWindow.xaml.cs
index 0cf8c2425..815ad4781 100644
--- a/MediaBrowser.Installer/MainWindow.xaml.cs
+++ b/MediaBrowser.Installer/MainWindow.xaml.cs
@@ -4,6 +4,7 @@ using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Net;
+using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Linq;
@@ -336,23 +337,39 @@ namespace MediaBrowser.Installer
/// <returns>The fully qualified name of the downloaded package</returns>
protected async Task<string> DownloadPackage(PackageVersionInfo version)
{
+ var success = false;
+ var retryCount = 0;
+ var archiveFile = Path.Combine(PrepareTempLocation(), version.targetFilename);
+
try
{
- var archiveFile = Path.Combine(PrepareTempLocation(), version.targetFilename);
-
- // setup download progress and download the package
- MainClient.DownloadProgressChanged += DownloadProgressChanged;
- try
- {
- await MainClient.DownloadFileTaskAsync(version.sourceUrl, archiveFile);
- }
- catch (WebException e)
+ while (!success && retryCount < 3)
{
- if (e.Status == WebExceptionStatus.RequestCanceled)
+
+ // setup download progress and download the package
+ MainClient.DownloadProgressChanged += DownloadProgressChanged;
+ try
+ {
+ await MainClient.DownloadFileTaskAsync(version.sourceUrl, archiveFile);
+ success = true;
+ }
+ catch (WebException e)
{
- return null;
+ if (e.Status == WebExceptionStatus.RequestCanceled)
+ {
+ return null;
+ }
+ if (e.Status == WebExceptionStatus.Timeout || e.Status == WebExceptionStatus.ConnectFailure || e.Status == WebExceptionStatus.ProtocolError)
+ {
+ Thread.Sleep(500); //wait just a sec
+ PrepareTempLocation(); //clear this out
+ retryCount++;
+ }
+ else
+ {
+ throw;
+ }
}
- throw;
}
return archiveFile;