Commit e4527b2901ea63d4defe1a89f85d628a05e5c448

Authored by Schwirg László
1 parent f0aff75d

v1.11.4

- KeyGroupList osztály bevezetése a WindowsServicegroup helyett
- folyamatban: a menuelemek csoportosítása (KeyGroup xml elem) és a csoportokból való előválasztást biztosító mechanizmus beépítése a menükezelőbe
Vrh.Log4Pro.MaintenanceConsole/Manager - FileCleanerManager.cs
... ... @@ -184,18 +184,27 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS
184 184 #region class FileCleanerManagerCore
185 185 public static class FileCleanerManagerCore
186 186 {
  187 + #region IsDirectoryEmpty
  188 + public static bool IsDirectoryEmpty(DirectoryInfo d)
  189 + {
  190 + FileInfo[] fis = d.GetFiles("*", SearchOption.TopDirectoryOnly);
  191 + DirectoryInfo[] dis = d.GetDirectories();
  192 + return (fis == null || !fis.Any()) && (dis == null || !dis.Any());
  193 + }
  194 + #endregion IsDirectoryEmpty
  195 +
187 196 #region public GetDirSize
188 197 public static long DirSize(DirectoryInfo d, string filenamemask, string filefullpathregex, bool recurse)
189 198 {
190 199 long size = 0;
191 200 // Add file sizes.
192 201 FileInfo[] fis = d.GetFiles(filenamemask, SearchOption.TopDirectoryOnly);
193   - foreach (FileInfo fi in fis) { if (Regex.Match(fi.FullName, filefullpathregex).Success) { size += fi.Length; } }
  202 + if (fis != null) { foreach (FileInfo fi in fis) { if (Regex.Match(fi.FullName, filefullpathregex).Success) { size += fi.Length; } } }
194 203 // Add subdirectory sizes.
195 204 if (recurse)
196 205 {
197 206 DirectoryInfo[] dis = d.GetDirectories();
198   - foreach (DirectoryInfo di in dis) { size += DirSize(di, filenamemask, filefullpathregex, recurse); }
  207 + if (dis != null) { foreach (DirectoryInfo di in dis) { size += DirSize(di, filenamemask, filefullpathregex, recurse); } }
199 208 }
200 209 return size;
201 210 }
... ... @@ -288,7 +297,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.FileCleanerManagerNS
288 297 {
289 298 foreach (DirectoryInfo di in d.GetDirectories()) { cleanedsize += CleanFolderFiles(di, ftc, delete); }
290 299 }
291   - if (ftc.Xml_RemoveEmptyFolder && DirSize(d, ftc.Xml_IncludeMask, ftc.Xml_IncludeFullpathRegexp, ftc.Xml_Recurse) == 0)
  300 + if (ftc.Xml_RemoveEmptyFolder && IsDirectoryEmpty(d))
292 301 {
293 302 try { Directory.Delete(d.FullName, ftc.Xml_Recurse); } catch { }
294 303 }
... ...
Vrh.Log4Pro.MaintenanceConsole/Manager - WindowsServiceManager.cs
... ... @@ -37,39 +37,44 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS
37 37 var config = new WindowsServiceManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU");
38 38 var selectedserviceindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.WindowsServiceManager.Function.CMD_SERVICES);
39 39 var functionkey = CommandLine.GetCommandLineArgument(args, CLP.CMD_FUNCTION);
  40 + bool exitwasrequested = false;
