SEBWIN-320: Implemented scroll mechanism for log step.

This commit is contained in:
dbuechel 2019-07-16 15:43:10 +02:00
parent 71854b33d8
commit a27723dc35
2 changed files with 60 additions and 11 deletions

View file

@ -15,8 +15,8 @@ namespace SafeExamBrowser.ResetUtility.Procedure
{
protected Context Context { get; }
protected ILogger Logger => Context.Logger;
protected ConsoleColor BackgroundColor => ConsoleColor.Black;
protected ConsoleColor ForegroundColor => ConsoleColor.White;
protected ConsoleColor BackgroundColor => ConsoleColor.White;
protected ConsoleColor ForegroundColor => ConsoleColor.Black;
internal ProcedureStep(Context context)
{

View file

@ -7,6 +7,7 @@
*/
using System;
using System.Collections.Generic;
using SafeExamBrowser.Contracts.Logging;
namespace SafeExamBrowser.ResetUtility.Procedure
@ -19,10 +20,43 @@ namespace SafeExamBrowser.ResetUtility.Procedure
internal override ProcedureStepResult Execute()
{
Initialize();
var log = Logger.GetLog();
var offset = 0;
foreach (var item in Logger.GetLog())
for (var key = default(ConsoleKey); key != ConsoleKey.Enter; key = Console.ReadKey(true).Key)
{
offset = UpdateOffset(key, offset, log.Count);
Initialize();
PrintInstructions();
PrintLogSection(log, offset);
}
return ProcedureStepResult.Continue;
}
internal override ProcedureStep GetNextStep()
{
return new MainMenu(Context);
}
private void PrintInstructions()
{
Console.WriteLine("Use the up/down arrow keys to scroll. Press enter to return to the main menu.");
Console.WriteLine();
}
private void PrintLogSection(IList<ILogContent> log, int offset)
{
var count = 0;
foreach (var item in log)
{
if (offset > log.IndexOf(item))
{
continue;
}
if (item is ILogMessage message)
{
PrintMessage(message);
@ -32,18 +66,33 @@ namespace SafeExamBrowser.ResetUtility.Procedure
{
PrintText(text);
}
}
Console.WriteLine();
Console.WriteLine("Press any key to return to the main menu.");
Console.ReadKey(true);
count++;
return ProcedureStepResult.Continue;
}
internal override ProcedureStep GetNextStep()
if (Console.CursorTop >= Console.BufferHeight - 3)
{
return new MainMenu(Context);
break;
}
}
Console.SetCursorPosition(0, Console.BufferHeight - 3);
Console.WriteLine();
Console.WriteLine($"Showing entries {offset + 1} - {offset + count} of total {log.Count}.");
}
private int UpdateOffset(ConsoleKey key, int offset, int total)
{
if (key == ConsoleKey.DownArrow)
{
offset = offset == total - 1 ? offset : offset + 1;
}
if (key == ConsoleKey.UpArrow)
{
offset = offset == 0 ? offset : offset - 1;
}
return offset;
}
private void PrintMessage(ILogMessage message)
@ -80,7 +129,7 @@ namespace SafeExamBrowser.ResetUtility.Procedure
switch (severity)
{
case LogLevel.Debug:
return ConsoleColor.Gray;
return ConsoleColor.DarkGray;
case LogLevel.Error:
return ConsoleColor.Red;
case LogLevel.Warning: