コード例 #1
0
        /// <summary>
        /// Disable torrents that are missing since last scan
        /// </summary>
        private async Task UpdateRemovedTorrentsAsync(ITorrentStatisticsRepository torrentStatisticsRepository, IList <Shared.TorrentStatistics.Torrent> persistedTorrents)
        {
            var exlcudedIds     = persistedTorrents.Select(t => t.Id).ToArray();
            var removedTorrents = await torrentStatisticsRepository.GetTorrentsThatWereInLastScanAsync(exlcudedIds);

            _logger.LogInformation("Updating {0} torrents that were removed in the torrentclient", removedTorrents.Count);

            foreach (var removedTorrent in removedTorrents)
            {
                _logger.LogDebug("Setting WasInClientOnLastScan to false for torrent with hash {0} and name '{1}'", removedTorrent.InfoHash, removedTorrent.Name);
                removedTorrent.WasInClientOnLastScan = false;
            }
        }
コード例 #2
0
        private async Task AddNewTorrentsAsync(ITorrentStatisticsRepository torrentStatisticsRepository,
                                               IEnumerable <Shared.TorrentClient.Torrent> torrentsFromClient, IList <Stats.Torrent> persistedTorrents)
        {
            var newTorrents = torrentsFromClient
                              .Where(t => !persistedTorrents.Any(pt => pt.InfoHash == t.InfoHash))
                              .Select(t => new Stats.Torrent(t))
                              .ToArray();

            _logger.LogInformation("Adding {0} new torrents that were added to the torrentclient for the first time", newTorrents.Length);

            foreach (var newTorrent in newTorrents)
            {
                _logger.LogDebug("Adding torrent with hash {0} and name '{1}'", newTorrent.InfoHash, newTorrent.Name);
            }

            await torrentStatisticsRepository.AddRangeAsync(newTorrents);
        }
コード例 #3
0
        private async Task AddUploadDeltaSnapshotsInnerAsync(DateTime jobDateTime, IEnumerable <Shared.TorrentClient.Torrent> torrentsFromClient,
                                                             ITorrentStatisticsRepository torrentStatisticsRepository, Dictionary <byte[], Stats.TrackerUrlCollection> trackerUrlCollectionsDict)
        {
            foreach (var clientTorrent in torrentsFromClient)
            {
                _logger.LogDebug("Retrieving torrentdata and last snapshot for torrent with hash {0}", clientTorrent.InfoHash);
                var persistedTorrent = await torrentStatisticsRepository.GetTorrentByInfoHashAsync(clientTorrent.InfoHash);

                var lastUploadDeltaSnapshot = await torrentStatisticsRepository.GetLastTorrentUploadDeltaSnapshotByTorrentIdAsync(persistedTorrent.Id, tracking : true);

                _logger.LogDebug("Retrieving or creating tracker url collection for torrent with hash {0}", clientTorrent.InfoHash);
                var trackerUrlCollection = await GetOrCreateTrackerUrlCollectionAsync(torrentStatisticsRepository, trackerUrlCollectionsDict, clientTorrent);

                //Returns null if there's no significant change to create a delta for
                var newUploadDeltaSnapshot = CreateNewUploadDeltaSnapshot(jobDateTime, clientTorrent, persistedTorrent, lastUploadDeltaSnapshot, trackerUrlCollection);

                if (newUploadDeltaSnapshot != null)
                {
                    await torrentStatisticsRepository.AddAsync(newUploadDeltaSnapshot);
                }
            }
        }
コード例 #4
0
        private async ValueTask <Stats.TrackerUrlCollection> GetOrCreateTrackerUrlCollectionAsync
            (ITorrentStatisticsRepository torrentStatisticsRepository,
            Dictionary <byte[], Stats.TrackerUrlCollection> trackerUrlCollectionsDict,
            Shared.TorrentClient.Torrent clientTorrent)
        {
            var trackerUrls = clientTorrent.TrackerUrls
                              .Select(tu => tu.ToLower())
                              .OrderBy(tu => tu)
                              .Distinct()
                              .ToArray();

            var hashString = string.Join(";", trackerUrls);
            var hash       = _hasher.ComputeHash(Encoding.UTF8.GetBytes(hashString));

            _logger.LogTrace("Retrieving or creating tracker url collection for torrent with hash {0}", clientTorrent.InfoHash);

            if (!trackerUrlCollectionsDict.TryGetValue(hash, out var trackerUrlCollection))
            {
                _logger.LogDebug("Didn't find any tracker url collection for torrent with hash {0}, creating one (urls are: {1})", clientTorrent.InfoHash, trackerUrls);

                trackerUrlCollection = new Stats.TrackerUrlCollection()
                {
                    CollectionHash = hash,
                    TrackerUrls    = trackerUrls.Select(tu => new Stats.TrackerUrl(tu)).ToList()
                };
                await torrentStatisticsRepository.AddAsync(trackerUrlCollection);

                trackerUrlCollectionsDict[hash] = trackerUrlCollection;
            }
            else
            {
                _logger.LogTrace("Found tracker url collection for torrent with hash {0}", clientTorrent.InfoHash);
            }

            return(trackerUrlCollection);
        }