40 41 while (true) // servicegroup selection
41 42 {
42   - List<WindowsServiceGroup> selectedServicegroups = null;
  43 + KeyGroupList selectedServicegroups = null;
43 44 List<WindowsService> selectedServices = null;
44 45 string selectedFunctionkey = null;
45 46  
46 47 if (!ColorConsole.SilentMode)
47 48 {
48 49 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());
  50 + if (menuservicegroups == null) { selectedServicegroups = null; if (exitwasrequested) { break; } }
  51 + else {
  52 + menuservicegroups.AddMenuItem(new Menu.ItemSeparator());
  53 + menuservicegroups.AddMenuItem(new Menu.Item(CLP.Module.WindowsServiceManager.Function.Purge.KEY, "Purge"));
  54 + menuservicegroups.AddMenuItem(new Menu.ItemSeparator());
52 55  
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();
  56 + menuservicegroups.DisplayTitle();
  57 + menuservicegroups.DisplayItems(1);
  58 + Menu.Selection srg = menuservicegroups.Select(selectedserviceindexes);
  59 + if (srg.Result == Menu.SelectionResult.Exit) { break; }
  60 + else if (srg.Result == Menu.SelectionResult.None) { break; }
  61 + else if (srg.Result == Menu.SelectionResult.Error) { break; }
  62 + else if (srg.Result == Menu.SelectionResult.Ok) { }
  63 + else { }
  64 + if (srg.SelectedKeyList.Contains(CLP.Module.WindowsServiceManager.Function.Purge.KEY) && srg.SelectedKeyList.Count() > 1) { continue; }
  65 + if (srg.SelectedKeyList.Contains(CLP.Module.WindowsServiceManager.Function.Purge.KEY)) { Purge(); continue; }
  66 + var _selectedServicegroups = srg.SelectedParameterList.Select(p => (p.Parameters as KeyGroupList.KeyGroup)).ToList();
  67 + selectedServicegroups = new KeyGroupList(_selectedServicegroups);
  68 + }
64 69 }
65 70  
66 71 while (true) //service and function selection
67 72 {
68 73 var menuservices = DisplayWindowsServiceMenu(config, $"Select the windows service(es) to manage!", selectedServicegroups);
69 74 //menuservices.DisplayTitle();
70   - menuservices.DisplayItems(1, listheader: selectedServicegroups == null ? null : "Services for groups: " + string.Join(",", selectedServicegroups.Select(wsg => $"{wsg.Xml_Description} ({wsg.Xml_Key})")));
  75 + menuservices.DisplayItems(1, listheader: selectedServicegroups == null ? null : "Services for groups: " + string.Join(",", selectedServicegroups.GetOneLineInfoList()));
71 76 Menu.Selection sr = menuservices.Select(selectedserviceindexes);
72   - if (sr.Result == Menu.SelectionResult.Exit) { break; }
  77 + if (sr.Result == Menu.SelectionResult.Exit) { exitwasrequested = true; break; }
73 78 else if (sr.Result == Menu.SelectionResult.None) { break; }
74 79 else if (sr.Result == Menu.SelectionResult.Error) { break; }
75 80 else if (sr.Result == Menu.SelectionResult.Ok) { }
... ... @@ -88,7 +93,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS
88 93 //menufunctions.DisplayTitle();
89 94 menufunctions.DisplayItems(1);
90 95 Menu.Selection srf = menufunctions.Select(functionkey);
91   - if (srf.Result == Menu.SelectionResult.Exit) { break; }
  96 + if (srf.Result == Menu.SelectionResult.Exit) { exitwasrequested = true; break; }
92 97 else if (srf.Result == Menu.SelectionResult.None) { break; }
93 98 else if (srf.Result == Menu.SelectionResult.Error) { break; }
94 99 else if (srf.Result == Menu.SelectionResult.Ok) { }
... ... @@ -254,7 +259,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS
254 259  
255 260 #region DisplayServices
256 261 private static void ServiceListDisplayer() { DisplayWindowsServiceMenu(); }
257   - public static Menu DisplayWindowsServiceMenu(WindowsServiceManagerXmlProcessor config=null,string prompt = null,List<WindowsServiceGroup> servicegroups=null)
  262 + public static Menu DisplayWindowsServiceMenu(WindowsServiceManagerXmlProcessor config=null,string prompt = null, KeyGroupList servicegroups=null)
258 263 {
259 264 if (config==null) { config = new WindowsServiceManagerXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); }
260 265 var menuservices = new Menu("Windows services",prompt)
... ... @@ -281,7 +286,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS
281 286 ;
282 287 menuservices.ClearMenuItemList();
283 288  
284   - List<WindowsServiceGroup> wsgdefList = config.GetWindowsServiceGroupDefinitionList();
  289 + KeyGroupList wsgdefList = config.WinServiceKeyGroupList;
  290 + if (wsgdefList == null || !wsgdefList.Any()) return null;
285 291 foreach (var wsgdef in wsgdefList)
286 292 {
287 293 //string menuitemtext = wsgdef.Xml_Description + "(" + string.Join(",", wsgdef.Xml_WindowsServiceKeyList) + ")";
... ... @@ -682,7 +688,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS
682 688 List<WindowsService> _winservicelist;
683 689 List<WindowsService> _winservicelistinstartorder;
684 690 List<WindowsService> _winservicelistinstoporder;
685   - List<WindowsServiceGroup> _winservicegrouplist;
  691 + public KeyGroupList WinServiceKeyGroupList;
686 692 #region constructor
687 693 public WindowsServiceManagerXmlProcessor(string xmlcs, string basefolder, string lcid) : base(xmlcs, basefolder, lcid, null)
688 694 {
... ... @@ -695,39 +701,19 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS
695 701 _winservicelistinstartorder = ProduceWindowsServiceDefinitionListInStartOrder();
696 702 _winservicelistinstoporder = ProduceWindowsServiceDefinitionListInStartOrder(); _winservicelistinstoporder.Reverse();
697 703  
698   - _winservicegrouplist = new List<WindowsServiceGroup>();
699   - var wsgxmllist = GetAllXElements(nameof(WindowsService.XmlStructure.WindowsServiceGroup));
700   - if (wsgxmllist != null && wsgxmllist.Any())
701   - {
702   - foreach (var wsgxml in wsgxmllist) { var wsg = new WindowsServiceGroup(wsgxml); if (wsg.Valid) { _winservicegrouplist.Add(wsg); } }
703   - }
  704 + WinServiceKeyGroupList = new KeyGroupList(this.RootElement);
704 705 }
705 706 #endregion constructor
706   - #region GetWindowsServiceGroupDefinitionList
707   - public WindowsServiceGroup GetWindowsServiceGroup(string key) { return _winservicegrouplist.FirstOrDefault(x => x.Xml_Key == key); }
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   - }
720   - #endregion GetWindowsServiceGroupDefinitionList
721 707  
722 708 #region GetWindowsServiceDefinitionList
723 709 public WindowsService GetWindowsService(string key) { return _winservicelist.FirstOrDefault(x => x.Xml_Key == key); }
724   - public List<WindowsService> GetWindowsServiceDefinitionList(List<WindowsServiceGroup> wsgList=null)
  710 + public List<WindowsService> GetWindowsServiceDefinitionList(KeyGroupList wsgList =null)
725 711 {
726 712 if (wsgList == null) { return _winservicelist; }
727 713 else
728 714 {
729 715 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(); }
  716 + foreach (var wsg in wsgList) { wsList = wsList.Concat(wsg.Xml_KeyList.Select(k=> _winservicelist.FirstOrDefault(ws=>ws.Xml_Key==k))).Where(ws=>ws!=null).ToList(); }
731 717 return wsList;
732 718 }
733 719 }
... ... @@ -760,6 +746,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS
760 746 #endregion GetWindowsServiceDefinitionList
761 747 }
762 748 #endregion WindowsServiceManagerXmlProcessor class
  749 +
763 750 #region WindowsService class
764 751 public class WindowsService : XmlLinqBase
765 752 {
... ... @@ -934,15 +921,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS
934 921 #region XmlStructure
935 922 public static class XmlStructure
936 923 {
937   - public static class WindowsServiceGroup
938   - {
939   - public static class Attributes
940   - {
941   - public static class Key { public static class Values { public static string DEFAULT = ""; } }
942   - public static class Description { public static class Values { public static string DEFAULT = ""; } }
943   - public static class WindowsServiceKeyList { public static class Values { public static string DEFAULT = ""; } }
944   - }
945   - }
946 924 public static class WindowsService
947 925 {
948 926 public static class Attributes
... ... @@ -1030,34 +1008,81 @@ namespace Vrh.Log4Pro.MaintenanceConsole.WindowsServiceManagerNS
1030 1008 #endregion public classes,types
1031 1009 }
1032 1010 #endregion WindowsService class
1033   - #region WindowsServiceGroup class
1034   - public class WindowsServiceGroup : XmlLinqBase
1035   - {
1036   - public bool Valid;
1037   - public List<string> Xml_WindowsServiceKeyList;
1038   - public string Xml_Key;
1039   - public string Xml_Description;
1040   - public WindowsServiceGroup() { }
1041   - public WindowsServiceGroup(WindowsServiceGroup wsg)
  1011 +
  1012 + #region KeyGroupList class
  1013 + public class KeyGroupList : List<KeyGroupList.KeyGroup>
  1014 + {
  1015 + public class KeyGroup : XmlLinqBase
  1016 + {
  1017 + public string GetOneLineInfo() { return $"{this.Xml_Description} ({this.Xml_Key})"; }
  1018 + public bool Valid;
  1019 + public List<string> Xml_KeyList;
  1020 + public string Xml_Key;
  1021 + public string Xml_Description;
  1022 + public KeyGroup() { }
  1023 + public KeyGroup(KeyGroup wsg)
  1024 + {
  1025 + Xml_Key = wsg.Xml_Key;
  1026 + Xml_KeyList = wsg.Xml_KeyList.Select(x => x).ToList();
  1027 + Xml_Description = wsg.Xml_Description;
  1028 + Valid = wsg.Valid;
  1029 + }
  1030 + public KeyGroup(XElement keygroupxml)
  1031 + {
  1032 + Xml_Key = GetValue(nameof(XmlStructure.KeyGroup.Attributes.Key), keygroupxml, XmlStructure.KeyGroup.Attributes.Key.Values.DEFAULT);
  1033 + Xml_Description = GetValue(nameof(XmlStructure.KeyGroup.Attributes.Description), keygroupxml, XmlStructure.KeyGroup.Attributes.Description.Values.DEFAULT);
  1034 + var keycommaliststring = GetValue(nameof(XmlStructure.KeyGroup.Attributes.KeyList), keygroupxml, XmlStructure.KeyGroup.Attributes.KeyList.Values.DEFAULT);
  1035 + Valid = false;
  1036 + if (!string.IsNullOrWhiteSpace(keycommaliststring))
  1037 + {
  1038 + Xml_KeyList = new List<string>(keycommaliststring.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
  1039 + if (Xml_KeyList.Contains("*")) { Xml_KeyList = new List<string>() { "*" }; }
  1040 + Valid = Xml_KeyList.Any();
  1041 + }
  1042 + }
  1043 +
  1044 + #region XmlStructure
  1045 + public static class XmlStructure
  1046 + {
  1047 + public static class KeyGroup
  1048 + {
  1049 + public static class Attributes
  1050 + {
  1051 + public static class Key { public static class Values { public static string DEFAULT = ""; } }
  1052 + public static class Description { public static class Values { public static string DEFAULT = ""; } }
  1053 + public static class KeyList { public static class Values { public static string DEFAULT = ""; } }
  1054 + }
  1055 + }
  1056 + }
  1057 + #endregion XmlStructure
  1058 + }
  1059 + public static KeyGroupList Factory(XElement keygrouplistcontainer)
1042 1060 {
1043   - Xml_Key = wsg.Xml_Key;
1044   - Xml_WindowsServiceKeyList = wsg.Xml_WindowsServiceKeyList.Select(x => x).ToList();
1045   - Xml_Description = wsg.Xml_Description;
1046   - Valid = wsg.Valid;
  1061 + return new KeyGroupList(keygrouplistcontainer);
1047 1062 }
1048   - public WindowsServiceGroup(XElement wsgxml)
  1063 + public KeyGroupList(XElement keygrouplistcontainer)
1049 1064 {
1050   - Xml_Key = GetValue(nameof(WindowsService.XmlStructure.WindowsServiceGroup.Attributes.Key), wsgxml, WindowsService.XmlStructure.WindowsServiceGroup.Attributes.Key.Values.DEFAULT);
1051   - Xml_Description = GetValue(nameof(WindowsService.XmlStructure.WindowsServiceGroup.Attributes.Description), wsgxml, WindowsService.XmlStructure.WindowsServiceGroup.Attributes.Description.Values.DEFAULT);
1052   - var keycommaliststring = GetValue(nameof(WindowsService.XmlStructure.WindowsServiceGroup.Attributes.WindowsServiceKeyList), wsgxml, WindowsService.XmlStructure.WindowsServiceGroup.Attributes.WindowsServiceKeyList.Values.DEFAULT);
1053   - Valid = false;
1054   - if (!string.IsNullOrWhiteSpace(keycommaliststring))
  1065 + var wsgxmllist = keygrouplistcontainer.Elements(XName.Get(nameof(KeyGroup.XmlStructure.KeyGroup)));
  1066 + if (wsgxmllist != null && wsgxmllist.Any())
1055 1067 {
1056   - Xml_WindowsServiceKeyList = new List<string>(keycommaliststring.Split(new char[] { ',' },StringSplitOptions.RemoveEmptyEntries));
1057   - if (Xml_WindowsServiceKeyList.Contains("*")) { Xml_WindowsServiceKeyList = new List<string>() { "*" }; }
1058   - Valid = Xml_WindowsServiceKeyList.Any();
  1068 + foreach (var wsgxml in wsgxmllist) { var wsg = new KeyGroup(wsgxml); if (wsg.Valid) { this.Add(wsg); } }
1059 1069 }
1060 1070 }
  1071 + public KeyGroupList(List<KeyGroup> keygrouplist)
  1072 + {
  1073 + foreach (var kg in keygrouplist) { this.Add(kg); }
  1074 + }
  1075 + public List<string> GetOneLineInfoList() { return this.Select(g=>g.GetOneLineInfo()).ToList(); }
  1076 + public KeyGroup GetGroup(string key) { return this.FirstOrDefault(x => x.Xml_Key == key); }
  1077 + public List<string> GetGroupKeyList(string groupkey, out string groupdescription)
  1078 + {
  1079 + groupdescription = null;
  1080 + List<KeyGroup> wsgdefList = this.Where(sgr => sgr.Xml_Key == groupkey || groupkey == null).ToList();
  1081 + if (groupkey != null && wsgdefList != null && wsgdefList.Any()) { groupdescription = wsgdefList.First().Xml_Description; }
  1082 + List<string> allwskeys = new List<string>();
  1083 + foreach (var wsg in wsgdefList) { allwskeys = allwskeys.Concat(wsg.Xml_KeyList).ToList(); }
  1084 + return allwskeys;
  1085 + }
1061 1086 }
1062   - #endregion WindowsServiceGroup class
  1087 + #endregion KeyGroupList class
1063 1088 }
... ...
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.11.3.0")]
36   -[assembly: AssemblyFileVersion("1.11.3.0")]
  35 +[assembly: AssemblyVersion("1.11.4.0")]
  36 +[assembly: AssemblyFileVersion("1.11.4.0")]
... ...