protected override void AddDownloadToList(string url, string destination, string username, string password) { Credentials = new NetworkCredential(username, password); try { foreach (Download download in GetFTPDownloadTree(new List <Download>(), Credentials, destination, url, url)) { try {//this inner try catch will prevent the rest of the downloads to not be added in case this one fails string newDestination = download.Destination.FullPath; download.Destination.FullPath = destination; DownloadsController.AddDownloadToList(download); download.Destination.FullPath = newDestination; } catch (Exception ex) { OnProcessError(new DownloadErrorEventArgs(ex)); } } } catch (Exception ex) { if (ex.Message.Contains("logged in")) { throw new DownloaderUCException(ErrorType.NotLoggedIn); } else { DownloaderUCException.Throw(ex); } } }
public void ValidationUnitTests() { downloadController = new DownloadsController(); Assert.DoesNotThrow( delegate { Assert.AreEqual(downloadController.CurrentDownload, null); }); try {//invalid fields download1 = new Download(new Destination("edwe"), new RemoteFileInfo("werfwerf", "asdasd", 234)); downloadController.AddDownloadToList(download1); } catch (DownloaderUCException e) { Assert.AreEqual(e.Error, ErrorType.InvalidField); } //insufficient space exception //CheckSpaceToAddDownload try { download1 = new Download(destination, new RemoteFileInfo("https://www.google.com", "anyname.exe" , long.MaxValue)); downloadController.AddDownloadToList(download1); } catch (DownloaderUCException e) { Assert.AreEqual(e.Error, ErrorType.InsufficientDiskSpaceFor); } }
public void LoadDataFromWeb() { this.IsLoading = true; var downloadsController = new DownloadsController(); App.InstapaperAPI.GetUnreadBookmarks(null, true, bookmarks => { var trimmedBookmarks = bookmarks.Take(25); UpdateBookmarksWithData(trimmedBookmarks); downloadsController.AddBookmarks(trimmedBookmarks); App.InstapaperAPI.GetStarredBookmarks(true, (starredBookmarks => { var trimmedStarredBookmarks = starredBookmarks.Take(10); UpdateBookmarksWithData(trimmedStarredBookmarks); downloadsController.AddBookmarks(trimmedStarredBookmarks); App.InstapaperAPI.GetArchiveBookmarks(true, (archivedBookmarks => { var trimmedArchivedBookmarks = archivedBookmarks.Take(5); UpdateBookmarksWithData(trimmedArchivedBookmarks); downloadsController.AddBookmarks(trimmedArchivedBookmarks); downloadsController.ProcessQueue(); })); })); }); this.IsLoading = false; }
protected override void AddDownloadToList(string url, string destination, string username, string password) { string fileName; long size; GetHttpHeaderInfo(url, out fileName, out size); DownloadsController.AddDownloadToList(new Download(new Destination(destination), new RemoteFileInfo(url, fileName, size))); }
private void CustomWebClientDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { //File level progress has changed. The download is fed with BytesReceived, //so that it can calculate some status data internally and send to the view DownloadsController.CurrentDownload.BytesReceived = e.BytesReceived; OnProgressChanged(new DownloaderEventArgs( DownloadsController.CurrentDownload.GetRemainingTimeString(speed.Speed), DownloadsController.GetRemainingTimeString(speed.Speed), speed.SpeedInUnit, DownloadsController.CurrentDownload.PercentCompleted(), DownloadsController.PercentCompleted())); }
/// <summary> /// Calculates the time remaining + report changes, updating the progress bar /// </summary> /// <param name="bufferLength">the amount of data per block (buffer)</param> /// <param name="progress">download progress</param> /// <param name="DownloadStart">was updated last report to .Now</param> private void CalculateAndReportProgress(double timeDifferenceMilliseconds, int bufferLength, long progress) { long speed = timeDifferenceMilliseconds > 0 ? (long)Math.Round(bufferLength / timeDifferenceMilliseconds) * 16000 : 0; //the line below is always needed for those equations DownloadsController.CurrentDownload.BytesReceived = progress; backgroundWorker.ReportProgress(0, new DownloaderEventArgs( DownloadsController.CurrentDownload.GetRemainingTimeString(speed), DownloadsController.GetRemainingTimeString(speed), speed > 0 ? Functions.ConvertSizeToUnit(speed) : "", DownloadsController.CurrentDownload.PercentCompleted(), DownloadsController.PercentCompleted())); }
private void UpdateBookmarkCacheStatus() { var bookmarks = App.DbDataContext.Bookmarks.ToList(); var downloadsController = new DownloadsController(); foreach (var bookmark in bookmarks) { if (!BookmarksStorageManager.DoesBookmarkBodyExist(bookmark.BookmarkId) && bookmark.IsDownloaded) { bookmark.IsDownloaded = false; bookmark.ShortBodyText = "Downloading..."; downloadsController.AddBookmark(bookmark); } } App.DbDataContext.SubmitChanges(); downloadsController.ProcessQueue(); }
public DownloadsControllerTests() { _appRepositoryMock = new Mock <IAppRepository>(); _appController = new DownloadsController(_appRepositoryMock.Object); }
public void DownloadsControllerUnitTests() { //DATA testing downloadController = new DownloadsController(); //testing the remaining bytes. will add 3 downloads, and set one to started and receive 10 bytes on it. download1 = new Download(destination, new RemoteFileInfo("https://www.google.com", "anyname.exe", 50)); download2 = new Download(destination, new RemoteFileInfo("https://www.google.com", "anyname.exe", 500)); download3 = new Download(destination, new RemoteFileInfo("https://www.google.com", "anyname.exe", 100)); downloadController.AddDownloadToList(download1); downloadController.AddDownloadToList(download2); downloadController.AddDownloadToList(download3); Assert.AreEqual(downloadController.DownloadsCollection.Count, 3); download2.BytesReceived = 10; download2.ChangeState(DownloadState.Started); Assert.AreEqual(downloadController.TotalSizeBytesRemainingToDownload(), 640); downloadController = new DownloadsController(); //testing TotalSizeBytes download1 = new Download(destination, new RemoteFileInfo("https://www.google.com", "anyname.exe", 100)); download2 = new Download(destination, new RemoteFileInfo("https://www.google.com", "anyname.exe", 2000)); download3 = new Download(destination, new RemoteFileInfo("https://www.google.com", "anyname.exe", 1500)); download4 = new Download(destination, new RemoteFileInfo("https://www.google.com", "anyname.exe", 5000)); downloadController.AddDownloadToList(download1); downloadController.AddDownloadToList(download2); downloadController.AddDownloadToList(download3); downloadController.AddDownloadToList(download4); Assert.AreEqual(downloadController.TotalSizeBytes(), 8600); download1.ChangeState(DownloadState.Closed); download2.ChangeState(DownloadState.Deleted); download3.BytesReceived = 1500; download3.ChangeState(DownloadState.Completed); download4.ChangeState(DownloadState.Started); download4.BytesReceived = 300; Assert.AreEqual(downloadController.TotalSizeBytes(), 6500); //testing percent completed downloadController = new DownloadsController(); download1 = new Download(destination, new RemoteFileInfo("https://www.google.com", "anyname.exe", 200)); download2 = new Download(destination, new RemoteFileInfo("https://www.google.com", "anyname.exe", 200)); download3 = new Download(destination, new RemoteFileInfo("https://www.google.com", "anyname.exe", 200)); download4 = new Download(destination, new RemoteFileInfo("https://www.google.com", "anyname.exe", 200)); download5 = new Download(destination, new RemoteFileInfo("https://www.google.com", "anyname.exe", 200)); downloadController.AddDownloadToList(download1); //will be completed downloadController.AddDownloadToList(download2); //will be have progress, but then canceled downloadController.AddDownloadToList(download3); //will be deleted downloadController.AddDownloadToList(download4); //suffer an error downloadController.AddDownloadToList(download5); // half way to go download1.ChangeState(DownloadState.Completed); download2.ChangeState(DownloadState.Started); download2.BytesReceived = 100; download2.ChangeState(DownloadState.Canceled); download3.ChangeState(DownloadState.Deleted); download4.ChangeState(DownloadState.Error, false); download5.BytesReceived = 100; Assert.AreEqual(downloadController.PercentCompleted(), 50); Assert.AreNotEqual(downloadController.GetRemainingTimeString(10), ""); Assert.AreEqual(downloadController.GetRemainingTimeString(201), ""); Assert.Throws(typeof(ArgumentOutOfRangeException), delegate { downloadController.CancelDownloads(new List <int>() { 6, 7, 8 }); }); downloadController.CancelDownloads(new List <int>() { 0, 1, 2, 3, 4 }); var deleted = downloadController.DownloadsCollection.Where(o => o.DownloadState == DownloadState.Deleted).Count(); Assert.AreEqual(deleted, 2); downloadController.ClearDownloads(); var closedCount = downloadController.DownloadsCollection.Where(o => o.DownloadState == DownloadState.Closed).Count(); Assert.AreEqual(closedCount, 1); }