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 | 102 | /// <param name="prefix"></param> |
103 | 103 | /// <param name="validitylist"></param> |
104 | 104 | /// <param name="exitvalue"></param> |
105 | + /// <param name="required"></param> | |
105 | 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 | 109 | string input; |
109 | 110 | while (true) |
... | ... | @@ -128,8 +129,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS |
128 | 129 | Write(prompt, f, b, bracket, prefix, suffix); |
129 | 130 | input = Console.ReadLine(); |
130 | 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 | 138 | return input; | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - CommandLineParser.cs
... | ... | @@ -289,6 +289,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.CommandLineParserNS |
289 | 289 | public const string KEY = "INM"; |
290 | 290 | public static class Functions |
291 | 291 | { |
292 | + public static class EnableWindowsFeature { public const string KEY = "ENA"; } | |
292 | 293 | public static class EnvironmentInstall { public const string KEY = "ENV"; } |
293 | 294 | public static class RestartServer { public const string KEY = "RST"; } |
294 | 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 | 215 | try |
216 | 216 | { |
217 | 217 | RegistryKey rk = Registry.LocalMachine.OpenSubKey(path); |
218 | - if (rk == null) return ""; | |
218 | + if (rk == null) { return ""; } | |
219 | 219 | return (string)rk.GetValue(key); |
220 | 220 | } |
221 | 221 | catch { return ""; } | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Manager - InstallManager.cs
... | ... | @@ -43,6 +43,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.InstallManagerNS |
43 | 43 | var menufunctions = new Menu("Install Manager", "Select function!") |
44 | 44 | .AddMenuItem(new Menu.Item(CLP.Module.InstallManager.Functions.EnvironmentInstall.KEY, "Environment install", EnvironmentInstall, new Menu.ExecutorParameter(cfg: config, null))) |
45 | 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 | 47 | .AddMenuItem(new Menu.ItemSeparator()) |
47 | 48 | .AddMenuItem(new Menu.Item(CLP.Module.InstallManager.Functions.RestartServer.KEY, "Restart server", RestartServer, new Menu.ExecutorParameter(cfg: config, null))) |
48 | 49 | .SetSelectionMode(Menu.SelectionMode.Single); |
... | ... | @@ -52,49 +53,53 @@ namespace Vrh.Log4Pro.MaintenanceConsole.InstallManagerNS |
52 | 53 | #endregion Execute |
53 | 54 | |
54 | 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 | 72 | #region EnvironmentInstall |
56 | 73 | private static object EnvironmentInstall(object parameter, object o) |
57 | 74 | { |
58 | 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 | 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 | 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 | 92 | foreach (var fn in environmentinstallconfig.GetFeatureList(os,grp)) |
88 | 93 | { |
94 | + if (featurename!=null && fn != featurename) { continue; } | |
89 | 95 | if (string.IsNullOrWhiteSpace(fn) || fn.StartsWith("#")) { continue; } |
90 | 96 | ColorConsole.WriteLine($"Enableing {grp} features for os {os}. Feature name: {fn}.",ConsoleColor.Yellow); |
91 | 97 | string response; |
92 | 98 | switch (os) |
93 | 99 | { |
94 | 100 | case InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values.WS2016: |
95 | - | |
96 | 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 | 103 | //response = Tools.ExecuteAndGetStdIo("Install-WindowsFeature", $"-Name {fn} -IncludeAllSubFeature -IncludeManagementTools"); |
99 | 104 | break; |
100 | 105 | case InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values.W7: |
... | ... | @@ -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 | 128 | #endregion EnvironmentInstall |
108 | 129 | #region Restart server |
109 | 130 | private static object RestartServer(object parameter, object o) | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Program.cs
... | ... | @@ -80,7 +80,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole |
80 | 80 | static void DisplayComputerInfo() |
81 | 81 | { |
82 | 82 | const string XMLCONNECTIONSTRING = "config=MAINTENANCECONSOLE;"; |
83 | - const string XMLCONNECTIONSTRING_DEFAULT = "file=Config.Xml;"; | |
83 | + //const string XMLCONNECTIONSTRING_DEFAULT = "file=Config.Xml;"; | |
84 | 84 | var config = new MaintenanceConsoleXmlProcessor(XMLCONNECTIONSTRING, "", "hu-HU"); |
85 | 85 | |
86 | 86 | ColorConsole.WriteLine(config.Xml_Header,ConsoleColor.Yellow,bracket:"[]"); | ... | ... |