diff --git a/Tools/HashingCmdStart/HashingCmdStart.csproj b/Tools/HashingCmdStart/HashingCmdStart.csproj index 9fcebb397cf5049487e500b331ed850f47cbed4c..b8a4abbaa30bdefb1ae1d291ba4e4f0f27dfa9a8 100644 --- a/Tools/HashingCmdStart/HashingCmdStart.csproj +++ b/Tools/HashingCmdStart/HashingCmdStart.csproj @@ -8,4 +8,8 @@ <DefineConstants /> </PropertyGroup> + <ItemGroup> + <Compile Include="..\VECTOStart\StarterHelper.cs" Link="StarterHelper.cs" /> + </ItemGroup> + </Project> diff --git a/Tools/HashingCmdStart/Program.cs b/Tools/HashingCmdStart/Program.cs index 4ee38c806d52ec7f2ee2e774945c926e400537ee..f3b287ab1d002769cb532880115205f80372126c 100644 --- a/Tools/HashingCmdStart/Program.cs +++ b/Tools/HashingCmdStart/Program.cs @@ -1,65 +1,7 @@ -using System; -using Microsoft.Win32; -using System.Diagnostics; -using System.Reflection; -using System.IO; - -namespace TUGraz.VECTO +namespace TUGraz.VECTO { class Program { - static void Main() - { - var version = GetHighestNETVersion(); - Process.Start(new ProcessStartInfo($"{version}\\{Assembly.GetExecutingAssembly().GetName().Name}.exe") { - WorkingDirectory = Directory.GetCurrentDirectory() - }); - } - - private static string GetHighestNETVersion() - { - if (SupportsNet60()) { - return "net60"; - } - - if (SupportsNet48()) { - return "net48"; - } - - return "net45"; - } - - private static bool SupportsNet60() - { - try { - var p = Process.Start(new ProcessStartInfo("dotnet", "--list-runtimes") { - CreateNoWindow = true, - UseShellExecute = false, - RedirectStandardError = true, - RedirectStandardOutput = true - }); - - p.WaitForExit(); - var output = p.StandardOutput.ReadToEnd(); - return output.Contains("Microsoft.WindowsDesktop.App 6"); - } catch (Exception e) { - Console.WriteLine(e); - } - - return false; - } - - private static bool SupportsNet48() - { - const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"; - using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey)) { - if (ndpKey != null && ndpKey.GetValue("Release") != null) { - var releaseKey = (int)ndpKey.GetValue("Release"); - return releaseKey >= 528040; - } - - return false; - } - } + static void Main(string[] args) => StarterHelper.StartVECTO(args); } -} +} \ No newline at end of file diff --git a/Tools/HashingToolStart/HashingToolStart.csproj b/Tools/HashingToolStart/HashingToolStart.csproj index e3d1dcf88ad6968750da69b00fd4acc572fe495b..c1f363bb2227524a61d13f8ba908bdc184e2c5bf 100644 --- a/Tools/HashingToolStart/HashingToolStart.csproj +++ b/Tools/HashingToolStart/HashingToolStart.csproj @@ -8,4 +8,12 @@ <TargetFrameworks>net45</TargetFrameworks> <DefineConstants /> </PropertyGroup> + + <ItemGroup> + <Compile Include="..\VECTOStart\StarterHelper.cs" Link="StarterHelper.cs" /> + </ItemGroup> + + <ItemGroup> + <Reference Include="System.Windows.Forms" /> + </ItemGroup> </Project> diff --git a/Tools/HashingToolStart/Program.cs b/Tools/HashingToolStart/Program.cs index c02231108231f8e676d4c49d64708861628ef3af..6d55a719f74068db46301e4485e52d527b6ce2ba 100644 --- a/Tools/HashingToolStart/Program.cs +++ b/Tools/HashingToolStart/Program.cs @@ -1,66 +1,19 @@ -using System; -using Microsoft.Win32; -using System.Diagnostics; -using System.Reflection; -using System.IO; +using System.Windows.Forms; +using System; namespace TUGraz.VECTO { class Program { - static void Main() - { - var version = GetHighestNETVersion(); - Process.Start(new ProcessStartInfo($"{version}\\{Assembly.GetExecutingAssembly().GetName().Name}.exe") { - WorkingDirectory = Directory.GetCurrentDirectory() - }); - } - - private static string GetHighestNETVersion() - { - //todo mk2022-02-17 hashing tool currently only works under net45. this has to be fixed. - //if (SupportsNet60()) { - // return "net60"; - //} - - //if (SupportsNet48()) { - // return "net48"; - //} - - return "net45"; - } - - private static bool SupportsNet60() + static void Main(string[] args) { try { - var p = Process.Start(new ProcessStartInfo("dotnet", "--list-runtimes") { - CreateNoWindow = true, - UseShellExecute = false, - RedirectStandardError = true, - RedirectStandardOutput = true - }); - - p.WaitForExit(); - var output = p.StandardOutput.ReadToEnd(); - return output.Contains("Microsoft.WindowsDesktop.App 6"); + // mk20220707: hashing tool currently only works under net45, therefore we hardcoded the version + StarterHelper.StartVECTO(new[]{"net45"}); } catch (Exception e) { - Console.WriteLine(e); + MessageBox.Show(e.Message); } - - return false; } - private static bool SupportsNet48() - { - const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"; - using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey)) { - if (ndpKey != null && ndpKey.GetValue("Release") != null) { - var releaseKey = (int)ndpKey.GetValue("Release"); - return releaseKey >= 528040; - } - - return false; - } - } } -} +} \ No newline at end of file diff --git a/Tools/VECTOConsoleStart/Program.cs b/Tools/VECTOConsoleStart/Program.cs index 4ee38c806d52ec7f2ee2e774945c926e400537ee..178aabefbf8e59c15ecad4b119b343f94ccb3928 100644 --- a/Tools/VECTOConsoleStart/Program.cs +++ b/Tools/VECTOConsoleStart/Program.cs @@ -1,65 +1,7 @@ -using System; -using Microsoft.Win32; -using System.Diagnostics; -using System.Reflection; -using System.IO; - -namespace TUGraz.VECTO +namespace TUGraz.VECTO { class Program { - static void Main() - { - var version = GetHighestNETVersion(); - Process.Start(new ProcessStartInfo($"{version}\\{Assembly.GetExecutingAssembly().GetName().Name}.exe") { - WorkingDirectory = Directory.GetCurrentDirectory() - }); - } - - private static string GetHighestNETVersion() - { - if (SupportsNet60()) { - return "net60"; - } - - if (SupportsNet48()) { - return "net48"; - } - - return "net45"; - } - - private static bool SupportsNet60() - { - try { - var p = Process.Start(new ProcessStartInfo("dotnet", "--list-runtimes") { - CreateNoWindow = true, - UseShellExecute = false, - RedirectStandardError = true, - RedirectStandardOutput = true - }); - - p.WaitForExit(); - var output = p.StandardOutput.ReadToEnd(); - return output.Contains("Microsoft.WindowsDesktop.App 6"); - } catch (Exception e) { - Console.WriteLine(e); - } - - return false; - } - - private static bool SupportsNet48() - { - const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"; - using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey)) { - if (ndpKey != null && ndpKey.GetValue("Release") != null) { - var releaseKey = (int)ndpKey.GetValue("Release"); - return releaseKey >= 528040; - } - - return false; - } - } + static void Main(string[] args) => StarterHelper.StartVECTO(args); } } diff --git a/Tools/VECTOConsoleStart/VECTOConsoleStart.csproj b/Tools/VECTOConsoleStart/VECTOConsoleStart.csproj index eb31dee287a0b3b2fdcfb7d6069dfdfbde1f7296..a87fbbd03e9cd78f53ccf2b74f476cd77ef64b4b 100644 --- a/Tools/VECTOConsoleStart/VECTOConsoleStart.csproj +++ b/Tools/VECTOConsoleStart/VECTOConsoleStart.csproj @@ -9,4 +9,12 @@ <DefineConstants /> </PropertyGroup> + <ItemGroup> + <Compile Include="..\VECTOStart\StarterHelper.cs" Link="StarterHelper.cs" /> + </ItemGroup> + + <ItemGroup> + <Reference Include="System.Windows.Forms" /> + </ItemGroup> + </Project> diff --git a/Tools/VECTOMultistageStart/Program.cs b/Tools/VECTOMultistageStart/Program.cs index 2dce9c985988ae71a5b9ae7bff4d3f32ca46718a..aeb288b8560de2928c7339bc928501f4126b11b7 100644 --- a/Tools/VECTOMultistageStart/Program.cs +++ b/Tools/VECTOMultistageStart/Program.cs @@ -1,47 +1,18 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Reflection; +using System.Windows.Forms; +using System; namespace TUGraz.VECTO { class Program { - static void Main() - { - var version = GetHighestNETVersion(); - Process.Start(new ProcessStartInfo($"{version}\\{Assembly.GetExecutingAssembly().GetName().Name}.exe") { - WorkingDirectory = Directory.GetCurrentDirectory() - }); - } - - private static string GetHighestNETVersion() - { - if (SupportsNet60()) { - return "net60"; - } - - return "net48"; - } - - private static bool SupportsNet60() + static void Main(string[] args) { try { - var p = Process.Start(new ProcessStartInfo("dotnet", "--list-runtimes") { - CreateNoWindow = true, - UseShellExecute = false, - RedirectStandardError = true, - RedirectStandardOutput = true - }); - - p.WaitForExit(); - var output = p.StandardOutput.ReadToEnd(); - return output.Contains("Microsoft.WindowsDesktop.App 6"); + StarterHelper.StartVECTO(args, "net48", "net60"); } catch (Exception e) { - Console.WriteLine(e); + MessageBox.Show(e.Message); } - - return false; } + } } diff --git a/Tools/VECTOMultistageStart/VECTOMultistage.csproj b/Tools/VECTOMultistageStart/VECTOMultistage.csproj index 06003236964e93d1b1df5cbf892ea81e74adc5f9..da3310873330bb510cc8a4fbb7f13b06a93bf3a5 100644 --- a/Tools/VECTOMultistageStart/VECTOMultistage.csproj +++ b/Tools/VECTOMultistageStart/VECTOMultistage.csproj @@ -9,4 +9,12 @@ <DefineConstants /> </PropertyGroup> + <ItemGroup> + <Compile Include="..\VECTOStart\StarterHelper.cs" Link="StarterHelper.cs" /> + </ItemGroup> + + <ItemGroup> + <Reference Include="System.Windows.Forms" /> + </ItemGroup> + </Project> diff --git a/Tools/VECTOStart/Program.cs b/Tools/VECTOStart/Program.cs index e5896e5d2f72524d42735eed5cff5d2af1143e1e..34b6e45df9c3dde2df7eafbbcce41beaf4fdd926 100644 --- a/Tools/VECTOStart/Program.cs +++ b/Tools/VECTOStart/Program.cs @@ -1,64 +1,16 @@ using System; -using Microsoft.Win32; -using System.Diagnostics; -using System.IO; -using System.Reflection; +using System.Windows.Forms; namespace TUGraz.VECTO { class Program { - static void Main() - { - var version = GetHighestNETVersion(); - Process.Start(new ProcessStartInfo($"{version}\\{Assembly.GetExecutingAssembly().GetName().Name}.exe") { - WorkingDirectory = Directory.GetCurrentDirectory() - }); - } - - private static string GetHighestNETVersion() - { - if (SupportsNet60()) { - return "net60"; - } - - if (SupportsNet48()) { - return "net48"; - } - - return "net45"; - } - - private static bool SupportsNet60() + static void Main(string[] args) { try { - var p = Process.Start(new ProcessStartInfo("dotnet", "--list-runtimes") { - CreateNoWindow = true, - UseShellExecute = false, - RedirectStandardError = true, - RedirectStandardOutput = true - }); - - p.WaitForExit(); - var output = p.StandardOutput.ReadToEnd(); - return output.Contains("Microsoft.WindowsDesktop.App 6"); + StarterHelper.StartVECTO(args); } catch (Exception e) { - Console.WriteLine(e); - } - - return false; - } - - private static bool SupportsNet48() - { - const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"; - using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey)) { - if (ndpKey != null && ndpKey.GetValue("Release") != null) { - var releaseKey = (int)ndpKey.GetValue("Release"); - return releaseKey >= 528040; - } - - return false; + MessageBox.Show(e.Message); } } } diff --git a/Tools/VECTOStart/StarterHelper.cs b/Tools/VECTOStart/StarterHelper.cs new file mode 100644 index 0000000000000000000000000000000000000000..40e4bab5374630491362afb3783fe97be601ce86 --- /dev/null +++ b/Tools/VECTOStart/StarterHelper.cs @@ -0,0 +1,92 @@ +using Microsoft.Win32; +using System; +using System.Collections; +using System.Diagnostics; +using System.IO; +using System.Reflection; + +namespace TUGraz.VECTO +{ + class StarterHelper + { + public static void StartVECTO(string[] args, params string[] validVersions) + { + var path = "No path found."; + string version = "No version found."; + if (validVersions is null || validVersions.Length == 0) { + validVersions = new[] { "net45", "net48", "net60" }; + } + try { + if (args.Length > 0) { + version = args[0].ToLower(); + } else { + version = GetHighestNETVersion(); + } + + path = $"{version}\\{Assembly.GetExecutingAssembly().GetName().Name}.exe"; + Process.Start(new ProcessStartInfo(path) { + WorkingDirectory = Directory.GetCurrentDirectory() + }); + ValidateVersion(version, validVersions); + } catch (Exception e) { + var message = $"Error during starting VECTO.\nDetected .NET version: {version}\nTried to open path: {path}\n{e.Message}"; + File.AppendAllText("LOG.txt", $"{DateTime.Now} {message}\n"); + Console.WriteLine(message); + throw new Exception(message); + } + } + + private static void ValidateVersion(string version, params string[] validVersions) + { + if (!((IList)validVersions).Contains(version)) + throw new Exception($"Invalid .NET Version supplied. Only the following values are valid: {string.Join(", ", validVersions)}"); + } + + private static string GetHighestNETVersion() + { + if (SupportsNet60()) { + return "net60"; + } + + if (SupportsNet48()) { + return "net48"; + } + + return "net45"; + } + + private static bool SupportsNet60() + { + try { + var p = Process.Start(new ProcessStartInfo("dotnet", "--list-runtimes") { + CreateNoWindow = true, + UseShellExecute = false, + RedirectStandardError = true, + RedirectStandardOutput = true + }); + + p.WaitForExit(); + var output = p.StandardOutput.ReadToEnd(); + return output.Contains("Microsoft.WindowsDesktop.App 6"); + } catch (Exception e) { + Console.WriteLine(e); + } + + return false; + } + + private static bool SupportsNet48() + { + const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"; + using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey)) { + if (ndpKey != null && ndpKey.GetValue("Release") != null) { + var releaseKey = (int)ndpKey.GetValue("Release"); + return releaseKey >= 528040; + } + + return false; + } + } + + } +} diff --git a/Tools/VECTOStart/VECTOStart.csproj b/Tools/VECTOStart/VECTOStart.csproj index c4cdcdedd451f9f16406bf197f3157ce195d5910..176ff3fc47fc375c2433a24d2546b29532da300d 100644 --- a/Tools/VECTOStart/VECTOStart.csproj +++ b/Tools/VECTOStart/VECTOStart.csproj @@ -10,4 +10,8 @@ <DefineConstants /> </PropertyGroup> + <ItemGroup> + <Reference Include="System.Windows.Forms" /> + </ItemGroup> + </Project> diff --git a/VECTO/GUI/AboutBox.vb b/VECTO/GUI/AboutBox.vb index c6b819ac8a9f344c92a4ae03cff6f8dc07c6ca1f..ec6c41301123c7e08075ee239d1826296705a321 100644 --- a/VECTO/GUI/AboutBox.vb +++ b/VECTO/GUI/AboutBox.vb @@ -15,7 +15,11 @@ Imports TUGraz.VectoCore.Utils ''' </summary> Public Class AboutBox Private Sub F10_AboutBox_Load(sender As Object, e As EventArgs) Handles MyBase.Load - Text = "VECTO " & VECTOvers & " / VectoCore" & VectoSimulationCore.BranchSuffix & " " & COREvers +#If NET47_OR_GREATER Or NET5_0_OR_GREATER Then + Text = "VECTO " & VECTOvers & " / VectoCore" & VectoSimulationCore.BranchSuffix & " " & COREvers & " / " & Runtime.InteropServices.RuntimeInformation.FrameworkDescription +#Else + Text = "VECTO " & VECTOvers & " / VectoCore" & VectoSimulationCore.BranchSuffix & " " & COREvers & " / .NET Framework " & If(Environment.Version.Revision < 42000, "4.5", "4.6") +#End If End Sub Private Sub LinkLabel1_LinkClicked_1(sender As Object, e As LinkLabelLinkClickedEventArgs) _ diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs index 3465fa90b62566887383800703b6b2e56988954a..c617ef869e79f937afe2e7001cdd4006eca09d62 100644 --- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs +++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/BusAuxiliariesAdapter.cs @@ -31,6 +31,7 @@ using System; using TUGraz.VectoCommon.BusAuxiliaries; +using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; using TUGraz.VectoCore.Models.BusAuxiliaries; @@ -378,6 +379,10 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl var missingEnergy = energyDemand - batEnergy; if (AuxCfg.ElectricalUserInputsConfig.ConnectESToREESS) { + if (DCDCConverter is null) { + throw new VectoException("DCDCConverter is missing: The current configuration for the bus auxiliaries " + + "requires a DCDCConverter (ES supply from HEV REESS is activated)."); + } DCDCConverter.ConsumerEnergy(-missingEnergy, dryRun); } else { if (!dryRun) {