diff --git a/Vrh.Log4Pro.MaintenanceConsole/App.config b/Vrh.Log4Pro.MaintenanceConsole/App.config
index e8d9451..dedbba6 100644
--- a/Vrh.Log4Pro.MaintenanceConsole/App.config
+++ b/Vrh.Log4Pro.MaintenanceConsole/App.config
@@ -1,9 +1,9 @@
-
-
-
+
+
+
diff --git a/Vrh.Log4Pro.MaintenanceConsole/Config.xml b/Vrh.Log4Pro.MaintenanceConsole/Config.xml
index 0707af0..123bb84 100644
--- a/Vrh.Log4Pro.MaintenanceConsole/Config.xml
+++ b/Vrh.Log4Pro.MaintenanceConsole/Config.xml
@@ -187,4 +187,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
index 5a4a8fb..074c2f3 100644
--- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
+++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
@@ -16,6 +16,36 @@ namespace Vrh.Log4Pro.MaintenanceConsole
#region ColorConsole
public static class ColorConsole
{
+ private static bool silentMode = false;
+ private static string[] readlineList = null;
+
+ /// Üzenet és utána Billentyűzet lenyomásra vár
+ ///
+ ///
+ ///
+ public static ConsoleKeyInfo PressAnykeyToContinue(string text = null)
+ {
+ ColorConsole.WriteLine(text ?? "Press any key to continue...", ConsoleColor.Yellow); return ColorConsole.ReadKey();
+ }
+
+
+ ///
+ /// Beállítja a command mode-ot, ami azt jelenti, hogy nem ír semmit a konzolra,
+ /// és a readline egy előre feltöltött bufferból olvassa az inputokat
+ ///
+ ///
+ public static void SetSilentMode(bool silentmode=true) { silentMode = silentmode; }
+ ///
+ /// Feltölti a command mode readline bufferét egy string tömbbel;
+ /// minden ColorConsole.ReadLine a tömb pillanatnyi első elemét adja vissza, amjd törli azt a tömbből
+ ///
+ ///
+ public static void SetReadLineList(string[] readlinelist) { readlineList = readlinelist; }
+ ///
+ /// A megadott stringet szóközökkel ritkított formában adja vissza
+ ///
+ ///
+ ///
public static string WideString(string txt)
{
if (txt == null) { return null; };
@@ -25,18 +55,116 @@ namespace Vrh.Log4Pro.MaintenanceConsole
return widetxt.Substring(0, widetxt.Length - 1);
}
+ ///
+ /// true, ha van lenyomott billentyű, illetve command mode-ban mindig false
+ ///
+ public static bool KeyAvailable { get { if (silentMode) { return false; } else { return Console.KeyAvailable; } } }
+
+
+ ///
+ /// Beállítja a console ablak méretét
+ ///
+ ///
+ ///
+ public static void SetWindowSize(int w, int h) { if (!silentMode) { Console.SetWindowSize(w, h); } }
+
+ ///
+ /// Visszaadja a lenyomott billentyűt, ha van, commandmode-ban pedig az enter-t
+ ///
+ ///
+ public static ConsoleKeyInfo ReadKey()
+ {
+ if (silentMode) { return GetConsoleKey(ConsoleKey.Enter); }
+ else { return Console.ReadKey(); }
+ }
+
+ ///
+ /// Visszaadja a lenyomott billentyűt, ha van, commandmode-ban pedig az enter-t
+ ///
+ ///
+ public static ConsoleKeyInfo GetConsoleKey(ConsoleKey ck, bool shift = false, bool alt=false,bool control=false)
+ {
+ switch (ck)
+ {
+ case ConsoleKey.Enter:
+ default:
+ return new ConsoleKeyInfo(keyChar: '\r', key: ConsoleKey.Enter, shift: shift, alt: alt, control: control);
+ }
+ }
+
+ ///
+ /// Beolvas egy sort a consolról, vagy commandmode-ban a bufferból
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
public static string ReadLine(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null, string prefix = "")
{
- Write(text, f, b,bracket,prefix);
- return Console.ReadLine();
+ if (silentMode)
+ {
+ if (readlineList == null || readlineList.Length == 0) { return null; }
+ else
+ {
+ var nextreadline = readlineList[0];
+ readlineList = readlineList.Skip(1).ToArray();
+ return nextreadline;
+ }
+ }
+ else
+ {
+ Write(text, f, b, bracket, prefix);
+ return Console.ReadLine();
+ }
+ }
+
+ ///
+ /// beállítja a cursor pozíciót
+ ///
+ ///
+ ///
+ public static void SetCursorPosition(int remembercursorleft, int remembercursortop)
+ {
+ if (silentMode) { return; }
+ Console.SetCursorPosition(remembercursorleft, remembercursortop);
}
+
+ public static int CursorLeft { get { return Console.CursorLeft; } }
+ public static int CursorTop { get { return Console.CursorTop; } }
+
+ public static void Clear() { Console.Clear(); }
+
+ ///
+ /// Kiír egy karaktersorozatot színesben a konzolra soremeléssel;
+ /// command mode-ban nem csinál semmit
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
public static void WriteLine(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null,string prefix="", string suffix = "")
{
+ if (silentMode) { return; }
Write(text, f, b, bracket,prefix,suffix);
Console.WriteLine();
}
+ ///
+ /// Kiír egy karaktersorozatot színesben a konzolra soremelés nélkül;
+ /// command mode-ban nem csinál semmit
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
public static void Write(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null, string prefix = "",string suffix="")
{
+ if (silentMode) { return; }
if (!string.IsNullOrEmpty(prefix)) { Write(prefix); }
if (!string.IsNullOrEmpty(bracket) && bracket.Length==1) { bracket = bracket + bracket; }
if (!string.IsNullOrEmpty(bracket)) { Console.Write($"{bracket[0]}"); }
diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
index b0d56ed..942b44d 100644
--- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
+++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
@@ -135,8 +135,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole
Test(44,"this \"is a\" test", new[] { "this", "is a", "test" });
Test(45,"\"C:\\Program Files\"", new[] { "C:\\Program Files" });
Test(46,"\"He whispered to her \\\"I love you\\\".\"", new[] { "He whispered to her \"I love you\"." });
- Console.WriteLine("Press a key to continue....");
- Console.ReadKey();
+ ColorConsole.WriteLine("Press a key to continue....");
+ ColorConsole.ReadKey();
}
static void Test(int id,string cmd, string[] r)
{
@@ -149,28 +149,28 @@ namespace Vrh.Log4Pro.MaintenanceConsole
if (r.Length != sr.Length)
{
- Console.WriteLine($"ERROR:{id}");
- Console.WriteLine($" cmdline : {cmd}");
- Console.WriteLine($" splitted: {scmd}");
- Console.WriteLine($" expected: {sexp}");
+ ColorConsole.WriteLine($"ERROR:{id}");
+ ColorConsole.WriteLine($" cmdline : {cmd}");
+ ColorConsole.WriteLine($" splitted: {scmd}");
+ ColorConsole.WriteLine($" expected: {sexp}");
return;
}
for (int i = 0; i < r.Length; i++)
if (r[i] != sr[i])
{
- Console.WriteLine($"ERROR:{id}");
- Console.WriteLine($" cmdline : {cmd}");
- Console.WriteLine($" splitted: {scmd}");
- Console.WriteLine($" expected: {sexp}");
+ ColorConsole.WriteLine($"ERROR:{id}");
+ ColorConsole.WriteLine($" cmdline : {cmd}");
+ ColorConsole.WriteLine($" splitted: {scmd}");
+ ColorConsole.WriteLine($" expected: {sexp}");
return;
}
}
catch (Exception ex)
{
- Console.WriteLine($"EXCEP:{id}");
- Console.WriteLine($" cmdline : {cmd}");
- Console.WriteLine($" splitted: {scmd}");
- Console.WriteLine($" expected: {sexp}");
+ ColorConsole.WriteLine($"EXCEP:{id}");
+ ColorConsole.WriteLine($" cmdline : {cmd}");
+ ColorConsole.WriteLine($" splitted: {scmd}");
+ ColorConsole.WriteLine($" expected: {sexp}");
return;
}
}
diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs
index acca9e2..a4854be 100644
--- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs
+++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs
@@ -11,11 +11,12 @@ using System.Management;
using System.Diagnostics;
using Vrh.XmlProcessing;
+using VRH.Common;
using System.Xml.Linq;
namespace Vrh.Log4Pro.MaintenanceConsole
{
- public class Menu
+ public class Menu
{
public delegate Object MenuItemExecutorFunc(Object p, Object o);
public delegate Object MenuItemDisplayerFunc(Object p, int i);
@@ -25,30 +26,71 @@ namespace Vrh.Log4Pro.MaintenanceConsole
private string Title { get { return ColorConsole.WideString(title); } set { title = value; } }
private MenuItemDisplayerFunc MenuItemDisplayer;
private SelectionMode selectionMode = Menu.SelectionMode.Multi;
+ private static bool commandModeAllMenus = false;
+ private bool commandMode = false;
private int HeaderWidth = 9;
private string SelectionPrompt = "Make Your selection!";
#endregion private fields
#region public properties
public List- MenuItemList { get; private set; } = new List
- ();
- List MenuKeyList { get { return MenuItemList.Where(x=> !x.Separator).Select(x => x.Key).ToList(); } }
+ List MenuKeyList { get { return MenuItemList.Where(x => !x.Separator).Select(x => x.Key).ToList(); } }
#endregion public properties
#region public tools
+
+ ///
+ /// Incorrect selection console üzenet megjelenítése
+ ///
+ ///
+ public static void IncorrectSelection(string partxt = "")
+ {
+ if (GetCommandModeAllMenus()) { return; }
+
+ ColorConsole.WriteLine();
+ ColorConsole.WriteLine($"Incorrect selection! {partxt} Make a new selection!", ConsoleColor.Red);
+ Menu.PressAnykeyToContinue();
+ }
+
+ ///
+ /// Üzenet és utána Billentyűzet lenyomásra vár
+ ///
+ ///
+ ///
+ public static ConsoleKeyInfo PressAnykeyToContinue(string text = null)
+ {
+ if (GetCommandModeAllMenus()) { return ColorConsole.GetConsoleKey(ConsoleKey.Enter); }
+
+ ColorConsole.WriteLine(text ?? "Press any key to continue...", ConsoleColor.Yellow); return ColorConsole.ReadKey();
+ }
+
+
+ public static void SetCommandModeAllMenus() { commandModeAllMenus = true; }
+
public Menu SetMenuItemDisplayer(MenuItemDisplayerFunc displayer)
{
MenuItemDisplayer = displayer;
return this;
}
public Menu SetSelectionMode(SelectionMode sm) { selectionMode = sm; return this; }
- public Menu SetHeaderWidth(int hw) { HeaderWidth= hw; return this; }
- public Menu AddMenuItem(Item mi)
- {
+ public Menu SetCommandMode(bool commandmode = false) { commandMode = true; return this; }
+ public static bool GetCommandModeAllMenus() { return commandModeAllMenus; }
+ public bool GetCommandMode() { return commandMode || commandModeAllMenus; }
+ public Menu SetHeaderWidth(int hw) { HeaderWidth = hw; return this; }
+ public Menu AddMenuItem(Item mi)
+ {
MenuItemList.Add(mi);
if (string.IsNullOrWhiteSpace(mi.Key)) { mi.Key = $"#$KEY{MenuItemList.IndexOf(mi)}"; }
return this;
}
public void ClearMenuItemList() { MenuItemList.Clear(); }
+ public void ExecuteCmd(string[] args)
+ {
+ var module = CommandLine.GetCommandLineArgument(args, "-MODULE");
+ var sr = new Menu.Selection(module, args);
+ ExecuteSelection(sr);
+ }
+
public void ExecuteMenu()
{
try
@@ -61,65 +103,69 @@ namespace Vrh.Log4Pro.MaintenanceConsole
if (sr.Result == Menu.SelectionResult.Exit) { return; }
else if (sr.Result == Menu.SelectionResult.None) { continue; }
else if (sr.Result == Menu.SelectionResult.Error) { continue; }
- Execute(sr.SelectedKeyList);
+ ExecuteSelection(sr.SelectedKeyList);
}
}
- catch (Exception ex)
- {
- ColorConsole.WriteLine(ex.Message,ConsoleColor.Red);
+ catch (Exception ex)
+ {
+ ColorConsole.WriteLine(ex.Message, ConsoleColor.Red);
if (ex.InnerException != null) { ColorConsole.WriteLine(ex.InnerException.Message, ConsoleColor.Red); }
- ColorConsole.WriteLine("Press any key to continue...");
+ Menu.PressAnykeyToContinue();
}
}
public void DisplayTitle()
{
- Console.Clear();
+ if (GetCommandMode()) { return; }
+
+ ColorConsole.Clear();
ColorConsole.WriteLine(Title, ConsoleColor.White);
ColorConsole.WriteLine(new string('-', Title.Length));
}
public void DisplayItems(int columns = 1, int columnlength = 0)
{
+ if (GetCommandMode()) { return; }
+
int columncounter = 0;
ColorConsole.WriteLine();
var i = 1;
- Console.SetCursorPosition(0, Console.CursorTop);
- foreach (var menuitem in MenuItemList)
+ ColorConsole.SetCursorPosition(0, ColorConsole.CursorTop);
+ foreach (var menuitem in MenuItemList)
{
if (menuitem.Separator && columns == 1)
{
- Console.SetCursorPosition(columnlength * columncounter + HeaderWidth, Console.CursorTop);
+ ColorConsole.SetCursorPosition(columnlength * columncounter + HeaderWidth, ColorConsole.CursorTop);
var seplen = menuitem.SeparatorLength;
- if (menuitem.SeparatorLength==0)
+ if (menuitem.SeparatorLength == 0)
{
- foreach (var mi in MenuItemList.Where(x=>!x.Separator)) { if (mi.Text.Length > seplen) { seplen = mi.Text.Length; } }
+ foreach (var mi in MenuItemList.Where(x => !x.Separator)) { if (mi.Text.Length > seplen) { seplen = mi.Text.Length; } }
}
ColorConsole.WriteLine(new string(menuitem.SeparatorChar, seplen));
continue;
}
ColorConsole.Write($"[");
ColorConsole.Write($"{i}");
- if (!string.IsNullOrEmpty(menuitem.Key) && !menuitem.Key.StartsWith("#$KEY"))
+ if (!string.IsNullOrEmpty(menuitem.Key) && !menuitem.Key.StartsWith("#$KEY"))
{
ColorConsole.Write($":");
ColorConsole.Write(menuitem.Key, ConsoleColor.Yellow);
}
ColorConsole.Write($"]");
- Console.SetCursorPosition(columnlength * columncounter+HeaderWidth, Console.CursorTop);
+ ColorConsole.SetCursorPosition(columnlength * columncounter + HeaderWidth, ColorConsole.CursorTop);
if (!string.IsNullOrEmpty(menuitem.Text))
{
- ColorConsole.Write(menuitem.Text);
+ ColorConsole.Write(menuitem.Text);
}
if (columns == 1)
{
if (!string.IsNullOrEmpty(menuitem.Text)) { ColorConsole.WriteLine(); }
- if (MenuItemDisplayer != null)
+ if (MenuItemDisplayer != null)
{
- for (var li = 0; li < 100; li++)
- {
- if (li>0) { ColorConsole.Write(new string(' ',HeaderWidth)); }
+ for (var li = 0; li < 100; li++)
+ {
+ if (li > 0) { ColorConsole.Write(new string(' ', HeaderWidth)); }
var str = (string)MenuItemDisplayer(menuitem.Parameters, li);
- if (string.IsNullOrEmpty(str)) { Console.SetCursorPosition(0, Console.CursorTop); }
+ if (string.IsNullOrEmpty(str)) { ColorConsole.SetCursorPosition(0, ColorConsole.CursorTop); }
if (str == null) { break; }
}
}
@@ -130,49 +176,63 @@ namespace Vrh.Log4Pro.MaintenanceConsole
if (columncounter == columns) { ColorConsole.WriteLine(); columncounter = 0; }
else
{
- Console.SetCursorPosition(columnlength * columncounter - 2, Console.CursorTop);
+ ColorConsole.SetCursorPosition(columnlength * columncounter - 2, ColorConsole.CursorTop);
ColorConsole.Write(" ");
}
}
i++;
}
if (columns != 1) { ColorConsole.WriteLine(); }
- if (selectionMode==SelectionMode.Multi)
+ if (selectionMode == SelectionMode.Multi)
{
- ColorConsole.Write("*", ConsoleColor.Red,bracket:"()");ColorConsole.WriteLine(" All");
+ ColorConsole.Write("*", ConsoleColor.Red, bracket: "()"); ColorConsole.WriteLine(" All");
}
- ColorConsole.Write("EX", ConsoleColor.Red,bracket:"()");ColorConsole.WriteLine(" Exit");
+ ColorConsole.Write("EX", ConsoleColor.Red, bracket: "()"); ColorConsole.WriteLine(" Exit");
}
public class Selection
{
+ public Selection() { }
+ public Selection(string selectedkey,object parameter)
+ {
+ Result = SelectionResult.Ok;
+ SelectedKeyList = new List() { { selectedkey } };
+ SelectedParameterList = new List