Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 3061fc15 authored by Michael KRISPER's avatar Michael KRISPER Committed by Markus Quaritsch
Browse files

Pull request #241: Bugfix/VECTO-1618 multiplatform working dir

Merge in VECTO/vecto-dev from VECTO/mk_vecto-dev:bugfix/VECTO-1618-multiplatform-working-dir to develop

* commit '6f0ad65f':
  StarterHelper: Minor changes
  StarterHelper: corrected check for empty params
  HashingToolStart: Only start with net45
  StarterHelper: Removed dependency to windows.Forms (for MessageBox)
  VECTO Starters: Refactored Methods to avoid code duplication
  VECTOStart now prints an error if the start failed.
  AboutBox: Now shows the .net version for older frameworks also (RuntimeInformation was only added with 4.7, and previously Environment.Version was used)
  AboutBox: Display the .NET version in title
  VECTOStart: Added argument to manually set the .NET version
  BusAuxiliariesAdapter: Better Error Message if ES supply from REESS is activated but no DCDCConverter is installed.
parents 010f1836 6f0ad65f
No related branches found
No related tags found
No related merge requests found
Showing with 156 additions and 263 deletions
......@@ -8,4 +8,8 @@
<DefineConstants />
</PropertyGroup>
<ItemGroup>
<Compile Include="..\VECTOStart\StarterHelper.cs" Link="StarterHelper.cs" />
</ItemGroup>
</Project>
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
......@@ -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>
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
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);
}
}
......@@ -9,4 +9,12 @@
<DefineConstants />
</PropertyGroup>
<ItemGroup>
<Compile Include="..\VECTOStart\StarterHelper.cs" Link="StarterHelper.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Windows.Forms" />
</ItemGroup>
</Project>
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;
}
}
}
......@@ -9,4 +9,12 @@
<DefineConstants />
</PropertyGroup>
<ItemGroup>
<Compile Include="..\VECTOStart\StarterHelper.cs" Link="StarterHelper.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Windows.Forms" />
</ItemGroup>
</Project>
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);
}
}
}
......
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;
}
}
}
}
......@@ -10,4 +10,8 @@
<DefineConstants />
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Windows.Forms" />
</ItemGroup>
</Project>
......@@ -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) _
......
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment