private static Stats.TorrentUploadDeltaSnapshot CreateTorrentUploadDeltaSnapshot(DateTime jobDateTime, Shared.TorrentClient.Torrent clientTorrent, Stats.Torrent persistedTorrent, Stats.TrackerUrlCollection trackerUrlCollection, long delta, long totalUpload) { return(new Stats.TorrentUploadDeltaSnapshot { DateTime = jobDateTime, TorrentId = persistedTorrent.Id, TotalUploadForThisTorrentInBytes = clientTorrent.TotalUploadInBytes, TrackerUrlCollection = trackerUrlCollection, TotalUploadInBytes = totalUpload, UploadDeltaSinceLastSnapshotInBytes = delta, }); }
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)); }
private Stats.TorrentUploadDeltaSnapshot CreateUploadDeltaSnapshotForNewTorrent(DateTime jobDateTime, Shared.TorrentClient.Torrent clientTorrent, Stats.Torrent persistedTorrent, Stats.TrackerUrlCollection trackerUrlCollection) { _logger.LogDebug("Creating first upload delta snapshot for torrent with hash {0}", clientTorrent.InfoHash); return(CreateTorrentUploadDeltaSnapshot(jobDateTime, clientTorrent, persistedTorrent, trackerUrlCollection, delta: clientTorrent.TotalUploadInBytes, totalUpload: clientTorrent.TotalUploadInBytes)); }
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)); }
/// <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)); } }