Commit b03c774335f9d73461aebe83d7ddc25157fc2979
1 parent
cac3ec8f
install environment további finomítása
Showing
5 changed files
with
53 additions
and
28 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
@@ -102,8 +102,9 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS | @@ -102,8 +102,9 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS | ||
102 | /// <param name="prefix"></param> | 102 | /// <param name="prefix"></param> |
103 | /// <param name="validitylist"></param> | 103 | /// <param name="validitylist"></param> |
104 | /// <param name="exitvalue"></param> | 104 | /// <param name="exitvalue"></param> |
105 | + /// <param name="required"></param> | ||
105 | /// <returns></returns> | 106 | /// <returns></returns> |
106 | - public static string ReadLine(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null, string prefix = "",string suffix = "",List<string> validitylist=null,string exitvalue="EX",string defaultvalue=null) | 107 | + public static string ReadLine(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null, string prefix = "", string suffix = "", List<string> validitylist = null, string exitvalue = "EX", string defaultvalue = null, bool required = false) |
107 | { | 108 | { |
108 | string input; | 109 | string input; |
109 | while (true) | 110 | while (true) |
@@ -128,8 +129,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS | @@ -128,8 +129,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS | ||
128 | Write(prompt, f, b, bracket, prefix, suffix); | 129 | Write(prompt, f, b, bracket, prefix, suffix); |
129 | input = Console.ReadLine(); | 130 | input = Console.ReadLine(); |
130 | if (defaultvalue!=null && (input == null || input == "")) { input = defaultvalue; } | 131 | if (defaultvalue!=null && (input == null || input == "")) { input = defaultvalue; } |
131 | - if (exitvalue != null && input!=null && input.ToLower() == exitvalue || validitylist ==null || !validitylist.Any() || validitylist.Contains(input)) { break; } | ||
132 | - WriteLine($"Erroneous value!",ConsoleColor.Red); | 132 | + if (required && string.IsNullOrWhiteSpace(input)) { WriteLine($"Erroneous value!", ConsoleColor.Red); continue; } |
133 | + if (exitvalue != null && input != null && input.ToLower() == exitvalue) { break; } | ||
134 | + if (validitylist == null || !validitylist.Any() || string.IsNullOrWhiteSpace(input) || validitylist.Contains(input)) { break; } | ||
135 | + WriteLine($"Erroneous value!", ConsoleColor.Red); | ||
133 | } | 136 | } |
134 | } | 137 | } |
135 | return input; | 138 | return input; |
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
@@ -289,6 +289,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS | @@ -289,6 +289,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS | ||
289 | public const string KEY = "INM"; | 289 | public const string KEY = "INM"; |
290 | public static class Functions | 290 | public static class Functions |
291 | { | 291 | { |
292 | + public static class EnableWindowsFeature { public const string KEY = "ENA"; } | ||
292 | public static class EnvironmentInstall { public const string KEY = "ENV"; } | 293 | public static class EnvironmentInstall { public const string KEY = "ENV"; } |
293 | public static class RestartServer { public const string KEY = "RST"; } | 294 | public static class RestartServer { public const string KEY = "RST"; } |
294 | public static class ConfigureIIS { public const string KEY = "IIS"; } | 295 | public static class ConfigureIIS { public const string KEY = "IIS"; } |
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs
@@ -215,7 +215,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | @@ -215,7 +215,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS | ||
215 | try | 215 | try |
216 | { | 216 | { |
217 | RegistryKey rk = Registry.LocalMachine.OpenSubKey(path); | 217 | RegistryKey rk = Registry.LocalMachine.OpenSubKey(path); |
218 | - if (rk == null) return ""; | 218 | + if (rk == null) { return ""; } |
219 | return (string)rk.GetValue(key); | 219 | return (string)rk.GetValue(key); |
220 | } | 220 | } |
221 | catch { return ""; } | 221 | catch { return ""; } |
Vrh.Log4Pro.MaintenanceConsole/Manager - InstallManager.cs
@@ -43,6 +43,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.InstallManagerNS | @@ -43,6 +43,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.InstallManagerNS | ||
43 | var menufunctions = new Menu("Install Manager", "Select function!") | 43 | var menufunctions = new Menu("Install Manager", "Select function!") |
44 | .AddMenuItem(new Menu.Item(CLP.Module.InstallManager.Functions.EnvironmentInstall.KEY, "Environment install", EnvironmentInstall, new Menu.ExecutorParameter(cfg: config, null))) | 44 | .AddMenuItem(new Menu.Item(CLP.Module.InstallManager.Functions.EnvironmentInstall.KEY, "Environment install", EnvironmentInstall, new Menu.ExecutorParameter(cfg: config, null))) |
45 | .AddMenuItem(new Menu.Item(CLP.Module.WebApplicationManager.Function.ConfigureIIS.KEY, "Configure IIS Default App Pool", WebApplicationManager.ConfigIIS, epWA)) | 45 | .AddMenuItem(new Menu.Item(CLP.Module.WebApplicationManager.Function.ConfigureIIS.KEY, "Configure IIS Default App Pool", WebApplicationManager.ConfigIIS, epWA)) |
46 | + .AddMenuItem(new Menu.Item(CLP.Module.InstallManager.Functions.EnableWindowsFeature.KEY, "Enable Windows feature (option: set install source)", EnableWindowsFeature, new Menu.ExecutorParameter(cfg: config, null))) | ||
46 | .AddMenuItem(new Menu.ItemSeparator()) | 47 | .AddMenuItem(new Menu.ItemSeparator()) |
47 | .AddMenuItem(new Menu.Item(CLP.Module.InstallManager.Functions.RestartServer.KEY, "Restart server", RestartServer, new Menu.ExecutorParameter(cfg: config, null))) | 48 | .AddMenuItem(new Menu.Item(CLP.Module.InstallManager.Functions.RestartServer.KEY, "Restart server", RestartServer, new Menu.ExecutorParameter(cfg: config, null))) |
48 | .SetSelectionMode(Menu.SelectionMode.Single); | 49 | .SetSelectionMode(Menu.SelectionMode.Single); |
@@ -52,49 +53,53 @@ namespace Vrh.Log4Pro.MaintenanceConsole.InstallManagerNS | @@ -52,49 +53,53 @@ namespace Vrh.Log4Pro.MaintenanceConsole.InstallManagerNS | ||
52 | #endregion Execute | 53 | #endregion Execute |
53 | 54 | ||
54 | #region First level Executors with UI | 55 | #region First level Executors with UI |
56 | + #region EnableWindowsFeature | ||
57 | + private static object EnableWindowsFeature(object parameter, object o) | ||
58 | + { | ||
59 | + var config = (parameter as Menu.ExecutorParameter).GetConfig<InstallManagerXmlParser>(); | ||
60 | + var selectedos = GetOsCode();if (selectedos == null) { return o; } | ||
61 | + | ||
62 | + string featurename = ColorConsole.ReadLine($"Enter Windows feature name!", ConsoleColor.Green,required:true); | ||
63 | + if (featurename.ToLower() == "ex") { return o; } | ||
64 | + | ||
65 | + foreach (var wfg in config.WindowsFeatureGroups.Where(x => selectedos == null || x.OS == selectedos)) | ||
66 | + { | ||
67 | + EnableWindowsFeatures(wfg.Group, wfg.OS, featurename, config); | ||
68 | + }; | ||
69 | + return o; | ||
70 | + } | ||
71 | + #endregion EnableWindowsFeature | ||
55 | #region EnvironmentInstall | 72 | #region EnvironmentInstall |
56 | private static object EnvironmentInstall(object parameter, object o) | 73 | private static object EnvironmentInstall(object parameter, object o) |
57 | { | 74 | { |
58 | var config = (parameter as Menu.ExecutorParameter).GetConfig<InstallManagerXmlParser>(); | 75 | var config = (parameter as Menu.ExecutorParameter).GetConfig<InstallManagerXmlParser>(); |
59 | - InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.Group.Values grp; | ||
60 | - InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values os; | ||
61 | - | ||
62 | - string osfrn = Tools.OSFriendlyName(); | ||
63 | - var defaultvalue = | ||
64 | - osfrn.StartsWith("Microsoft Windows 10") ? InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values.WS2016.ToString() | ||
65 | - : osfrn.StartsWith("Microsoft Windows Server 2016") ? InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values.WS2016.ToString() | ||
66 | - : osfrn.StartsWith("Microsoft Windows Server 2012") ? InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values.WS2016.ToString() | ||
67 | - : null; | ||
68 | - var oslist = Enum.GetNames(typeof(InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values)).ToList(); | ||
69 | - string answer = ColorConsole.ReadLine($"Enter os code (friendly name is: '{osfrn}')!", ConsoleColor.Green, validitylist: oslist, defaultvalue: defaultvalue.ToString()); | 76 | + var selectedos = GetOsCode(); if (selectedos == null) { return o; } |
70 | 77 | ||
71 | - InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values? selectedos = null; | ||
72 | - selectedos = (InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values)Enum | ||
73 | - .Parse(typeof(InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values), answer); | ||
74 | foreach (var wfg in config.WindowsFeatureGroups.Where(x=>selectedos==null || x.OS== selectedos)) | 78 | foreach (var wfg in config.WindowsFeatureGroups.Where(x=>selectedos==null || x.OS== selectedos)) |
75 | { | 79 | { |
76 | - grp = wfg.Group; | ||
77 | - os = wfg.OS; | ||
78 | - answer = ColorConsole.ReadLine($"Do You want to configure feature group '{grp}' for os '{os}'?(Y/N)", ConsoleColor.Green); | ||
79 | - if (answer.ToUpper() == "Y") { EnableWindowsFeatures(grp, os, config); } | 80 | + string answer = ColorConsole.ReadLine($"Do You want to configure feature group '{wfg.Group}' for os '{wfg.OS}'?(Y/N)", ConsoleColor.Green); |
81 | + if (answer.ToUpper() == "Y") { EnableWindowsFeatures(wfg.Group, wfg.OS, null, config); } | ||
80 | }; | 82 | }; |
81 | return o; | 83 | return o; |
82 | } | 84 | } |
83 | - private static void EnableWindowsFeatures(InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.Group.Values grp | ||
84 | - , InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values os, InstallManagerXmlParser environmentinstallconfig) | 85 | + private static void EnableWindowsFeatures( |
86 | + InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.Group.Values grp | ||
87 | + , InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values os | ||
88 | + , string featurename | ||
89 | + , InstallManagerXmlParser environmentinstallconfig) | ||
85 | { | 90 | { |
86 | - ColorConsole.WriteLine($"Enableing {grp} features for os {os}...",ConsoleColor.Green); | 91 | + if (featurename == null) { ColorConsole.WriteLine($"Enableing {grp} features for os {os}...", ConsoleColor.Green); } |
87 | foreach (var fn in environmentinstallconfig.GetFeatureList(os,grp)) | 92 | foreach (var fn in environmentinstallconfig.GetFeatureList(os,grp)) |
88 | { | 93 | { |
94 | + if (featurename!=null && fn != featurename) { continue; } | ||
89 | if (string.IsNullOrWhiteSpace(fn) || fn.StartsWith("#")) { continue; } | 95 | if (string.IsNullOrWhiteSpace(fn) || fn.StartsWith("#")) { continue; } |
90 | ColorConsole.WriteLine($"Enableing {grp} features for os {os}. Feature name: {fn}.",ConsoleColor.Yellow); | 96 | ColorConsole.WriteLine($"Enableing {grp} features for os {os}. Feature name: {fn}.",ConsoleColor.Yellow); |
91 | string response; | 97 | string response; |
92 | switch (os) | 98 | switch (os) |
93 | { | 99 | { |
94 | case InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values.WS2016: | 100 | case InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values.WS2016: |
95 | - | ||
96 | //var cmd = "Powershell -Command {Import-Module ServerManager ; Install-WindowsFeature XXXX}"; | 101 | //var cmd = "Powershell -Command {Import-Module ServerManager ; Install-WindowsFeature XXXX}"; |
97 | - response = Tools.ExecuteAndGetStdIo("Powershell", $"-Command {{Import - Module ServerManager ; Install-WindowsFeature -Name {fn} -IncludeAllSubFeature -IncludeManagementTools}}"); | 102 | + response = Tools.ExecuteAndGetStdIo("Powershell", $"-Command {{Import-Module ServerManager; Install-WindowsFeature -Name {fn} -IncludeAllSubFeature -IncludeManagementTools}}"); |
98 | //response = Tools.ExecuteAndGetStdIo("Install-WindowsFeature", $"-Name {fn} -IncludeAllSubFeature -IncludeManagementTools"); | 103 | //response = Tools.ExecuteAndGetStdIo("Install-WindowsFeature", $"-Name {fn} -IncludeAllSubFeature -IncludeManagementTools"); |
99 | break; | 104 | break; |
100 | case InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values.W7: | 105 | case InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values.W7: |
@@ -104,6 +109,22 @@ namespace Vrh.Log4Pro.MaintenanceConsole.InstallManagerNS | @@ -104,6 +109,22 @@ namespace Vrh.Log4Pro.MaintenanceConsole.InstallManagerNS | ||
104 | } | 109 | } |
105 | } | 110 | } |
106 | } | 111 | } |
112 | + public static InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values? GetOsCode() | ||
113 | + { | ||
114 | + string osfrn = Tools.OSFriendlyName(); | ||
115 | + var defaultvalue = | ||
116 | + osfrn.StartsWith("Microsoft Windows 10") ? InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values.WS2016.ToString() | ||
117 | + : osfrn.StartsWith("Microsoft Windows Server 2016") ? InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values.WS2016.ToString() | ||
118 | + : osfrn.StartsWith("Microsoft Windows Server 2012") ? InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values.WS2016.ToString() | ||
119 | + : null; | ||
120 | + var oslist = Enum.GetNames(typeof(InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values)).ToList(); | ||
121 | + string answer = ColorConsole.ReadLine($"Enter os code (friendly name is: '{osfrn}')!", ConsoleColor.Green, validitylist: oslist, defaultvalue: defaultvalue.ToString(), required: true); | ||
122 | + if (answer.ToLower() == "ex") { return null; } | ||
123 | + InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values? selectedos = null; | ||
124 | + selectedos = (InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values)Enum | ||
125 | + .Parse(typeof(InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values), answer); | ||
126 | + return selectedos; | ||
127 | + } | ||
107 | #endregion EnvironmentInstall | 128 | #endregion EnvironmentInstall |
108 | #region Restart server | 129 | #region Restart server |
109 | private static object RestartServer(object parameter, object o) | 130 | private static object RestartServer(object parameter, object o) |
Vrh.Log4Pro.MaintenanceConsole/Program.cs
@@ -80,7 +80,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole | @@ -80,7 +80,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole | ||
80 | static void DisplayComputerInfo() | 80 | static void DisplayComputerInfo() |
81 | { | 81 | { |
82 | const string XMLCONNECTIONSTRING = "config=MAINTENANCECONSOLE;"; | 82 | const string XMLCONNECTIONSTRING = "config=MAINTENANCECONSOLE;"; |
83 | - const string XMLCONNECTIONSTRING_DEFAULT = "file=Config.Xml;"; | 83 | + //const string XMLCONNECTIONSTRING_DEFAULT = "file=Config.Xml;"; |
84 | var config = new MaintenanceConsoleXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); | 84 | var config = new MaintenanceConsoleXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); |
85 | 85 | ||
86 | ColorConsole.WriteLine(config.Xml_Header,ConsoleColor.Yellow,bracket:"[]"); | 86 | ColorConsole.WriteLine(config.Xml_Header,ConsoleColor.Yellow,bracket:"[]"); |