public TorrentRunner(ISettings settings, ITorrents torrents, IDownloads downloads, IRemoteService remoteService) { _settings = settings; _torrents = torrents; _downloads = downloads; _remoteService = remoteService; }
private async Task ProcessStatus(IDownloads downloads, ISettings settings, ITorrents torrents) { foreach (var(downloadId, download) in ActiveDownloads) { if (download.NewStatus.HasValue) { download.Download.Status = download.NewStatus.Value; download.NewStatus = null; await downloads.UpdateStatus(downloadId, download.Download.Status); if (download.Download.Status == DownloadStatus.Finished) { ActiveDownloads.TryRemove(downloadId, out _); // Check if all downloads are completed and update the torrent var allDownloads = await downloads.GetForTorrent(download.Download.TorrentId); if (allDownloads.All(m => m.Status == DownloadStatus.Finished)) { await torrents.UpdateStatus(download.Download.TorrentId, TorrentStatus.Finished); if (download.Download.Torrent.AutoDelete) { await torrents.Delete(download.Download.TorrentId); } } } } } }
private async Task ProcessAutoDownloads(IDownloads downloads, ISettings settings, ITorrents torrents) { var allTorrents = await torrents.Get(); allTorrents = allTorrents.Where(m => (m.Status == TorrentStatus.WaitingForDownload && m.AutoDownload && m.Downloads.Count == 0) || m.Status == TorrentStatus.DownloadQueued) .ToList(); foreach (var torrent in allTorrents) { await torrents.Download(torrent.TorrentId); } }
private async Task ProcessDownloads(IDownloads downloads, ISettings settings, ITorrents torrents) { var allDownloads = await downloads.Get(); allDownloads = allDownloads.Where(m => m.Status != DownloadStatus.Finished) .OrderByDescending(m => m.Status) .ThenByDescending(m => m.Added) .ToList(); var maxDownloads = await settings.GetNumber("DownloadLimit"); var destinationFolderPath = await settings.GetString("DownloadFolder"); foreach (var download in allDownloads) { if (ActiveDownloads.ContainsKey(download.DownloadId)) { continue; } if (ActiveDownloads.Count >= maxDownloads) { return; } // Prevent circular references download.Torrent.Downloads = null; await torrents.UpdateStatus(download.TorrentId, TorrentStatus.Downloading); await Task.Factory.StartNew(async delegate { var downloadManager = new DownloadManager(); if (ActiveDownloads.TryAdd(download.DownloadId, downloadManager)) { downloadManager.Download = download; await downloadManager.Start(destinationFolderPath, download.Torrent.RdName, download.Status); } }); } }
public Torrents(ITorrentData torrentData, ISettings settings, IDownloads downloads) { _torrentData = torrentData; _settings = settings; _downloads = downloads; }
public TorrentsController(ITorrents torrents, IDownloads downloads, ITorrentRunner torrentRunner) { _torrents = torrents; _downloads = downloads; _torrentRunner = torrentRunner; }