SEBWIN-320: Implemented scroll mechanism for log step.
This commit is contained in:
		
							parent
							
								
									71854b33d8
								
							
						
					
					
						commit
						a27723dc35
					
				
					 2 changed files with 60 additions and 11 deletions
				
			
		| 
						 | 
					@ -15,8 +15,8 @@ namespace SafeExamBrowser.ResetUtility.Procedure
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		protected Context Context { get; }
 | 
							protected Context Context { get; }
 | 
				
			||||||
		protected ILogger Logger => Context.Logger;
 | 
							protected ILogger Logger => Context.Logger;
 | 
				
			||||||
		protected ConsoleColor BackgroundColor => ConsoleColor.Black;
 | 
							protected ConsoleColor BackgroundColor => ConsoleColor.White;
 | 
				
			||||||
		protected ConsoleColor ForegroundColor => ConsoleColor.White;
 | 
							protected ConsoleColor ForegroundColor => ConsoleColor.Black;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		internal ProcedureStep(Context context)
 | 
							internal ProcedureStep(Context context)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,7 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
using SafeExamBrowser.Contracts.Logging;
 | 
					using SafeExamBrowser.Contracts.Logging;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace SafeExamBrowser.ResetUtility.Procedure
 | 
					namespace SafeExamBrowser.ResetUtility.Procedure
 | 
				
			||||||
| 
						 | 
					@ -19,10 +20,43 @@ namespace SafeExamBrowser.ResetUtility.Procedure
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		internal override ProcedureStepResult Execute()
 | 
							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)
 | 
									if (item is ILogMessage message)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					PrintMessage(message);
 | 
										PrintMessage(message);
 | 
				
			||||||
| 
						 | 
					@ -32,18 +66,33 @@ namespace SafeExamBrowser.ResetUtility.Procedure
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					PrintText(text);
 | 
										PrintText(text);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									count++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if (Console.CursorTop >= Console.BufferHeight - 3)
 | 
				
			||||||
 | 
									{
 | 
				
			||||||
 | 
										break;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								Console.SetCursorPosition(0, Console.BufferHeight - 3);
 | 
				
			||||||
			Console.WriteLine();
 | 
								Console.WriteLine();
 | 
				
			||||||
			Console.WriteLine("Press any key to return to the main menu.");
 | 
								Console.WriteLine($"Showing entries {offset + 1} - {offset + count} of total {log.Count}.");
 | 
				
			||||||
			Console.ReadKey(true);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			return ProcedureStepResult.Continue;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		internal override ProcedureStep GetNextStep()
 | 
							private int UpdateOffset(ConsoleKey key, int offset, int total)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return new MainMenu(Context);
 | 
								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)
 | 
							private void PrintMessage(ILogMessage message)
 | 
				
			||||||
| 
						 | 
					@ -80,7 +129,7 @@ namespace SafeExamBrowser.ResetUtility.Procedure
 | 
				
			||||||
			switch (severity)
 | 
								switch (severity)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				case LogLevel.Debug:
 | 
									case LogLevel.Debug:
 | 
				
			||||||
					return ConsoleColor.Gray;
 | 
										return ConsoleColor.DarkGray;
 | 
				
			||||||
				case LogLevel.Error:
 | 
									case LogLevel.Error:
 | 
				
			||||||
					return ConsoleColor.Red;
 | 
										return ConsoleColor.Red;
 | 
				
			||||||
				case LogLevel.Warning:
 | 
									case LogLevel.Warning:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue