From 0e407387b06660cc1372ad0ddb31e0c22b603522 Mon Sep 17 00:00:00 2001 From: Schwirg László Date: Mon, 25 Apr 2022 12:49:27 +0200 Subject: [PATCH] - KeyGroupList általánosítása folyamatban --- Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs | 58 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs index e160e65..1d2b620 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs @@ -46,9 +46,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS if (!ColorConsole.SilentMode) { - var menuservicegroups = DisplayWindowsServiceGroupMenu(config, $"Select the windows service group(s) to manage!"); - if (menuservicegroups == null) { selectedServicegroups = null; if (exitwasrequested) { break; } } + KeyGroupList wsgdefList = KeyGroupList.Factory(config.GetRootElement()); + if (wsgdefList == null) { selectedServicegroups = null; if (exitwasrequested) { break; } } else { + var menuservicegroups = wsgdefList.DisplayKeyGroupMenu(DisplayServiceInfo, ServiceListDisplayer, "Windows services", $"Select the windows service group(s) to manage!"); menuservicegroups.AddMenuItem(new Menu.ItemSeparator()); menuservicegroups.AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Purge.KEY, "Purge")); menuservicegroups.AddMenuItem(new Menu.ItemSeparator()); @@ -276,26 +277,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS } return menuservices; } - public static Menu DisplayWindowsServiceGroupMenu(WindowsServiceManagerXmlProcessor config = null, string prompt = null) - { - if (config == null) { config = new WindowsServiceManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); } - var menuservices = new Menu("Windows services", prompt) - .SetMenuItemDisplayer(DisplayServiceInfo) - .SetSelectionMode(Menu.SelectionMode.Single) - .SetMenuHeaderDisplayer(ServiceListDisplayer) - ; - menuservices.ClearMenuItemList(); - - KeyGroupList wsgdefList = config.WinServiceKeyGroupList; - if (wsgdefList == null || !wsgdefList.Any()) return null; - foreach (var wsgdef in wsgdefList) - { - //string menuitemtext = wsgdef.Xml_Description + "(" + string.Join(",", wsgdef.Xml_WindowsServiceKeyList) + ")"; - string menuitemtext = wsgdef.Xml_Description; - menuservices.AddMenuItem(new Menu.Item(wsgdef.Xml_Key, menuitemtext, null, new Menu.ExecutorParameter(pars: wsgdef))); - } - return menuservices; - } #endregion DisplayServices #region private method: DisplayServiceInfo @@ -688,7 +669,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS List _winservicelist; List _winservicelistinstartorder; List _winservicelistinstoporder; - public KeyGroupList WinServiceKeyGroupList; #region constructor public WindowsServiceManagerXmlProcessor(string xmlcs, string basefolder, string lcid) : base(xmlcs, basefolder, lcid, null) { @@ -701,7 +681,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS _winservicelistinstartorder = ProduceWindowsServiceDefinitionListInStartOrder(); _winservicelistinstoporder = ProduceWindowsServiceDefinitionListInStartOrder(); _winservicelistinstoporder.Reverse(); - WinServiceKeyGroupList = new KeyGroupList(this.RootElement); } #endregion constructor @@ -1058,16 +1037,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS } public static KeyGroupList Factory(XElement keygrouplistcontainer) { - return new KeyGroupList(keygrouplistcontainer); - } - public KeyGroupList(XElement keygrouplistcontainer) - { var wsgxmllist = keygrouplistcontainer.Elements(XName.Get(nameof(KeyGroup.XmlStructure.KeyGroup))); - if (wsgxmllist != null && wsgxmllist.Any()) - { - foreach (var wsgxml in wsgxmllist) { var wsg = new KeyGroup(wsgxml); if (wsg.Valid) { this.Add(wsg); } } - } + if (wsgxmllist == null || !wsgxmllist.Any()) return null; + var kgl = new KeyGroupList(); + foreach (var wsgxml in wsgxmllist) { var wsg = new KeyGroup(wsgxml); if (wsg.Valid) { kgl.Add(wsg); } } + return kgl; } + public KeyGroupList() { } public KeyGroupList(List keygrouplist) { foreach (var kg in keygrouplist) { this.Add(kg); } @@ -1083,6 +1059,24 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS foreach (var wsg in wsgdefList) { allwskeys = allwskeys.Concat(wsg.Xml_KeyList).ToList(); } return allwskeys; } + public Menu DisplayKeyGroupMenu(Menu.MenuItemDisplayerFunc menuitemdisplayer, Menu.MenuHeaderDisplayerFunc menuheaderdisplayer, string title, string prompt = null) + { + var menuservices = new Menu(title, prompt) + .SetMenuItemDisplayer(menuitemdisplayer) + .SetSelectionMode(Menu.SelectionMode.Single) + .SetMenuHeaderDisplayer(menuheaderdisplayer) + ; + menuservices.ClearMenuItemList(); + + if (!this.Any()) return null; + foreach (var wsgdef in this) + { + //string menuitemtext = wsgdef.Xml_Description + "(" + string.Join(",", wsgdef.Xml_KeyList) + ")"; + string menuitemtext = wsgdef.Xml_Description; + menuservices.AddMenuItem(new Menu.Item(wsgdef.Xml_Key, menuitemtext, null, new Menu.ExecutorParameter(pars: wsgdef))); + } + return menuservices; + } } #endregion KeyGroupList class } -- libgit2 0.21.2