Example #1
0
        public static void LogDownloadProgress(DownloadStatus status, bool fancyLogging)
        {
            int curRow = ConsoleCursorTop;

            try {
                double percentComplete = Math.Round((status.DownloadedSoFar * 100.0) / status.TotalSize, 2);

                Utilities.FormatSize(status.DownloadedSoFar, out decimal sizeValue, out string sizeUnit);
                Utilities.FormatSpeed(status.BytesPerSecond, out decimal speedValue, out string speedUnit);

                string progress = $"{percentComplete}% ({sizeValue} {sizeUnit} at {speedValue} {speedUnit})";
                if (!fancyLogging)
                {
                    Log.StatusLine($"Download progress: {progress}", ConsoleColor.White);
                    return;
                }
                ConsoleSetCursorPosition(0, ConsoleWindowHeight - 1);
                Log.Status($"{progress}             ", ConsoleColor.White);
            } catch (Exception ex) {
                Log.DebugLine($"Failed to report progress: {ex.Message}");
                Log.DebugLine(ex.ToString());
            } finally {
                ConsoleSetCursorPosition(0, curRow);
            }
        }