Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit fd6bd650 authored by Michael KRISPER's avatar Michael KRISPER
Browse files

VECTO-425 corrected printing of progress if console output was redirected:...

VECTO-425 corrected printing of progress if console output was redirected: only last progress is written
parent 96e82763
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,7 @@ using System.Xml.Linq;
using NLog;
using NLog.Config;
using NLog.Targets;
using TUGraz.VectoCommon.Exceptions;
using TUGraz.VectoCommon.InputData;
using TUGraz.VectoCommon.Models;
using TUGraz.VectoCommon.Utils;
......@@ -243,7 +244,6 @@ Examples:
timings.Add("Reading input files", stopWatch.Elapsed.TotalMilliseconds);
stopWatch.Reset();
WriteLine(@"Starting simulation runs", ConsoleColor.White);
if (_debugEnabled) {
WriteLine(@"Debug-Output is enabled, executing simulation runs sequentially", ConsoleColor.Yellow);
......@@ -269,7 +269,7 @@ Examples:
stopWatch.Stop();
timings.Add("Simulation runs", stopWatch.Elapsed.TotalMilliseconds);
PrintProgress(_jobContainer.GetProgress(), args.Contains("-t"));
PrintProgress(_jobContainer.GetProgress(), args.Contains("-t"), force: true);
if (args.Contains("-t")) {
PrintTimings(timings);
......@@ -343,46 +343,53 @@ Examples:
}
private static void PrintProgress(Dictionary<int, JobContainer.ProgressEntry> progessData,
bool showTiming = true)
bool showTiming = true, bool force = false)
{
if (_quiet) {
return;
}
try {
if (_quiet || (Console.IsOutputRedirected && !force)) {
return;
}
Console.SetCursorPosition(0, Console.CursorTop - _numLines);
_numLines = 0;
var sumProgress = 0.0;
foreach (var progressEntry in progessData) {
if (progressEntry.Value.Success) {
Console.ForegroundColor = ConsoleColor.Green;
} else if (progressEntry.Value.Error != null) {
Console.ForegroundColor = ConsoleColor.Red;
if (!Console.IsOutputRedirected) {
Console.SetCursorPosition(0, Console.CursorTop - _numLines);
}
_numLines = 0;
var sumProgress = 0.0;
foreach (var progressEntry in progessData) {
if (progressEntry.Value.Success) {
Console.ForegroundColor = ConsoleColor.Green;
} else if (progressEntry.Value.Error != null) {
Console.ForegroundColor = ConsoleColor.Red;
}
var timingString = "";
if (showTiming && progressEntry.Value.ExecTime > 0) {
timingString = string.Format("{0,9:F2}s", progressEntry.Value.ExecTime / 1000.0);
}
var runName = string.Format("{0} {1} {2}", progressEntry.Value.RunName, progressEntry.Value.CycleName,
progressEntry.Value.RunSuffix);
Console.WriteLine(@"{0,-60} {1,8:P}{2}", runName, progressEntry.Value.Progress, timingString);
Console.ResetColor();
sumProgress += progressEntry.Value.Progress;
_numLines++;
}
var timingString = "";
if (showTiming && progressEntry.Value.ExecTime > 0) {
timingString = string.Format("{0,9:F2}s", progressEntry.Value.ExecTime / 1000.0);
sumProgress /= _numLines;
var spinner = "/-\\|"[ProgessCounter++ % 4];
var bar = new string('#', (int)(sumProgress * 100.0 / 2));
Console.WriteLine(@" {2} [{1,-50}] [{0,7:P}]", sumProgress, bar, spinner);
if (WarningMessages.Any()) {
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(@"Warnings: {0,5}", WarningMessages.Count);
Console.ResetColor();
} else {
Console.WriteLine("");
}
var runName = string.Format("{0} {1} {2}", progressEntry.Value.RunName, progressEntry.Value.CycleName,
progressEntry.Value.RunSuffix);
Console.WriteLine(@"{0,-60} {1,8:P}{2}", runName, progressEntry.Value.Progress, timingString);
Console.ResetColor();
sumProgress += progressEntry.Value.Progress;
_numLines++;
}
sumProgress /= _numLines;
var spinner = "/-\\|"[ProgessCounter++ % 4];
var bar = new string('#', (int)(sumProgress * 100.0 / 2));
Console.WriteLine(@" {2} [{1,-50}] [{0,7:P}]", sumProgress, bar, spinner);
if (WarningMessages.Any()) {
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(@"Warnings: {0,5}", WarningMessages.Count);
Console.ResetColor();
} else {
Console.WriteLine("");
_numLines += 2;
} catch (Exception e) {
throw new VectoException("Error during writing progress to output: " + e.Message);
}
_numLines += 2;
}
private static void PrintTimings(Dictionary<string, double> timings)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment