2
0

Added New CLI Options to list enqueued task and view last 20 loglines

This commit is contained in:
glax 2023-05-21 02:11:47 +02:00
parent fe52d2c3b5
commit 32467191f6
2 changed files with 30 additions and 19 deletions

View File

@ -18,25 +18,22 @@ public class MemoryLogger : LoggerBase
public string[] GetLogMessage()
{
string[] ret = new string[logMessages.Count];
for (int logMessageIndex = 0; logMessageIndex < ret.Length; logMessageIndex++)
{
DateTime logTime = logMessages.GetValueAtIndex(logMessageIndex).logTime;
string dateTimeString = $"{logTime.ToShortDateString()} {logTime.ToShortTimeString()}";
string callerString = logMessages.GetValueAtIndex(logMessageIndex).caller.ToString();
string value = $"[{dateTimeString}] {callerString} | {logMessages.GetValueAtIndex(logMessageIndex).value}";
ret[logMessageIndex] = value;
}
return Tail(Convert.ToUInt32(logMessages.Count));
}
public string[] Tail(uint? length)
{
int retLength;
if (length is null || length > logMessages.Count)
retLength = logMessages.Count;
else
retLength = (int)length;
string[] ret = new string[retLength];
for (int logMessageIndex = logMessages.Count - retLength; logMessageIndex < logMessages.Count; logMessageIndex++)
ret[logMessageIndex + retLength - logMessages.Count] = logMessages.GetValueAtIndex(logMessageIndex).ToString();
return ret;
}
public string[] Tail(uint length)
{
string[] ret = new string[length];
for (int logMessageIndex = logMessages.Count - 1; logMessageIndex > logMessageIndex - length; logMessageIndex--)
ret[logMessageIndex] = logMessages.GetValueAtIndex(logMessageIndex).ToString();
return ret.Reverse().ToArray();
}
}

View File

@ -110,6 +110,18 @@ public static class Tranga_Cli
Console.WriteLine("Press any key.");
Console.ReadKey();
break;
case ConsoleKey.K:
PrintTasks(taskManager.GetAllTasks().Where(qTask => qTask.state is TrangaTask.ExecutionState.Enqueued).ToArray(), logger);
Console.WriteLine("Press any key.");
Console.ReadKey();
break;
case ConsoleKey.F:
Console.Clear();
foreach (string message in logger.Tail(20))
Console.Write(message);
Console.WriteLine("Press any key.");
Console.ReadKey();
break;
}
selection = PrintMenu(taskManager, settings.downloadLocation, logger);
}
@ -140,7 +152,9 @@ public static class Tranga_Cli
Console.WriteLine($"{"C: Create Task",-30}{"L: List tasks",-30}");
Console.WriteLine($"{"D: Delete Task",-30}{"R: List Running Tasks", -30}");
Console.WriteLine($"{"E: Execute Task now",-30}{"S: Search Tasks", -30}");
Console.WriteLine();
Console.WriteLine($"{"",-30}{"K: List Task Queue", -30}");
//Console.WriteLine();
Console.WriteLine($"{"F: Show last 20 Log-lines",-30}{"",-30}");
Console.WriteLine($"{"U: Update this Screen",-30}{"Q: Exit",-30}");
ConsoleKey selection = Console.ReadKey().Key;
logger.WriteLine("Tranga_CLI", $"Menu selection: {selection}");