private static void BitSwarm_StatsUpdated(object source, BitSwarm.StatsUpdatedArgs e) { try { if (view != View.Stats && view != View.Peers) { return; } if (Console.WindowHeight != prevHeight) { prevHeight = Console.WindowHeight; Console.Clear(); } lock (lockRefresh) if (view == View.Peers) { Console.Clear(); Console.SetCursorPosition(0, 0); Console.WriteLine(bitSwarm.DumpPeers()); } else if (view == View.Stats) { Console.SetCursorPosition(0, 0); Console.WriteLine(bitSwarm.DumpStats()); } PrintMenu(); } catch (Exception) { } }
private void OnStatsUpdated(BitSwarm.StatsUpdatedArgs e, Action <string> writeLog, Action <TorrentDownloadStats> onDownloadingProgress) { const string EventType = "StatsUpdated"; var stats = e.Stats; var newDownloadedFiles = _torrent.data.filesIncludes .Where(x => !_downloadedFiles.Contains(x) && File.Exists(Path.Combine(_torrent.data.folder ?? _bitSwarm.Options.FolderComplete, x))) .ToList(); foreach (var newDownloadedFile in newDownloadedFiles) { _downloadedFiles.Add(newDownloadedFile); writeLog($"[{EventType}] Downloaded file {newDownloadedFile}."); } writeLog($"[{EventType}] {ByteSize.FromBytes(stats.BytesDownloadedPrevSession + stats.BytesDownloaded)}/{ByteSize.FromBytes(stats.BytesIncluded)} ({stats.Progress}%)" + $" | Download speed: {ByteSize.FromBytes(stats.DownRate)}/s (max: {ByteSize.FromBytes(stats.MaxRate)}/s)" + $" | ETA: {TimeSpan.FromSeconds(stats.ETA):hh\\:mm\\:ss} AvgETA: {TimeSpan.FromSeconds(stats.AvgETA):hh\\:mm\\:ss}" + $" | Connected peers: {stats.PeersConnected}/{stats.PeersTotal}."); onDownloadingProgress.Invoke(new TorrentDownloadStats { Files = _torrent.file.paths.ToDictionary(x => x, x => new FileStatus { FileName = x, DownloadStatus = _downloadedFiles.Contains(x) ? DownloadStatus.Finished : _torrent.data.filesIncludes.Contains(x) ? DownloadStatus.Downloading : DownloadStatus.Canceled }), Progress = stats.Progress, TotalBytes = stats.BytesIncluded, DownloadedBytes = stats.BytesDownloadedPrevSession + stats.BytesDownloaded, DownloadSpeed = stats.DownRate, MaxSpeed = stats.MaxRate, ETA = TimeSpan.FromSeconds(stats.ETA), AvgETA = TimeSpan.FromSeconds(stats.AvgETA), PeersConnected = stats.PeersConnected, PeersTotal = stats.PeersTotal, }); }
private void Stats(object source, BitSwarm.StatsUpdatedArgs e) { if (fileSize == 0) { return; } var downPercentage = (int)(((fileSize - (torrent.data.progress.GetAll0().Count *(long)torrent.file.pieceLength)) / (decimal)fileSize) * 100); if (downPercentage < 0) { downPercentage = 0; } else if (downPercentage > 100) { downPercentage = 100; } player.renderer.NewMessage(OSDMessage.Type.TorrentStats, $"D: {e.Stats.PeersDownloading} | W: {e.Stats.PeersChoked}/{e.Stats.PeersInQueue} | {String.Format("{0:n0}", (e.Stats.DownRate / 1024))} KB/s | {downPercentage}%"); DownloadNext(); }
private void BitSwarm_StatsUpdated(object source, BitSwarm.StatsUpdatedArgs e) { if (InvokeRequired) { BeginInvoke(new Action(() => BitSwarm_StatsUpdated(source, e))); return; } else { downRate.Text = String.Format("{0:n0}", (e.Stats.DownRate / 1024)) + " KB/s"; downRateAvg.Text = String.Format("{0:n0}", (e.Stats.AvgRate / 1024)) + " KB/s"; maxRate.Text = String.Format("{0:n0}", (e.Stats.MaxRate / 1024)) + " KB/s"; eta.Text = TimeSpan.FromSeconds((e.Stats.ETA + e.Stats.AvgETA) / 2).ToString(@"hh\:mm\:ss"); etaAvg.Text = TimeSpan.FromSeconds(e.Stats.AvgETA).ToString(@"hh\:mm\:ss"); etaCur.Text = TimeSpan.FromSeconds(e.Stats.ETA).ToString(@"hh\:mm\:ss"); bDownloaded.Text = Utils.BytesToReadableString(e.Stats.BytesDownloaded + e.Stats.BytesDownloadedPrevSession); bDropped.Text = Utils.BytesToReadableString(e.Stats.BytesDropped); pPeers.Text = e.Stats.PeersTotal.ToString(); pInqueue.Text = e.Stats.PeersInQueue.ToString(); pConnecting.Text = e.Stats.PeersConnecting.ToString(); pConnected.Text = (e.Stats.PeersConnecting + e.Stats.PeersConnected).ToString(); pFailed.Text = bitSwarm.isDHTRunning ? "On" : "Off"; pFailed1.Text = e.Stats.DHTPeers.ToString(); pFailed2.Text = e.Stats.TRKPeers.ToString(); pChoked.Text = e.Stats.PeersChoked.ToString(); pUnchocked.Text = e.Stats.PeersUnChoked.ToString(); pDownloading.Text = e.Stats.PeersDownloading.ToString(); if (torrent != null && torrent.data.totalSize != 0) { progress.Value = e.Stats.Progress; } //progress.Value = (int) (torrent.data.progress.setsCounter * 100.0 / torrent.data.progress.size); //progress.Value = (int) (stats.BytesDownloaded * 100.0 / torrent.data.totalSize); } }
private void StatsUpdated(object source, BitSwarm.StatsUpdatedArgs e) { player.renderer.NewMessage(OSDMessage.Type.TorrentStats, $"{(downloadNextStarted ? "(N) " : "")}D: {e.Stats.PeersDownloading} | W: {e.Stats.PeersChoked}/{e.Stats.PeersInQueue} | {String.Format("{0:n0}", (e.Stats.DownRate / 1024))} KB/s | {e.Stats.Progress}%"); }
private static void BitSwarm_StatsUpdated(object source, BitSwarm.StatsUpdatedArgs e) { WriteLine(bitSwarm.DumpStats()); }