Commit cac3ec8fabc3be233138ede5b7d232a32235f8cb

Authored by Schwirg László
1 parent 0cafa26d

v1.1.0

- Environmentinstall finomítása
Vrh.Log4Pro.MaintenanceConsole/App.config
... ... @@ -20,11 +20,15 @@
20 20 <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
21 21 <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
22 22 </dependentAssembly>
  23 + <dependentAssembly>
  24 + <assemblyIdentity name="System.Security.Principal.Windows" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  25 + <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
  26 + </dependentAssembly>
23 27 </assemblyBinding>
24 28 </runtime>
25 29 <system.web>
26   - <membership configSource="system.web.membership.config"/>
27   - <roleManager configSource="system.web.roleManager.config"/>
  30 + <membership configSource="system.web.membership.config" />
  31 + <roleManager configSource="system.web.roleManager.config" />
28 32 </system.web>
29 33 <entityFramework>
30 34 <providers>
... ...
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - ColorConsole.cs
... ... @@ -100,24 +100,39 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS
100 100 /// <param name="b"></param>
101 101 /// <param name="bracket"></param>
102 102 /// <param name="prefix"></param>
  103 + /// <param name="validitylist"></param>
  104 + /// <param name="exitvalue"></param>
103 105 /// <returns></returns>
104   - public static string ReadLine(string text = null, ConsoleColor? f = null, ConsoleColor? b = null, string bracket = null, string prefix = "",string suffix = "")
  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)
105 107 {
106   - if (silentMode)
  108 + string input;
  109 + while (true)
107 110 {
108   - if (readlineList == null || readlineList.Length == 0) { return null; }
  111 + string prompt = text;
  112 + if (silentMode)
  113 + {
  114 + if (readlineList == null || readlineList.Length == 0) { return null; }
  115 + else
  116 + {
  117 + var nextreadline = readlineList[0];
  118 + readlineList = readlineList.Skip(1).ToArray();
  119 + return nextreadline;
  120 + }
  121 + }
109 122 else
110 123 {
111   - var nextreadline = readlineList[0];
112   - readlineList = readlineList.Skip(1).ToArray();
113   - return nextreadline;
  124 + if (validitylist != null && validitylist.Any()) { prompt += $" Valid values are {'\''+string.Join("','", validitylist)+'\''}."; }
  125 + if (defaultvalue != null) { prompt += $" Default value is '{defaultvalue}'."; }
  126 + if (exitvalue != null) { prompt += $" Enter EX to exit."; }
  127 +
  128 + Write(prompt, f, b, bracket, prefix, suffix);
  129 + input = Console.ReadLine();
  130 + 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);
114 133 }
115 134 }
116   - else
117   - {
118   - Write(text, f, b, bracket, prefix,suffix);
119   - return Console.ReadLine();
120   - }
  135 + return input;
121 136 }
122 137  
123 138 /// <summary>
... ...
Vrh.Log4Pro.MaintenanceConsole/ConsoleFunction - Tools.cs
... ... @@ -17,6 +17,7 @@ using Vrh.XmlProcessing;
17 17 using System.Xml.Linq;
18 18 using Vrh.Log4Pro.MaintenanceConsole.ColorConsoleNS;
19 19 using VRH.Common;
  20 +using Microsoft.Win32;
20 21  
21 22 namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS
22 23 {
... ... @@ -209,5 +210,27 @@ namespace Vrh.Log4Pro.MaintenanceConsole.ToolsNS
209 210 Process.Start(startinfo);
210 211 }
211 212 public enum ShutDownMode { Sleep, Hibernation,Lock,Logoff,Restart,ShutDown,}
  213 + public static string HKLM_GetString(string path, string key)
  214 + {
  215 + try
  216 + {
  217 + RegistryKey rk = Registry.LocalMachine.OpenSubKey(path);
  218 + if (rk == null) return "";
  219 + return (string)rk.GetValue(key);
  220 + }
  221 + catch { return ""; }
  222 + }
  223 +
  224 + public static string OSFriendlyName()
  225 + {
  226 + string ProductName = HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName");
  227 + string CSDVersion = HKLM_GetString(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CSDVersion");
  228 + if (ProductName != "")
  229 + {
  230 + return (ProductName.StartsWith("Microsoft") ? "" : "Microsoft ") + ProductName +
  231 + (CSDVersion != "" ? " " + CSDVersion : "");
  232 + }
  233 + return "";
  234 + }
212 235 }
213 236 }
... ...
Vrh.Log4Pro.MaintenanceConsole/Manager - InstallManager.cs
... ... @@ -9,7 +9,6 @@ using System.Threading;
9 9 using System.Threading.Tasks;
10 10  
11 11 using Microsoft.Web.Administration;
12   -using System.Management;
13 12 using System.Diagnostics;
14 13  
15 14 using Vrh.Log4Pro.MaintenanceConsole.MenuNS;
... ... @@ -22,6 +21,7 @@ using Vrh.Log4Pro.MaintenanceConsole.WebApplicationManagerNS;
22 21 using Vrh.XmlProcessing;
23 22 using System.Xml.Linq;
24 23 using System.Text.RegularExpressions;
  24 +using System.Collections.ObjectModel;
