private Stats.TorrentUploadDeltaSnapshot CreateNewUploadDeltaSnapshotForReAddedTorrent(DateTime jobDateTime, Shared.TorrentClient.Torrent clientTorrent, Stats.Torrent persistedTorrent, Stats.TorrentUploadDeltaSnapshot lastUploadDeltaSnapshot, Stats.TrackerUrlCollection trackerUrlCollection) { _logger.LogInformation("Torrent with hash {0} seems the be re-added", clientTorrent.InfoHash); persistedTorrent.LatestAddedDateTime = clientTorrent.AddedDateTime; var delta = clientTorrent.TotalUploadInBytes; var totalUpload = lastUploadDeltaSnapshot.TotalUploadInBytes + delta; return(CreateTorrentUploadDeltaSnapshot(jobDateTime, clientTorrent, persistedTorrent, trackerUrlCollection, delta, totalUpload)); }
private Stats.TorrentUploadDeltaSnapshot CreateUploadDeltaSnapshotForExistingTorrent(DateTime jobDateTime, Shared.TorrentClient.Torrent clientTorrent, Stats.Torrent persistedTorrent, Stats.TorrentUploadDeltaSnapshot lastUploadDeltaSnapshot, Stats.TrackerUrlCollection trackerUrlCollection) { var delta = clientTorrent.TotalUploadInBytes - lastUploadDeltaSnapshot.TotalUploadForThisTorrentInBytes; if (delta == 0) { _logger.LogDebug("Torrent with hash {0} has a delta of 0, skipping", clientTorrent.InfoHash); return(null); } if (delta < 0) { _logger.LogWarning("Upload delta for torrent with hash {0} is {1} which shouldn't happen, this could be a bug or mean that the torrent client db was restored. Truncating to 0", clientTorrent.InfoHash, delta); delta = 0; } var totalUpload = lastUploadDeltaSnapshot.TotalUploadInBytes + delta; return(CreateTorrentUploadDeltaSnapshot(jobDateTime, clientTorrent, persistedTorrent, trackerUrlCollection, delta, totalUpload)); }
/// <summary> /// Returns null if nothing relevant has changed /// </summary> private Stats.TorrentUploadDeltaSnapshot CreateNewUploadDeltaSnapshot(DateTime jobDateTime, Shared.TorrentClient.Torrent clientTorrent, Stats.Torrent persistedTorrent, Stats.TorrentUploadDeltaSnapshot lastUploadDeltaSnapshot, Stats.TrackerUrlCollection trackerUrlCollection) { _logger.LogDebug("Creating new upload delta snapshot for torrent with hash {0} and name '{1}' if there are any relevant changes", clientTorrent.InfoHash, clientTorrent.Name); if (lastUploadDeltaSnapshot == null) { return(CreateUploadDeltaSnapshotForNewTorrent(jobDateTime, clientTorrent, persistedTorrent, trackerUrlCollection)); } if (clientTorrent.AddedDateTime != persistedTorrent.LatestAddedDateTime) { return(CreateNewUploadDeltaSnapshotForReAddedTorrent(jobDateTime, clientTorrent, persistedTorrent, lastUploadDeltaSnapshot, trackerUrlCollection)); } else { return(CreateUploadDeltaSnapshotForExistingTorrent(jobDateTime, clientTorrent, persistedTorrent, lastUploadDeltaSnapshot, trackerUrlCollection)); } }