diff --git a/Vrh.Log4Pro.MaintenanceConsole/App.config b/Vrh.Log4Pro.MaintenanceConsole/App.config
index dedbba6..dec5bbc 100644
--- a/Vrh.Log4Pro.MaintenanceConsole/App.config
+++ b/Vrh.Log4Pro.MaintenanceConsole/App.config
@@ -5,7 +5,7 @@
-
+
@@ -16,11 +16,19 @@
+
+
+
+
-
+
+
+
+
+
-
\ No newline at end of file
+
diff --git a/Vrh.Log4Pro.MaintenanceConsole/Config.xml b/Vrh.Log4Pro.MaintenanceConsole/Config.xml
index 123bb84..16dc8cd 100644
--- a/Vrh.Log4Pro.MaintenanceConsole/Config.xml
+++ b/Vrh.Log4Pro.MaintenanceConsole/Config.xml
@@ -152,10 +152,10 @@
-
-
-
-
+
+
+
+
@@ -197,4 +197,18 @@
+
+
+
+
+
+
+
+
+
+ ^(T|t)est.*$
+ ^(Operator|Lineleader)$
+
+
+
\ No newline at end of file
diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
index 074c2f3..91e91a5 100644
--- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
+++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
@@ -11,7 +11,7 @@ using System.Diagnostics;
using Vrh.XmlProcessing;
using System.Xml.Linq;
-namespace Vrh.Log4Pro.MaintenanceConsole
+namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS
{
#region ColorConsole
public static class ColorConsole
@@ -101,7 +101,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole
///
///
///
- public static string ReadLine(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null, string prefix = "")
+ public static string ReadLine(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null, string prefix = "",string suffix = "")
{
if (silentMode)
{
@@ -115,7 +115,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole
}
else
{
- Write(text, f, b, bracket, prefix);
+ Write(text, f, b, bracket, prefix,suffix);
return Console.ReadLine();
}
}
@@ -133,6 +133,12 @@ namespace Vrh.Log4Pro.MaintenanceConsole
public static int CursorLeft { get { return Console.CursorLeft; } }
public static int CursorTop { get { return Console.CursorTop; } }
+ public static int WindowWidth { get { return Console.WindowWidth; } }
+ public static int BufferWidth { get { return Console.BufferWidth; } }
+ public static int WindowHeight { get { return Console.WindowHeight; } }
+ public static int BufferHeight { get { return Console.BufferHeight; } }
+ public static int WindowLeft { get { return Console.WindowLeft; } }
+ public static int WindowTop { get { return Console.WindowTop; } }
public static void Clear() { Console.Clear(); }
diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
index 942b44d..1b0d388 100644
--- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
+++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
@@ -8,10 +8,12 @@ using Microsoft.Web.Administration;
using System.Management;
using System.Diagnostics;
+using Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS;
+
using Vrh.XmlProcessing;
using System.Xml.Linq;
-namespace Vrh.Log4Pro.MaintenanceConsole
+namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS
{
#region CommandLineParser
public static class CommandLineParser
@@ -74,7 +76,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole
}
else if (chr == ' ' && !quoted)
{
- if (started) yield return result.ToString();
+ if (started) { yield return result.ToString(); }
result.Clear();
started = false;
}
@@ -85,7 +87,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole
}
}
- if (started) yield return result.ToString();
+ if (started) { yield return result.ToString(); }
}
public static void UnitTest()
{
@@ -156,6 +158,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole
return;
}
for (int i = 0; i < r.Length; i++)
+ {
if (r[i] != sr[i])
{
ColorConsole.WriteLine($"ERROR:{id}");
@@ -164,8 +167,9 @@ namespace Vrh.Log4Pro.MaintenanceConsole
ColorConsole.WriteLine($" expected: {sexp}");
return;
}
+ }
}
- catch (Exception ex)
+ catch
{
ColorConsole.WriteLine($"EXCEP:{id}");
ColorConsole.WriteLine($" cmdline : {cmd}");
@@ -176,4 +180,119 @@ namespace Vrh.Log4Pro.MaintenanceConsole
}
}
#endregion CommandLineParser
+ #region Commandline parameter definition class
+ public static class CLP
+ {
+ public const string CMD_MODULE = "-MODULE";
+ public const string CMD_FUNCTION = "-FUNCTION";
+ public const string CMD_SILENT = "-SILENT";
+ public const string CMD_APPCONFIG = "-APPCONFIG";
+ public static class Module
+ {
+ public static class Log4ProUserManager
+ {
+ public const string KEY = "LUM";
+ public static class Functions
+ {
+ public static class CreateSuperuser { public const string KEY = "CSU"; }
+ public static class CreateAdminusers { public const string KEY = "CAU"; }
+ public static class DeleteUsers { public const string KEY = "DEU"; }
+ }
+ }
+ public static class WebApplicationManager
+ {
+ public const string KEY = "WAM";
+ public static class Function
+ {
+ public const string CMD_WEBAPPS = "-WEBAPPS";
+ public static class Register { public const string KEY = "WAR"; }
+ public static class Unregister { public const string KEY = "WAU"; }
+ public static class SetImpersonateIdentity { public const string KEY = "WAI"; }
+ public static class PoolStart { public const string KEY = "APS"; }
+ public static class PoolStop { public const string KEY = "APF"; }
+ public static class PoolRecycle { public const string KEY = "APR"; }
+ public static class SiteStart { public const string KEY = "WSS"; }
+ public static class SiteStop { public const string KEY = "WSF"; }
+ public static class PoolSetUserAccount { public const string KEY = "APU"; }
+ public static class Restart { public const string KEY = "R"; }
+ }
+ }
+ public static class WindowsServiceManager
+ {
+ public const string KEY = "WSM";
+ public static class Function
+ {
+ public const string CMD_SERVICES = "-SERVICES";
+ public static class Register { public const string KEY = "WSR"; }
+ public static class Unregister { public const string KEY = "WSU"; }
+ public static class SetUserAccount { public const string KEY = "WSA"; }
+ public static class Start { public const string KEY = "WSS"; }
+ public static class Stop { public const string KEY = "WSX"; }
+ public static class Kill { public const string KEY = "WSK"; }
+ public static class Purge { public const string KEY = "WSP"; }
+ }
+ }
+ public static class FileCleanerManager
+ {
+ public const string KEY = "FCL";
+ public static class Functions
+ {
+ public const string CMD_FOLDERS = "-FOLDERS";
+ public static class FolderClean { public const string KEY = "CLN"; }
+ }
+ }
+ public static class ScheduledTaskManager
+ {
+ public const string KEY = "SCH";
+ public static class Function
+ {
+ public const string CMD_TASKS = "-TASKS";
+ public static class Install { public const string KEY = "INS"; }
+ public static class Uninstall { public const string KEY = "UIN"; }
+ public static class Run { public const string KEY = "RUN"; }
+ public static class End { public const string KEY = "END"; }
+ public static class Enable { public const string KEY = "ENA"; }
+ public static class Disable { public const string KEY = "DIS"; }
+ public static class ChangePriority { public const string KEY = "CHP"; }
+ }
+ }
+ public static class BackupPackageManager
+ {
+ public const string KEY = "BAK";
+ public static class Functions
+ {
+ public const string CMD_PACKAGES = "-PACKAGES";
+ public static class CreateBackupPackage
+ {
+ public const string KEY = "CRE";
+ }
+ }
+ }
+ public static class SQLDataBaseManager
+ {
+ public const string KEY = "SQL";
+ public static class Function
+ {
+ public const string CMD_DATABASES = "-DATABASES";
+ public static class BackupDataBase { public const string KEY = "BAK"; }
+ public static class CreateCodeScripts { public const string KEY = "CCS"; }
+ public static class CreateDataScripts { public const string KEY = "CDS"; }
+ public static class RestoreDataBase { public const string KEY = "RES"; public const string CMD_RESTOREFIRST = "-RESTOREFIRST";
+ }
+ public static class RelocatePhysicalFiles { public const string KEY = "COP"; }
+ }
+ }
+ public static class MaintenanceToolManager
+ {
+ public const string KEY = "TOL";
+ public static class Functions
+ {
+ public static class RegexTester { public const string KEY = "RGX"; }
+ public static class Tool1 { public const string KEY = "TL1"; }
+ public static class Tool2 { public const string KEY = "TL2"; }
+ }
+ }
+ }
+ }
+ #endregion Commandline parameter definition class
}
diff --git a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs
index a4854be..ce2d4f3 100644
--- a/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs
+++ b/Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs
@@ -10,31 +10,44 @@ using Microsoft.Web.Administration;
using System.Management;
using System.Diagnostics;
+using Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS;
+
using Vrh.XmlProcessing;
using VRH.Common;
using System.Xml.Linq;
-namespace Vrh.Log4Pro.MaintenanceConsole
+namespace Vrh.Log4Pro.MaintenanceConsole.MenuNS
{
public class Menu
{
- public delegate Object MenuItemExecutorFunc(Object p, Object o);
+ ///
+ /// Egy menupont executor függvény prototípusa
+ ///
+ /// az executor paramétereit tartalmazó osztály
+ ///
+ /// több menupont kiválasztásakor ezt a paramétert az első menuponthoz tartozó executor tölti fel,
+ /// majd ezt az értéket megkapja a második, aki módosíthatja, majd megkapja a harmadik, és így tovább...
+ ///
+ ///
+ public delegate Object MenuItemExecutorFunc(Menu.ExecutorParameter p, Object o);
public delegate Object MenuItemDisplayerFunc(Object p, int i);
+ public delegate void MenuHeaderDisplayerFunc();
+
public Menu(string title, string selectionprompt = null) { Title = title; if (!string.IsNullOrWhiteSpace(selectionprompt)) { SelectionPrompt = selectionprompt; } }
#region private fields
private string title;
private string Title { get { return ColorConsole.WideString(title); } set { title = value; } }
private MenuItemDisplayerFunc MenuItemDisplayer;
+ private MenuHeaderDisplayerFunc MenuHeaderDisplayer;
private SelectionMode selectionMode = Menu.SelectionMode.Multi;
- private static bool commandModeAllMenus = false;
- private bool commandMode = false;
- private int HeaderWidth = 9;
+ private static bool commandMode = false;
+ private int MenuItemIndentWidth = 0;
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 MenuItemKeyList { get { return MenuItemList.Where(x => !x.Separator).Select(x => x.Key).ToList(); } }
#endregion public properties
#region public tools
@@ -45,7 +58,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole
///
public static void IncorrectSelection(string partxt = "")
{
- if (GetCommandModeAllMenus()) { return; }
+ if (IsCommandMode()) { return; }
ColorConsole.WriteLine();
ColorConsole.WriteLine($"Incorrect selection! {partxt} Make a new selection!", ConsoleColor.Red);
@@ -59,51 +72,90 @@ namespace Vrh.Log4Pro.MaintenanceConsole
///
public static ConsoleKeyInfo PressAnykeyToContinue(string text = null)
{
- if (GetCommandModeAllMenus()) { return ColorConsole.GetConsoleKey(ConsoleKey.Enter); }
+ if (IsCommandMode()) { return ColorConsole.GetConsoleKey(ConsoleKey.Enter); }
ColorConsole.WriteLine(text ?? "Press any key to continue...", ConsoleColor.Yellow); return ColorConsole.ReadKey();
}
+ ///
+ /// Beállítja a parancs módot a menükezelő számára
+ ///
+ ///
+ public static void SetCommandMode(bool commandmode=true) { commandMode = commandmode; }
- public static void SetCommandModeAllMenus() { commandModeAllMenus = true; }
+ ///
+ /// true= a menükezelő parancs módban van
+ ///
+ ///
+ public static bool IsCommandMode() { return commandMode; }
+ ///
+ /// Beállítja a menükezelő számára a displayer metódust, amelynek feladata
+ /// az egyes menüpontok információjának soronkénti előállítása
+ ///
+ ///
+ ///
public Menu SetMenuItemDisplayer(MenuItemDisplayerFunc displayer)
{
MenuItemDisplayer = displayer;
return this;
}
+
+ ///
+ /// Beállítja a menükezelő számára a header displayer metódust, amelynek feladata
+ /// a menu címe alatti terület információjának előállítása
+ ///
+ ///
+ ///
+ public Menu SetMenuHeaderDisplayer(MenuHeaderDisplayerFunc displayer)
+ {
+ MenuHeaderDisplayer = displayer;
+ return this;
+ }
+
+ ///
+ /// Beállítja, hogy egy, vagy több menüpont választható
+ ///
+ ///
+ ///
public Menu SetSelectionMode(SelectionMode sm) { selectionMode = sm; return this; }
- 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; }
+
+ ///
+ /// Létrehoz egy menüpontot
+ ///
+ ///
+ ///
public Menu AddMenuItem(Item mi)
{
MenuItemList.Add(mi);
if (string.IsNullOrWhiteSpace(mi.Key)) { mi.Key = $"#$KEY{MenuItemList.IndexOf(mi)}"; }
return this;
}
+
+ ///
+ /// Törli a menüpontok listáját
+ ///
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()
+ ///
+ /// Végrehajtja a menüt, azaz választási lehetőséget biztosít, majd végrehajtja a kiválasztott menupontokhoz tartozó executor metódusokat
+ ///
+ ///
+ public void ExecuteMenu(string forcedselectionkeylist=null)
{
try
{
while (true)
{
DisplayTitle();
+ MenuHeaderDisplayer?.Invoke();
DisplayItems();
- var sr = Select();
+ var sr = Select(forcedselectionkeylist);
if (sr.Result == Menu.SelectionResult.Exit) { return; }
else if (sr.Result == Menu.SelectionResult.None) { continue; }
else if (sr.Result == Menu.SelectionResult.Error) { continue; }
ExecuteSelection(sr.SelectedKeyList);
+ if (Menu.IsCommandMode()) { return; }
}
}
catch (Exception ex)
@@ -113,33 +165,70 @@ namespace Vrh.Log4Pro.MaintenanceConsole
Menu.PressAnykeyToContinue();
}
}
+
+
+ ///
+ /// Megjeleníti a menő fejlécét
+ ///
public void DisplayTitle()
{
- if (GetCommandMode()) { return; }
+ if (Menu.IsCommandMode()) { return; }
ColorConsole.Clear();
ColorConsole.WriteLine(Title, ConsoleColor.White);
ColorConsole.WriteLine(new string('-', Title.Length));
}
+
+ private static int SetMenuItemHeaderWidth(List
- MenuItemList,int columns)
+ {
+ var menuItemmaxwidth = 0;
+ var i = 1;
+ foreach (var menuitem in MenuItemList)
+ {
+ var len = 0;
+ len += 1;//ColorConsole.Write($"[");
+ len += $"{i}".Length;// ColorConsole.Write($"{i}");
+ if (menuitem.Separator) { continue; }
+ if (!string.IsNullOrEmpty(menuitem.Key) && !menuitem.Key.StartsWith("#$KEY"))
+ {
+ len += 1;//ColorConsole.Write($":");
+ len += $"{menuitem.Key}".Length;//ColorConsole.Write(menuitem.Key, ConsoleColor.Yellow);
+ }
+ len += 1;//ColorConsole.Write($"]");
+ if (columns == 1)
+ {
+ if (menuItemmaxwidth == 0 || len > menuItemmaxwidth) { menuItemmaxwidth = len+1; }
+ }
+ i++;
+ }
+ return menuItemmaxwidth;
+ }
+
+ ///
+ /// Megjeleníti a menüpontokat
+ ///
+ ///
+ ///
public void DisplayItems(int columns = 1, int columnlength = 0)
{
- if (GetCommandMode()) { return; }
+ if (Menu.IsCommandMode()) { return; }
int columncounter = 0;
ColorConsole.WriteLine();
var i = 1;
ColorConsole.SetCursorPosition(0, ColorConsole.CursorTop);
+ MenuItemIndentWidth = SetMenuItemHeaderWidth(MenuItemList, columns);
foreach (var menuitem in MenuItemList)
{
if (menuitem.Separator && columns == 1)
{
- ColorConsole.SetCursorPosition(columnlength * columncounter + HeaderWidth, ColorConsole.CursorTop);
+ ColorConsole.SetCursorPosition(MenuItemIndentWidth, ColorConsole.CursorTop);
var seplen = menuitem.SeparatorLength;
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 (!string.IsNullOrWhiteSpace(mi.Text) && mi.Text.Length > seplen) { seplen = mi.Text.Length; } }
}
- ColorConsole.WriteLine(new string(menuitem.SeparatorChar, seplen));
+ ColorConsole.WriteLine(new string(menuitem.SeparatorChar, seplen==0?20:seplen));
continue;
}
ColorConsole.Write($"[");
@@ -150,21 +239,18 @@ namespace Vrh.Log4Pro.MaintenanceConsole
ColorConsole.Write(menuitem.Key, ConsoleColor.Yellow);
}
ColorConsole.Write($"]");
- ColorConsole.SetCursorPosition(columnlength * columncounter + HeaderWidth, ColorConsole.CursorTop);
-
- if (!string.IsNullOrEmpty(menuitem.Text))
- {
- ColorConsole.Write(menuitem.Text);
- }
- if (columns == 1)
+ if (columns == 1)
{
+ if (MenuItemIndentWidth == 0) { MenuItemIndentWidth = ColorConsole.CursorLeft + 1; }
+ ColorConsole.SetCursorPosition(MenuItemIndentWidth, ColorConsole.CursorTop);
+ if (!string.IsNullOrEmpty(menuitem.Text)) { ColorConsole.Write(menuitem.Text); }
if (!string.IsNullOrEmpty(menuitem.Text)) { ColorConsole.WriteLine(); }
if (MenuItemDisplayer != null)
{
for (var li = 0; li < 100; li++)
{
- if (li > 0) { ColorConsole.Write(new string(' ', HeaderWidth)); }
- var str = (string)MenuItemDisplayer(menuitem.Parameters, li);
+ if (li > 0) { ColorConsole.Write(new string(' ', MenuItemIndentWidth)); }
+ var str = (string)MenuItemDisplayer.Invoke(menuitem.Parameters, li);
if (string.IsNullOrEmpty(str)) { ColorConsole.SetCursorPosition(0, ColorConsole.CursorTop); }
if (str == null) { break; }
}
@@ -172,6 +258,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole
}
else
{
+ ColorConsole.SetCursorPosition(columnlength * columncounter, ColorConsole.CursorTop);
+ if (!string.IsNullOrEmpty(menuitem.Text)) { ColorConsole.Write(menuitem.Text); }
columncounter++;
if (columncounter == columns) { ColorConsole.WriteLine(); columncounter = 0; }
else
@@ -189,28 +277,61 @@ namespace Vrh.Log4Pro.MaintenanceConsole
}
ColorConsole.Write("EX", ConsoleColor.Red, bracket: "()"); ColorConsole.WriteLine(" Exit");
}
+ public static Selection SelectFromItemList(string listtitle, string selectionprompt, Dictionary items, Menu.SelectionMode mode = SelectionMode.Single,bool getconfirmation=false)
+ {
+ var menubackupfiles = new Menu(listtitle, selectionprompt)
+ .SetSelectionMode(mode);
+
+ foreach (var i in items)
+ {
+ menubackupfiles.AddMenuItem(new Item(null, i.Key, null, new ExecutorParameter(pars: i.Value)));
+ }
+ Menu.Selection ms;
+ while (true)
+ {
+ menubackupfiles.DisplayItems(1);
+ ms = menubackupfiles.Select();
+ if (ms.Result == SelectionResult.None) { continue; }
+ else if (ms.Result == SelectionResult.Error) { continue; }
+ else if (ms.Result == SelectionResult.Exit) { return null; }
+ else
+ {
+ if (!getconfirmation || getconfirmation && ColorConsole.ReadLine("Enter [CONFIRM] to confirm!", ConsoleColor.Yellow,suffix:" --> ").ToUpper() == "CONFIRM") { return ms; }
+ else { continue; }
+ }
+ }
+ }
+
+
+ ///
+ /// A Menuből való választás eredményét tartalmazza
+ ///
public class Selection
{
public Selection() { }
- public Selection(string selectedkey,object parameter)
+ public Selection(string selectedkey, Menu.ExecutorParameter parameter)
{
Result = SelectionResult.Ok;
SelectedKeyList = new List() { { selectedkey } };
- SelectedParameterList = new List