25 25  
26 26 namespace Vrh.Log4Pro.MaintenanceConsole.InstallManagerNS
27 27 {
... ... @@ -58,12 +58,24 @@ namespace Vrh.Log4Pro.MaintenanceConsole.InstallManagerNS
58 58 var config = (parameter as Menu.ExecutorParameter).GetConfig<InstallManagerXmlParser>();
59 59 InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.Group.Values grp;
60 60 InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values os;
61   - string answer;
62   - foreach (var wfg in config.WindowsFeatureGroups)
  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());
  70 +
  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))
63 75 {
64 76 grp = wfg.Group;
65 77 os = wfg.OS;
66   - answer = ColorConsole.ReadLine($"Do You want to configure feature group '{grp}' for os '{os}'?(Y/N)", ConsoleColor.Yellow);
  78 + answer = ColorConsole.ReadLine($"Do You want to configure feature group '{grp}' for os '{os}'?(Y/N)", ConsoleColor.Green);
67 79 if (answer.ToUpper() == "Y") { EnableWindowsFeatures(grp, os, config); }
68 80 };
69 81 return o;
... ... @@ -71,7 +83,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.InstallManagerNS
71 83 private static void EnableWindowsFeatures(InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.Group.Values grp
72 84 , InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values os, InstallManagerXmlParser environmentinstallconfig)
73 85 {
74   - ColorConsole.WriteLine($"Enableing {grp} features for os {os}...",ConsoleColor.Yellow);
  86 + ColorConsole.WriteLine($"Enableing {grp} features for os {os}...",ConsoleColor.Green);
75 87 foreach (var fn in environmentinstallconfig.GetFeatureList(os,grp))
76 88 {
77 89 if (string.IsNullOrWhiteSpace(fn) || fn.StartsWith("#")) { continue; }
... ... @@ -80,7 +92,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.InstallManagerNS
80 92 switch (os)
81 93 {
82 94 case InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values.WS2016:
83   - response = Tools.ExecuteAndGetStdIo("Install-WindowsFeature", $"-Name {fn} -IncludeAllSubFeature -IncludeManagementTools");
  95 +
  96 + //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}}");
  98 + //response = Tools.ExecuteAndGetStdIo("Install-WindowsFeature", $"-Name {fn} -IncludeAllSubFeature -IncludeManagementTools");
84 99 break;
85 100 case InstallManagerXmlParser.XmlStructure.EnvironmentInstall.WindowsFeatureList.Attributes.OS.Values.W7:
86 101 response = Tools.ExecuteAndGetStdIo("dism", $"/online /Enable-Feature /FeatureName:{fn}");
... ...
Vrh.Log4Pro.MaintenanceConsole/Program.cs
... ... @@ -134,9 +134,12 @@ namespace Vrh.Log4Pro.MaintenanceConsole
134 134 ColorConsole.Write(System.Environment.OSVersion.ServicePack, ConsoleColor.Yellow, bracket: "[]", prefix: "Service pack:", suffix: ",");
135 135 ColorConsole.Write(System.Environment.OSVersion.VersionString, ConsoleColor.Yellow, bracket: "[]", prefix: "Version string:");
136 136 ColorConsole.WriteLine("");
  137 + ColorConsole.Write(Tools.OSFriendlyName(), ConsoleColor.Yellow, bracket: "[]", prefix: " Friendly name:");
  138 + ColorConsole.WriteLine("");
137 139 ColorConsole.WriteLine("");
138 140 }
139 141 }
  142 +
140 143 #region MaintenanceConsoleXmlProcessor class
141 144 public class MaintenanceConsoleXmlProcessor : XmlParser
142 145 {
... ...
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.0.1.0")]
36   -[assembly: AssemblyFileVersion("1.0.1.0")]
  35 +[assembly: AssemblyVersion("1.1.0.0")]
  36 +[assembly: AssemblyFileVersion("1.1.0.0")]
... ...
Vrh.Log4Pro.MaintenanceConsole/Vrh.Log4Pro.MaintenanceConsole.csproj
... ... @@ -215,6 +215,11 @@
215 215 <Reference Include="System.IO.FileSystem.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
216 216 <HintPath>..\packages\System.IO.FileSystem.Primitives.4.0.1\lib\net46\System.IO.FileSystem.Primitives.dll</HintPath>
217 217 </Reference>
  218 + <Reference Include="System.Linq.Expressions, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  219 + <HintPath>..\packages\System.Linq.Expressions.4.3.0\lib\net463\System.Linq.Expressions.dll</HintPath>
  220 + <Private>True</Private>
  221 + <Private>True</Private>
  222 + </Reference>
218 223 <Reference Include="System.Management" />
219 224 <Reference Include="System.Messaging" />
220 225 <Reference Include="System.Net.Http, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
... ...
Vrh.Log4Pro.MaintenanceConsole/packages.config
... ... @@ -39,7 +39,7 @@
39 39 <package id="System.IO.FileSystem" version="4.0.1" targetFramework="net462" />
40 40 <package id="System.IO.FileSystem.Primitives" version="4.0.1" targetFramework="net462" />
41 41 <package id="System.Linq" version="4.1.0" targetFramework="net462" requireReinstallation="true" />
42   - <package id="System.Linq.Expressions" version="4.1.0" targetFramework="net462" requireReinstallation="true" />
  42 + <package id="System.Linq.Expressions" version="4.3.0" targetFramework="net472" />
43 43 <package id="System.Management" version="5.0.0" targetFramework="net462" />
44 44 <package id="System.Net.Http" version="4.1.0" targetFramework="net462" />
45 45 <package id="System.Net.Primitives" version="4.0.11" targetFramework="net462" />
... ...