Esempio n. 1
0
 public TorrentRunner(ISettings settings, ITorrents torrents, IDownloads downloads, IRemoteService remoteService)
 {
     _settings      = settings;
     _torrents      = torrents;
     _downloads     = downloads;
     _remoteService = remoteService;
 }
Esempio n. 2
0
        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);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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);
                    }
                });
            }
        }
Esempio n. 5
0
 public Torrents(ITorrentData torrentData, ISettings settings, IDownloads downloads)
 {
     _torrentData = torrentData;
     _settings    = settings;
     _downloads   = downloads;
 }
Esempio n. 6
0
 public TorrentsController(ITorrents torrents, IDownloads downloads, ITorrentRunner torrentRunner)
 {
     _torrents      = torrents;
     _downloads     = downloads;
     _torrentRunner = torrentRunner;
 }