public FileDownloader(IFileDownloaderActions actions, AvailableFile file, int refreshProgresIntervalInMiliseconds) { _actions = actions; _file = file; _refreshProgresIntervalInMiliseconds = refreshProgresIntervalInMiliseconds; _webClient = new WebClient(); }
public void DownloadErrorHappened(AvailableFile file) { if (_downloaders.ContainsKey(file)) { _downloaders.TryRemove(file, out FileDownloader downloader); } _downloaderView.RefreshAvailableFiles(); }
private void AddDownloadedFile(AvailableFile file, byte[] data) { var downloadedFile = _downloadFileManager.CreateFile(file.Uri.Segments.Last(), _fileStoragePath, data); lock (_downloadedFiles) { _downloadedFiles.Enqueue(downloadedFile); } }
public void StopDownload(AvailableFile file) { if (_downloaders.ContainsKey(file)) { _downloaders[file].Stop(); } else if (file.Status == FileStatusEnum.ForDownload) { file.Status = FileStatusEnum.DownloadStopped; } }
private void StartDownloadIfAvailable(AvailableFile file) { file.Modified = DateTime.Now; file.Status = FileStatusEnum.ForDownload; if (_appSettings.NumberOfDownloaders > _downloaders.Count) { if (!_downloaders.ContainsKey(file)) { var fd = new FileDownloader(this, file, _appSettings.RefreshProgresIntervalInMiliseconds); _downloaders.TryAdd(file, fd); fd.Start(); } } }
public void DownloadCompleted(AvailableFile file, byte[] data) { _downloaders.TryRemove(file, out FileDownloader downloader); AddDownloadedFile(file, data); while (_appSettings.NumberOfDownloaders > _downloaders.Count && _availableFiles.Any(f => f.Status == FileStatusEnum.ForDownload)) { var nextFile = _availableFiles.OrderBy(f => f.Modified).FirstOrDefault(f => f.Status == FileStatusEnum.ForDownload); StartDownloadIfAvailable(nextFile); } if (_downloaders.Count == 0) { DeleteOldFiles(); } _downloaderView.RefreshAvailableFiles(); _downloaderView.SetDownloadedFiles(_downloadedFiles); }
public void StartDownload(AvailableFile file) { StartDownloadIfAvailable(file); _downloaderView.RefreshAvailableFiles(); }