Commit 247be1a20223b78a8b202e684db1c232a2aa115e
1 parent
e9ee2f8b
v1.8.5
- a service kezelő menüjének átalakítása
Showing
5 changed files
with
197 additions
and
202 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
| ... | ... | @@ -16,7 +16,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
| 16 | 16 | #region ColorConsole |
| 17 | 17 | public static class ColorConsole |
| 18 | 18 | { |
| 19 | - private static bool silentMode = false; | |
| 19 | + /// <summary> | |
| 20 | + /// true= nem ír semmit a konzolra, és a readline egy előre feltöltött bufferból olvassa az inputokat | |
| 21 | + /// </summary> | |
| 22 | + public static bool SilentMode { get; set; } = false; | |
| 20 | 23 | private static string[] readlineList = null; |
| 21 | 24 | |
| 22 | 25 | /// Üzenet és utána Billentyűzet lenyomásra vár |
| ... | ... | @@ -28,13 +31,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
| 28 | 31 | ColorConsole.WriteLine(text ?? "Press any key to continue...", ConsoleColor.Yellow); return ColorConsole.ReadKey(); |
| 29 | 32 | } |
| 30 | 33 | |
| 31 | - | |
| 32 | - /// <summary> | |
| 33 | - /// Beállítja a command mode-ot, ami azt jelenti, hogy nem ír semmit a konzolra, | |
| 34 | - /// és a readline egy előre feltöltött bufferból olvassa az inputokat | |
| 35 | - /// </summary> | |
| 36 | - /// <param name="silentmode"></param> | |
| 37 | - public static void SetSilentMode(bool silentmode=true) { silentMode = silentmode; } | |
| 38 | 34 | /// <summary> |
| 39 | 35 | /// Feltölti a command mode readline bufferét egy string tömbbel; |
| 40 | 36 | /// minden ColorConsole.ReadLine a tömb pillanatnyi első elemét adja vissza, amjd törli azt a tömbből |
| ... | ... | @@ -58,7 +54,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
| 58 | 54 | /// <summary> |
| 59 | 55 | /// true, ha van lenyomott billentyű, illetve command mode-ban mindig false |
| 60 | 56 | /// </summary> |
| 61 | - public static bool KeyAvailable { get { if (silentMode) { return false; } else { return Console.KeyAvailable; } } } | |
| 57 | + public static bool KeyAvailable { get { if (SilentMode) { return false; } else { return Console.KeyAvailable; } } } | |
| 62 | 58 | |
| 63 | 59 | |
| 64 | 60 | /// <summary> |
| ... | ... | @@ -66,7 +62,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
| 66 | 62 | /// </summary> |
| 67 | 63 | /// <param name="w"></param> |
| 68 | 64 | /// <param name="h"></param> |
| 69 | - public static void SetWindowSize(int w, int h) { if (!silentMode) { Console.SetWindowSize(w, h); } } | |
| 65 | + public static void SetWindowSize(int w, int h) { if (!SilentMode) { Console.SetWindowSize(w, h); } } | |
| 70 | 66 | |
| 71 | 67 | /// <summary> |
| 72 | 68 | /// Visszaadja a lenyomott billentyűt, ha van, commandmode-ban pedig az enter-t |
| ... | ... | @@ -74,7 +70,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
| 74 | 70 | /// <returns></returns> |
| 75 | 71 | public static ConsoleKeyInfo ReadKey() |
| 76 | 72 | { |
| 77 | - if (silentMode) { return GetConsoleKey(ConsoleKey.Enter); } | |
| 73 | + if (SilentMode) { return GetConsoleKey(ConsoleKey.Enter); } | |
| 78 | 74 | else { return Console.ReadKey(); } |
| 79 | 75 | } |
| 80 | 76 | |
| ... | ... | @@ -144,7 +140,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
| 144 | 140 | while (true) |
| 145 | 141 | { |
| 146 | 142 | string prompt = text; |
| 147 | - if (silentMode) | |
| 143 | + if (SilentMode) | |
| 148 | 144 | { |
| 149 | 145 | if (readlineList == null || readlineList.Length == 0) { return null; } |
| 150 | 146 | else |
| ... | ... | @@ -179,7 +175,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
| 179 | 175 | /// <param name="remembercursortop"></param> |
| 180 | 176 | public static void SetCursorPosition(int remembercursorleft, int remembercursortop) |
| 181 | 177 | { |
| 182 | - if (silentMode) { return; } | |
| 178 | + if (SilentMode) { return; } | |
| 183 | 179 | Console.SetCursorPosition(remembercursorleft, remembercursortop); |
| 184 | 180 | } |
| 185 | 181 | public static void SetCursorStartOfLine() { SetCursorPosition(0, ColorConsole.CursorTop); } |
| ... | ... | @@ -207,7 +203,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
| 207 | 203 | /// <param name="suffix"></param> |
| 208 | 204 | public static void WriteLine(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null,string prefix="", string suffix = "") |
| 209 | 205 | { |
| 210 | - if (silentMode) { return; } | |
| 206 | + if (SilentMode) { return; } | |
| 211 | 207 | Write(text, f, b, bracket,prefix,suffix); |
| 212 | 208 | Console.WriteLine(); |
| 213 | 209 | } |
| ... | ... | @@ -223,7 +219,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
| 223 | 219 | /// <param name="suffix"></param> |
| 224 | 220 | public static void Write(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null, string prefix = "",string suffix="") |
| 225 | 221 | { |
| 226 | - if (silentMode) { return; } | |
| 222 | + if (SilentMode) { return; } | |
| 227 | 223 | if (!string.IsNullOrEmpty(prefix)) { Write(prefix); } |
| 228 | 224 | if (!string.IsNullOrEmpty(bracket) && bracket.Length==1) { bracket = bracket + bracket; } |
| 229 | 225 | if (!string.IsNullOrEmpty(bracket)) { Console.Write($"{bracket[0]}"); } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Menu.cs
| ... | ... | @@ -219,12 +219,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole.MenuNS |
| 219 | 219 | /// </summary> |
| 220 | 220 | /// <param name="columns"></param> |
| 221 | 221 | /// <param name="columnlength"></param> |
| 222 | - public void DisplayItems(int columns = 1, int columnlength = 0) | |
| 222 | + public void DisplayItems(int columns = 1, int columnlength = 0,string listheader=null) | |
| 223 | 223 | { |
| 224 | 224 | if (Menu.IsCommandMode()) { return; } |
| 225 | 225 | |
| 226 | 226 | int columncounter = 0; |
| 227 | 227 | ColorConsole.WriteLine(); |
| 228 | + if (listheader != null) { ColorConsole.WriteLine(listheader); } | |
| 228 | 229 | var i = 1; |
| 229 | 230 | ColorConsole.SetCursorPosition(0, ColorConsole.CursorTop); |
| 230 | 231 | MenuItemIndentWidth = SetMenuItemHeaderWidth(MenuItemList, columns); | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs
| ... | ... | @@ -34,35 +34,142 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS |
| 34 | 34 | public static object Execute(object o1 = null, object o2 = null) |
| 35 | 35 | { |
| 36 | 36 | var args = (o1 as Menu.ExecutorParameter).Args; |
| 37 | + var config = new WindowsServiceManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); | |
| 38 | + var selectedserviceindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.WindowsServiceManager.Function.CMD_SERVICES); | |
| 37 | 39 | var functionkey = CommandLine.GetCommandLineArgument(args, CLP.CMD_FUNCTION); |
| 40 | + while (true) // servicegroup selection | |
| 41 | + { | |
| 42 | + List<WindowsServiceGroup> selectedServicegroups = null; | |
| 43 | + List<WindowsService> selectedServices = null; | |
| 44 | + string selectedFunctionkey = null; | |
| 38 | 45 | |
| 39 | - var config = new WindowsServiceManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); | |
| 40 | - var ep = new Menu.ExecutorParameter(config, args); | |
| 41 | - var menufunctions = new Menu("Manage Windows Services", "Select the management function!") | |
| 42 | - .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Register.KEY, "Register", Register,ep)) | |
| 43 | - .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Unregister.KEY, "Unregister", Unregister, ep)) | |
| 44 | - .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Start.KEY, "Start", Start, ep)) | |
| 45 | - .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Stop.KEY, "Stop", Stop, ep)) | |
| 46 | - .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Kill.KEY, "Kill", Kill, ep)) | |
| 47 | - .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Purge.KEY, "Purge", Purge, ep)) | |
| 48 | - .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.SetUserAccount.KEY, "Set user account", SetUserAccount, ep)) | |
| 49 | - .SetSelectionMode(Menu.SelectionMode.Single) | |
| 50 | - .SetMenuHeaderDisplayer(ServiceListDisplayer); | |
| 51 | - menufunctions.ExecuteMenu(functionkey); | |
| 46 | + if (!ColorConsole.SilentMode) | |
| 47 | + { | |
| 48 | + var menuservicegroups = DisplayWindowsServiceGroupMenu(config, $"Select the windows service group(s) to manage!"); | |
| 49 | + menuservicegroups.AddMenuItem(new Menu.ItemSeparator()); | |
| 50 | + menuservicegroups.AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Purge.KEY, "Purge")); | |
| 51 | + menuservicegroups.AddMenuItem(new Menu.ItemSeparator()); | |
| 52 | + | |
| 53 | + menuservicegroups.DisplayTitle(); | |
| 54 | + menuservicegroups.DisplayItems(1); | |
| 55 | + Menu.Selection srg = menuservicegroups.Select(selectedserviceindexes); | |
| 56 | + if (srg.Result == Menu.SelectionResult.Exit) { break; } | |
| 57 | + else if (srg.Result == Menu.SelectionResult.None) { break; } | |
| 58 | + else if (srg.Result == Menu.SelectionResult.Error) { break; } | |
| 59 | + else if (srg.Result == Menu.SelectionResult.Ok) { } | |
| 60 | + else { } | |
| 61 | + if (srg.SelectedKeyList.Contains(CLP.Module.WindowsServiceManager.Function.Purge.KEY) && srg.SelectedKeyList.Count()>1) { continue; } | |
| 62 | + if (srg.SelectedKeyList.Contains(CLP.Module.WindowsServiceManager.Function.Purge.KEY)) { Purge(); continue; } | |
| 63 | + selectedServicegroups = srg.SelectedParameterList.Select(p => (p.Parameters as WindowsServiceGroup)).ToList(); | |
| 64 | + } | |
| 65 | + | |
| 66 | + while (true) //service and function selection | |
| 67 | + { | |
| 68 | + var menuservices = DisplayWindowsServiceMenu(config, $"Select the windows service(es) to manage!", selectedServicegroups); | |
| 69 | + //menuservices.DisplayTitle(); | |
| 70 | + menuservices.DisplayItems(1, listheader: selectedServicegroups == null ? null : "Services for groups: " + string.Join(",", selectedServicegroups.Select(wsg => $"{wsg.Xml_Description} ({wsg.Xml_Key})"))); | |
| 71 | + Menu.Selection sr = menuservices.Select(selectedserviceindexes); | |
| 72 | + if (sr.Result == Menu.SelectionResult.Exit) { break; } | |
| 73 | + else if (sr.Result == Menu.SelectionResult.None) { break; } | |
| 74 | + else if (sr.Result == Menu.SelectionResult.Error) { break; } | |
| 75 | + else if (sr.Result == Menu.SelectionResult.Ok) { } | |
| 76 | + else { } | |
| 77 | + selectedServices = sr.SelectedParameterList.Select(p => (p.Parameters as WindowsService)).ToList(); | |
| 78 | + | |
| 79 | + var menufunctions = new Menu("Manage Windows Services", "Select the management function!") | |
| 80 | + .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Register.KEY, "Register")) | |
| 81 | + .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Unregister.KEY, "Unregister")) | |
| 82 | + .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Start.KEY, "Start")) | |
| 83 | + .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Stop.KEY, "Stop")) | |
| 84 | + .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Kill.KEY, "Kill")) | |
| 85 | + .AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.SetUserAccount.KEY, "Set user account")) | |
| 86 | + .SetSelectionMode(Menu.SelectionMode.Single) | |
| 87 | + ; | |
| 88 | + //menufunctions.DisplayTitle(); | |
| 89 | + menufunctions.DisplayItems(1); | |
| 90 | + Menu.Selection srf = menufunctions.Select(functionkey); | |
| 91 | + if (srf.Result == Menu.SelectionResult.Exit) { break; } | |
| 92 | + else if (srf.Result == Menu.SelectionResult.None) { break; } | |
| 93 | + else if (srf.Result == Menu.SelectionResult.Error) { break; } | |
| 94 | + else if (srf.Result == Menu.SelectionResult.Ok) { } | |
| 95 | + else { } | |
| 96 | + selectedFunctionkey = srf.SelectedKeyList.First(); | |
| 97 | + | |
| 98 | + switch (selectedFunctionkey) | |
| 99 | + { | |
| 100 | + case CLP.Module.WindowsServiceManager.Function.Register.KEY: | |
| 101 | + foreach (var ws in selectedServices) | |
| 102 | + { | |
| 103 | + try | |
| 104 | + { | |
| 105 | + var success = WindowsServiceManagerCore.Register(ws, selectedServices.Select(x => x.Name).ToList()); | |
| 106 | + ColorConsole.WriteLine($"Service registered. Name:{ws.Name}", ConsoleColor.Green); | |
| 107 | + } | |
| 108 | + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
| 109 | + } | |
| 110 | + break; | |
| 111 | + case CLP.Module.WindowsServiceManager.Function.Unregister.KEY: | |
| 112 | + foreach (var ws in selectedServices) | |
| 113 | + { | |
| 114 | + try | |
| 115 | + { | |
| 116 | + var success = WindowsServiceManagerCore.Unregister(ws); | |
| 117 | + ColorConsole.WriteLine($"Service unregistered. Name:{ws.Name}", ConsoleColor.Green); | |
| 118 | + } | |
| 119 | + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
| 120 | + } | |
| 121 | + break; | |
| 122 | + case CLP.Module.WindowsServiceManager.Function.Start.KEY: | |
| 123 | + foreach (var ws in selectedServices) | |
| 124 | + { | |
| 125 | + try | |
| 126 | + { | |
| 127 | + var success = WindowsServiceManagerCore.Start(ws.Name, ws.Xml_StartTimeout); | |
| 128 | + ColorConsole.WriteLine($"Service started. Name:{ws.Name}", ConsoleColor.Green); | |
| 129 | + } | |
| 130 | + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
| 131 | + } | |
| 132 | + break; | |
| 133 | + case CLP.Module.WindowsServiceManager.Function.Stop.KEY: | |
| 134 | + foreach (var ws in selectedServices) | |
| 135 | + { | |
| 136 | + try | |
| 137 | + { | |
| 138 | + var success = WindowsServiceManagerCore.Stop(ws.Name, ws.Xml_StopTimeout); | |
| 139 | + ColorConsole.WriteLine($"Service stopped. Name:{ws.Name}", ConsoleColor.Green); | |
| 140 | + } | |
| 141 | + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
| 142 | + } | |
| 143 | + break; | |
| 144 | + case CLP.Module.WindowsServiceManager.Function.Kill.KEY: | |
| 145 | + foreach (var ws in selectedServices) | |
| 146 | + { | |
| 147 | + try | |
| 148 | + { | |
| 149 | + var success = WindowsServiceManagerCore.Kill(ws.Name); | |
| 150 | + ColorConsole.WriteLine($"Service killed. Name:{ws.Name}", ConsoleColor.Green); | |
| 151 | + } | |
| 152 | + catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
| 153 | + } | |
| 154 | + break; | |
| 155 | + case CLP.Module.WindowsServiceManager.Function.SetUserAccount.KEY: SetUserAccount(config, selectedserviceindexes); break; | |
| 156 | + case CLP.Module.WindowsServiceManager.Function.Purge.KEY: Purge(); break; | |
| 157 | + } | |
| 158 | + } | |
| 159 | + } | |
| 52 | 160 | return null; |
| 53 | 161 | } |
| 54 | 162 | #endregion Execute |
| 55 | 163 | |
| 56 | 164 | #region First level Executors with UI |
| 57 | - private static object Purge(object parameter, object o) | |
| 165 | + private static void Purge() | |
| 58 | 166 | { |
| 59 | - var config = (parameter as Menu.ExecutorParameter).GetConfig<WindowsServiceManagerXmlProcessor>(); | |
| 60 | 167 | while (true) |
| 61 | 168 | { |
| 62 | 169 | ColorConsole.WriteLine($"Enter servicename mask to select from the result list (% and ? are wildchars)...", ConsoleColor.Yellow); |
| 63 | 170 | ColorConsole.WriteLine($"...or enter service name directly (put an asterisk (*) before the name).", ConsoleColor.Yellow); |
| 64 | 171 | var mask = ColorConsole.ReadLine($" ---> ", ConsoleColor.Yellow).ToUpper(); |
| 65 | - if (mask == "EX") { return o; } | |
| 172 | + if (mask == "EX") { return; } | |
| 66 | 173 | else if (mask == "") { continue; } |
| 67 | 174 | |
| 68 | 175 | if (mask.StartsWith("*") && mask.Length>=2) { DeleteOneService(mask.Substring(1)); } |
| ... | ... | @@ -86,12 +193,12 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS |
| 86 | 193 | { |
| 87 | 194 | foreach (var p in ms.SelectedParameterList) |
| 88 | 195 | { |
| 89 | - if (DeleteOneService((string)(p.Parameters))) { return o; } | |
| 196 | + if (DeleteOneService((string)(p.Parameters))) { return; } | |
| 90 | 197 | } |
| 91 | 198 | } |
| 92 | 199 | } |
| 93 | 200 | } |
| 94 | - return o; | |
| 201 | + return; | |
| 95 | 202 | } |
| 96 | 203 | private static bool DeleteOneService(string servicename) |
| 97 | 204 | { |
| ... | ... | @@ -111,150 +218,14 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS |
| 111 | 218 | } |
| 112 | 219 | return false; |
| 113 | 220 | } |
| 114 | - private static object Kill(object parameter, object o) | |
| 115 | - { | |
| 116 | - var config = (parameter as Menu.ExecutorParameter).GetConfig<WindowsServiceManagerXmlProcessor>(); | |
| 117 | - var args = (parameter as Menu.ExecutorParameter).Args; | |
| 118 | - | |
| 119 | - var selectedserviceindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.WindowsServiceManager.Function.CMD_SERVICES); | |
| 120 | - | |
| 121 | - var menuservices = DisplayWindowsServiceMenu(config, $"Select the windows service(es) to manage with function '{nameof(Kill)}'!", silent: true); | |
| 122 | - | |
| 123 | - Menu.Selection sr = menuservices.Select(selectedserviceindexes); | |
| 124 | - if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
| 125 | - else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
| 126 | - else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
| 127 | - else if (sr.Result == Menu.SelectionResult.Ok) { } | |
| 128 | - else { } | |
| 129 | - foreach (var p in sr.SelectedParameterList) | |
| 130 | - { | |
| 131 | - WindowsService ws = p.Parameters as WindowsService; | |
| 132 | - try | |
| 133 | - { | |
| 134 | - var success = WindowsServiceManagerCore.Kill(ws.Name); | |
| 135 | - ColorConsole.WriteLine($"Service killed. Name:{ws.Name}", ConsoleColor.Green); | |
| 136 | - } | |
| 137 | - catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
| 138 | - } | |
| 139 | - return o; | |
| 140 | - } | |
| 141 | - private static object Register(object parameter, object o) | |
| 142 | - { | |
| 143 | - var config = (parameter as Menu.ExecutorParameter).GetConfig<WindowsServiceManagerXmlProcessor>(); | |
| 144 | - var args = (parameter as Menu.ExecutorParameter).Args; | |
| 145 | - | |
| 146 | - var selectedserviceindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.WindowsServiceManager.Function.CMD_SERVICES); | |
| 147 | - | |
| 148 | - var menuservices = DisplayWindowsServiceMenu(config, $"Select the windows service(es) to manage with function '{nameof(Register)}'!", silent: true); | |
| 149 | - | |
| 150 | - Menu.Selection sr = menuservices.Select(selectedserviceindexes); | |
| 151 | - if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
| 152 | - else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
| 153 | - else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
| 154 | - else if (sr.Result == Menu.SelectionResult.Ok) { } | |
| 155 | - else { } | |
| 156 | - foreach (var p in sr.SelectedParameterList) | |
| 157 | - { | |
| 158 | - WindowsService ws = p.Parameters as WindowsService; | |
| 159 | - try | |
| 160 | - { | |
| 161 | - var success = WindowsServiceManagerCore.Register(ws, sr.SelectedParameterList.Select(x => (x.Parameters as WindowsService).Name).ToList()); | |
| 162 | - ColorConsole.WriteLine($"Service registered. Name:{ws.Name}", ConsoleColor.Green); | |
| 163 | - } | |
| 164 | - catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
| 165 | - } | |
| 166 | - return o; | |
| 167 | - } | |
| 168 | - private static object Unregister(object parameter, object o) | |
| 169 | - { | |
| 170 | - var config = (parameter as Menu.ExecutorParameter).GetConfig<WindowsServiceManagerXmlProcessor>(); | |
| 171 | - var args = (parameter as Menu.ExecutorParameter).Args; | |
| 172 | - var selectedserviceindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.WindowsServiceManager.Function.CMD_SERVICES); | |
| 173 | - | |
| 174 | - var menuservices = DisplayWindowsServiceMenu(config, $"Select the windows service(es) to manage with function '{nameof(Unregister)}'!", silent: true); | |
| 175 | - | |
| 176 | - Menu.Selection sr = menuservices.Select(selectedserviceindexes); | |
| 177 | - if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
| 178 | - else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
| 179 | - else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
| 180 | - else if (sr.Result == Menu.SelectionResult.Ok) { } | |
| 181 | - else { } | |
| 182 | - foreach (var p in sr.SelectedParameterList) | |
| 183 | - { | |
| 184 | - WindowsService ws = p.Parameters as WindowsService; | |
| 185 | - try | |
| 186 | - { | |
| 187 | - var success = WindowsServiceManagerCore.Unregister(ws); | |
| 188 | - ColorConsole.WriteLine($"Service unregistered. Name:{ws.Name}", ConsoleColor.Green); | |
| 189 | - } | |
| 190 | - catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
| 191 | - } | |
| 192 | - return o; | |
| 193 | - } | |
| 194 | - private static object Start(object parameter, object o) | |
| 195 | - { | |
| 196 | - var config = (parameter as Menu.ExecutorParameter).GetConfig<WindowsServiceManagerXmlProcessor>(); | |
| 197 | - var args = (parameter as Menu.ExecutorParameter).Args; | |
| 198 | - var selectedserviceindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.WindowsServiceManager.Function.CMD_SERVICES); | |
| 199 | - | |
| 200 | - var menuservices = DisplayWindowsServiceMenu(config, $"Select the windows service(es) to manage with function '{nameof(Start)}'!", silent: true); | |
| 201 | - | |
| 202 | - Menu.Selection sr = menuservices.Select(selectedserviceindexes); | |
| 203 | - if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
| 204 | - else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
| 205 | - else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
| 206 | - else if (sr.Result == Menu.SelectionResult.Ok) { } | |
| 207 | - else { } | |
| 208 | - foreach (var p in sr.SelectedParameterList) | |
| 209 | - { | |
| 210 | - WindowsService ws = p.Parameters as WindowsService; | |
| 211 | - try | |
| 212 | - { | |
| 213 | - var success = WindowsServiceManagerCore.Start(ws.Name, ws.Xml_StartTimeout); | |
| 214 | - ColorConsole.WriteLine($"Service started. Name:{ws.Name}", ConsoleColor.Green); | |
| 215 | - } | |
| 216 | - catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
| 217 | - } | |
| 218 | - return o; | |
| 219 | - } | |
| 220 | - private static object Stop(object parameter, object o) | |
| 221 | - { | |
| 222 | - var config = (parameter as Menu.ExecutorParameter).GetConfig<WindowsServiceManagerXmlProcessor>(); | |
| 223 | - var args = (parameter as Menu.ExecutorParameter).Args; | |
| 224 | - var selectedserviceindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.WindowsServiceManager.Function.CMD_SERVICES); | |
| 225 | - | |
| 226 | - var menuservices = DisplayWindowsServiceMenu(config, $"Select the windows service(es) to manage with function '{nameof(Stop)}'!", silent: true); | |
| 227 | - | |
| 228 | - Menu.Selection sr = menuservices.Select(selectedserviceindexes); | |
| 229 | - if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
| 230 | - else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
| 231 | - else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
| 232 | - else if (sr.Result == Menu.SelectionResult.Ok) { } | |
| 233 | - else { } | |
| 234 | - foreach (var p in sr.SelectedParameterList) | |
| 235 | - { | |
| 236 | - WindowsService ws = p.Parameters as WindowsService; | |
| 237 | - try | |
| 238 | - { | |
| 239 | - var success = WindowsServiceManagerCore.Stop(ws.Name, ws.Xml_StopTimeout); | |
| 240 | - ColorConsole.WriteLine($"Service stopped. Name:{ws.Name}", ConsoleColor.Green); | |
| 241 | - } | |
| 242 | - catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } | |
| 243 | - } | |
| 244 | - return o; | |
| 245 | - } | |
| 246 | - private static object SetUserAccount(object parameter, object o) | |
| 221 | + private static void SetUserAccount(WindowsServiceManagerXmlProcessor config, string selectedserviceindexes) | |
| 247 | 222 | { |
| 248 | - var config = (parameter as Menu.ExecutorParameter).GetConfig<WindowsServiceManagerXmlProcessor>(); | |
| 249 | - var args = (parameter as Menu.ExecutorParameter).Args; | |
| 250 | - var selectedserviceindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.WindowsServiceManager.Function.CMD_SERVICES); | |
| 251 | - | |
| 252 | - var menuservices = DisplayWindowsServiceMenu(config, $"Select the windows service(es) to manage with function '{nameof(SetUserAccount)}'!", silent: true); | |
| 223 | + var menuservices = DisplayWindowsServiceMenu(config, $"Select the windows service(es) to manage with function '{nameof(SetUserAccount)}'!"); | |
| 253 | 224 | |
| 254 | 225 | Menu.Selection sr = menuservices.Select(selectedserviceindexes); |
| 255 | - if (sr.Result == Menu.SelectionResult.Exit) { return o; } | |
| 256 | - else if (sr.Result == Menu.SelectionResult.None) { return o; } | |
| 257 | - else if (sr.Result == Menu.SelectionResult.Error) { return o; } | |
| 226 | + if (sr.Result == Menu.SelectionResult.Exit) { return; } | |
| 227 | + else if (sr.Result == Menu.SelectionResult.None) { return; } | |
| 228 | + else if (sr.Result == Menu.SelectionResult.Error) { return; } | |
| 258 | 229 | else if (sr.Result == Menu.SelectionResult.Ok) { } |
| 259 | 230 | else { } |
| 260 | 231 | |
| ... | ... | @@ -269,7 +240,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS |
| 269 | 240 | if (username == null) |
| 270 | 241 | { |
| 271 | 242 | GetUsernameAndPassword(wmiService,ws,out username, out password); |
| 272 | - if (username == "EX" || password == "EX") { return null; } | |
| 243 | + if (username == "EX" || password == "EX") { return; } | |
| 273 | 244 | } |
| 274 | 245 | if (WindowsServiceManagerCore.SetUserAccount(wmiService, username, password)) { ColorConsole.WriteLine($"Service user account changed. Name:{ws.Name}", ConsoleColor.Green); } |
| 275 | 246 | else { ColorConsole.WriteLine($"Service user account change FAILED! Name:{ws.Name}", ConsoleColor.Red); } |
| ... | ... | @@ -277,36 +248,46 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS |
| 277 | 248 | } |
| 278 | 249 | catch (Exception ex) { ColorConsole.WriteLine(ex.Message, ConsoleColor.Red); } |
| 279 | 250 | } |
| 280 | - return o; | |
| 251 | + return; | |
| 281 | 252 | } |
| 282 | 253 | #endregion First level Executors with UI |
| 283 | 254 | |
| 284 | 255 | #region DisplayServices |
| 285 | 256 | private static void ServiceListDisplayer() { DisplayWindowsServiceMenu(); } |
| 286 | - public static Menu DisplayWindowsServiceMenu(WindowsServiceManagerXmlProcessor config=null,string prompt = null,bool silent=false) | |
| 257 | + public static Menu DisplayWindowsServiceMenu(WindowsServiceManagerXmlProcessor config=null,string prompt = null,List<WindowsServiceGroup> servicegroups=null) | |
| 287 | 258 | { |
| 288 | 259 | if (config==null) { config = new WindowsServiceManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); } |
| 289 | 260 | var menuservices = new Menu("Windows services",prompt) |
| 290 | 261 | .SetMenuItemDisplayer(DisplayServiceInfo) |
| 291 | - .SetSelectionMode(Menu.SelectionMode.Multi); | |
| 262 | + .SetSelectionMode(Menu.SelectionMode.Multi) | |
| 263 | + .SetMenuHeaderDisplayer(ServiceListDisplayer) | |
| 264 | + ; | |
| 292 | 265 | menuservices.ClearMenuItemList(); |
| 293 | 266 | |
| 294 | - List<WindowsServiceGroup> wsgdefList = config.GetWindowsServiceGroupDefinitionList(); | |
| 295 | - foreach (var wsgdef in wsgdefList) | |
| 296 | - { | |
| 297 | - string menuitemtext = wsgdef.Xml_Description + "(" + string.Join(",", wsgdef.Xml_WindowsServiceKeyList) + ")"; | |
| 298 | - menuservices.AddMenuItem(new Menu.ItemGroup(wsgdef.Xml_Key, menuitemtext, wsgdef.Xml_WindowsServiceKeyList)); | |
| 299 | - } | |
| 300 | - | |
| 301 | - menuservices.AddMenuItem(new Menu.ItemSeparator());// separator | |
| 302 | - | |
| 303 | - List<WindowsService> wsdefList = config.GetWindowsServiceDefinitionList(); | |
| 267 | + List<WindowsService> wsdefList = config.GetWindowsServiceDefinitionList(servicegroups); | |
| 304 | 268 | foreach (var wsdef in wsdefList) |
| 305 | 269 | { |
| 306 | 270 | menuservices.AddMenuItem(new Menu.Item(wsdef.Xml_Key, null, null, new Menu.ExecutorParameter(pars: wsdef.CollectWindowsServiceInfo()))); |
| 307 | - } | |
| 271 | + } | |
| 272 | + return menuservices; | |
| 273 | + } | |
| 274 | + public static Menu DisplayWindowsServiceGroupMenu(WindowsServiceManagerXmlProcessor config = null, string prompt = null) | |
| 275 | + { | |
| 276 | + if (config == null) { config = new WindowsServiceManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); } | |
| 277 | + var menuservices = new Menu("Windows services", prompt) | |
| 278 | + .SetMenuItemDisplayer(DisplayServiceInfo) | |
| 279 | + .SetSelectionMode(Menu.SelectionMode.Single) | |
| 280 | + .SetMenuHeaderDisplayer(ServiceListDisplayer) | |
| 281 | + ; | |
| 282 | + menuservices.ClearMenuItemList(); | |
| 308 | 283 | |
| 309 | - if (!silent) { menuservices.DisplayItems(1); } | |
| 284 | + List<WindowsServiceGroup> wsgdefList = config.GetWindowsServiceGroupDefinitionList(); | |
| 285 | + foreach (var wsgdef in wsgdefList) | |
| 286 | + { | |
| 287 | + //string menuitemtext = wsgdef.Xml_Description + "(" + string.Join(",", wsgdef.Xml_WindowsServiceKeyList) + ")"; | |
| 288 | + string menuitemtext = wsgdef.Xml_Description; | |
| 289 | + menuservices.AddMenuItem(new Menu.Item(wsgdef.Xml_Key, menuitemtext, null, new Menu.ExecutorParameter(pars: wsgdef))); | |
| 290 | + } | |
| 310 | 291 | return menuservices; |
| 311 | 292 | } |
| 312 | 293 | #endregion DisplayServices |
| ... | ... | @@ -320,7 +301,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS |
| 320 | 301 | if (lineix == 0) |
| 321 | 302 | { |
| 322 | 303 | ColorConsole.Write($"{ws.Description}", ConsoleColor.Black, ConsoleColor.White); |
| 323 | - ColorConsole.WriteLine($"{ws.DisplayName}", bracket: "()"); | |
| 304 | + ColorConsole.Write($"{ws.DisplayName}", bracket: "()"); | |
| 305 | + ColorConsole.Write($", User:"); | |
| 306 | + ColorConsole.Write($"{ws.StartName}", ConsoleColor.White); | |
| 307 | + ColorConsole.WriteLine(); | |
| 324 | 308 | return ws.DisplayName+ws.Description; |
| 325 | 309 | } |
| 326 | 310 | else if (lineix == 1) |
| ... | ... | @@ -374,12 +358,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS |
| 374 | 358 | } |
| 375 | 359 | else if (lineix == 4) |
| 376 | 360 | { |
| 377 | - ColorConsole.Write($"User:"); | |
| 378 | - ColorConsole.WriteLine($"{ws.StartName}", ConsoleColor.White); | |
| 379 | - return ws.StartName; | |
| 380 | - } | |
| 381 | - else if (lineix == 5) | |
| 382 | - { | |
| 383 | 361 | ColorConsole.WriteLine(); |
| 384 | 362 | return " "; |
| 385 | 363 | } |
| ... | ... | @@ -728,11 +706,31 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS |
| 728 | 706 | #region GetWindowsServiceGroupDefinitionList |
| 729 | 707 | public WindowsServiceGroup GetWindowsServiceGroup(string key) { return _winservicegrouplist.FirstOrDefault(x => x.Xml_Key == key); } |
| 730 | 708 | public List<WindowsServiceGroup> GetWindowsServiceGroupDefinitionList() { return _winservicegrouplist; } |
| 709 | + | |
| 710 | + | |
| 711 | + public List<string> GetGroupWindowsServiceKeyList(string groupkey,out string groupdescription) | |
| 712 | + { | |
| 713 | + groupdescription = null; | |
| 714 | + List<WindowsServiceGroup> wsgdefList = GetWindowsServiceGroupDefinitionList().Where(sgr => sgr.Xml_Key == groupkey || groupkey == null).ToList(); | |
| 715 | + if (groupkey != null && wsgdefList != null && wsgdefList.Any()) { groupdescription = wsgdefList.First().Xml_Description; } | |
| 716 | + List<string> allwskeys = new List<string>(); | |
| 717 | + foreach (var wsg in wsgdefList) { allwskeys = allwskeys.Concat(wsg.Xml_WindowsServiceKeyList).ToList(); } | |
| 718 | + return allwskeys; | |
| 719 | + } | |
| 731 | 720 | #endregion GetWindowsServiceGroupDefinitionList |
| 732 | 721 | |
| 733 | 722 | #region GetWindowsServiceDefinitionList |
| 734 | 723 | public WindowsService GetWindowsService(string key) { return _winservicelist.FirstOrDefault(x => x.Xml_Key == key); } |
| 735 | - public List<WindowsService> GetWindowsServiceDefinitionList() { return _winservicelist; } | |
| 724 | + public List<WindowsService> GetWindowsServiceDefinitionList(List<WindowsServiceGroup> wsgList=null) | |
| 725 | + { | |
| 726 | + if (wsgList == null) { return _winservicelist; } | |
| 727 | + else | |
| 728 | + { | |
| 729 | + var wsList = new List<WindowsService>(); | |
| 730 | + foreach (var wsg in wsgList) { wsList = wsList.Concat(wsg.Xml_WindowsServiceKeyList.Select(k=> _winservicelist.FirstOrDefault(ws=>ws.Xml_Key==k))).Where(ws=>ws!=null).ToList(); } | |
| 731 | + return wsList; | |
| 732 | + } | |
| 733 | + } | |
| 736 | 734 | public List<WindowsService> GetWindowsServiceDefinitionListInStartOrder() { return _winservicelistinstartorder; } |
| 737 | 735 | public List<WindowsService> GetWindowsServiceDefinitionListInStopOrder() { return _winservicelistinstoporder; } |
| 738 | 736 | private List<WindowsService> ProduceWindowsServiceDefinitionListInStartOrder() | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Program.cs
| ... | ... | @@ -70,7 +70,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole |
| 70 | 70 | var forcedmodulekey = CommandLine.GetCommandLineArgument(args, CLP.CMD_MODULE); |
| 71 | 71 | var commandmode = !string.IsNullOrEmpty(forcedmodulekey); |
| 72 | 72 | var silentmode = commandmode && !string.IsNullOrEmpty(CommandLine.GetCommandLineArgument(args, CLP.CMD_SILENT, switchtype: true)); |
| 73 | - ColorConsole.SetSilentMode(silentmode); | |
| 73 | + ColorConsole.SilentMode=silentmode; | |
| 74 | 74 | Menu.SetCommandMode(commandmode); |
| 75 | 75 | |
| 76 | 76 | var appconfigpath = CommandLine.GetCommandLineArgument(args, CLP.CMD_APPCONFIG); | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
| ... | ... | @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; |
| 32 | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
| 33 | 33 | // by using the '*' as shown below: |
| 34 | 34 | // [assembly: AssemblyVersion("1.0.*")] |
| 35 | -[assembly: AssemblyVersion("1.8.4.0")] | |
| 36 | -[assembly: AssemblyFileVersion("1.8.4.0")] | |
| 35 | +[assembly: AssemblyVersion("1.8.5.0")] | |
| 36 | +[assembly: AssemblyFileVersion("1.8.5.0")] | ... | ... |