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

Skip to content
Snippets Groups Projects
Commit d345ac2d authored by Michael KRISPER's avatar Michael KRISPER
Browse files

errors and warnings in gui and console

parent a8d985cb
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
......@@ -94,6 +94,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NLog.4.2.0\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
......
......@@ -2,4 +2,5 @@
<packages>
<package id="iTextSharp" version="5.5.7" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="NLog" version="4.2.0" targetFramework="net45" />
</packages>
\ No newline at end of file
......@@ -38,6 +38,7 @@ using System.Reflection;
using System.Threading;
using NLog;
using NLog.Config;
using NLog.Targets;
using TUGraz.VectoCore.Configuration;
using TUGraz.VectoCore.InputData.FileIO.JSON;
using TUGraz.VectoCore.Models.Simulation.Impl;
......@@ -48,6 +49,8 @@ namespace VectoConsole
{
internal static class Program
{
public static List<string> WarningMessages = new List<string>();
private static int _numLines;
private static int ProgessCounter { get; set; }
......@@ -119,9 +122,21 @@ Examples:
}
var config = LogManager.Configuration;
//config.LoggingRules.Add(new LoggingRule("*", logLevel, config.FindTargetByName("ConsoleLogger")));
config.LoggingRules.Add(new LoggingRule("*", logLevel, config.FindTargetByName("LogFile")));
if (logLevel > LogLevel.Warn) {
var methodCallTarget = new MethodCallTarget {
ClassName = "VectoConsole.Program, vectocmd",
MethodName = "LogWarning",
Name = "WarningLogger"
};
methodCallTarget.Parameters.Add(new MethodCallParameter("${level}"));
methodCallTarget.Parameters.Add(new MethodCallParameter("${message}"));
config.LoggingRules.Add(new LoggingRule("*", LogLevel.Warn, methodCallTarget));
}
LogManager.Configuration = config;
// todo mk 2016-03-02: trace listener still needed?
Trace.Listeners.Add(new ConsoleTraceListener(true));
if (args.Contains("-V") || debugEnabled) {
......@@ -140,8 +155,6 @@ Examples:
var timings = new Dictionary<string, double>();
// process the file list and start simulation
//var sumFileName = Path.Combine(Path.GetDirectoryName(fileList.First()) ?? "",
// Path.GetFileNameWithoutExtension(fileList.First()) + Constants.FileExtensions.SumFile);
var fileWriter = new FileOutputWriter(fileList.First());
var sumWriter = new SummaryDataContainer(fileWriter);
_jobContainer = new JobContainer(sumWriter);
......@@ -154,9 +167,19 @@ Examples:
Console.ResetColor();
}
Console.WriteLine(@"Reading Job Files");
stopWatch.Start();
foreach (var file in fileList.Where(f => Path.GetExtension(f) == Constants.FileExtensions.VectoJobFile)) {
var jobFiles = fileList.Where(f => Path.GetExtension(f) == Constants.FileExtensions.VectoJobFile).ToList();
if (!jobFiles.Any()) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(@"No Job files found. Please restart the application with a valid '.vecto' file.");
Console.ResetColor();
return 1;
}
foreach (var file in jobFiles) {
Console.WriteLine(@"Reading job: " + file);
var dataProvider = JSONInputDataFactory.ReadJsonJob(file);
var runsFactory = new SimulatorFactory(mode, dataProvider, fileWriter);
......@@ -170,7 +193,6 @@ Examples:
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(@"Detected cycles:");
Console.ResetColor();
var cycles = _jobContainer.GetCycleTypes().ToList();
foreach (var cycle in _jobContainer.GetCycleTypes()) {
Console.WriteLine(@" {0}: {1}", cycle.Name, cycle.CycleType);
}
......@@ -188,6 +210,9 @@ Examples:
}
Console.ResetColor();
Console.WriteLine();
DisplayWarnings();
Console.WriteLine();
stopWatch.Start();
_jobContainer.Execute(!debugEnabled);
......@@ -205,20 +230,48 @@ Examples:
stopWatch.Stop();
timings.Add("Simulation runs", stopWatch.Elapsed.TotalMilliseconds);
PrintProgress(_jobContainer.GetProgress(), args.Contains("-t"));
if (args.Contains("-t")) {
PrintTimings(timings);
}
DisplayWarnings();
} catch (Exception e) {
Console.Error.WriteLine(e.Message);
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine("Please see log-file for further details (logs/log.txt)");
Console.Error.WriteLine(e.Message);
Console.ResetColor();
Console.Error.WriteLine("Please see log-file for further details (logs/log.txt)");
Environment.ExitCode = Environment.ExitCode != 0 ? Environment.ExitCode : 1;
}
Console.ReadKey();
return Environment.ExitCode;
}
private static void DisplayWarnings()
{
if (WarningMessages.Any()) {
Console.ForegroundColor = ConsoleColor.Yellow;
foreach (var message in WarningMessages) {
Console.Error.WriteLine(message);
}
Console.ResetColor();
}
WarningMessages.Clear();
}
public static void LogWarning(string level, string message)
{
if (level == "Warn") {
WarningMessages.Add(message);
}
}
private static void ShowVersionInformation()
{
var vectodll = AssemblyName.GetAssemblyName("VectoCore.dll");
......@@ -253,7 +306,14 @@ Examples:
var spinner = "/-\\|"[ProgessCounter++ % 4];
var bar = new string('#', (int)(sumProgress * 100.0 / 2));
Console.WriteLine(@" {2} [{1,-50}] [{0,7:P}]", sumProgress, bar, spinner);
_numLines++;
if (WarningMessages.Any()){
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(@"Warnings: {0,5}", WarningMessages.Count);
Console.ResetColor();
}
_numLines +=2;
}
private static void PrintTimings(Dictionary<string, double> timings)
......
......@@ -62,13 +62,22 @@ namespace TUGraz.VectoCore.Models.Declaration
if (grossVehicleMassRating < 7.5.SI<Ton>()) {
throw new VectoException("Gross vehicle mass must be greater than 7.5 tons");
}
var row =
SegmentTable.Rows.Cast<DataRow>().First(r => r.Field<string>("valid") == "1"
&& r.Field<string>("vehiclecategory") == vehicleCategory.ToString()
&& r.Field<string>("axleconf.") == axleConfiguration.GetName()
&& r.ParseDouble("gvw_min").SI<Ton>() < grossVehicleMassRating
&& r.ParseDouble("gvw_max").SI<Ton>() >= grossVehicleMassRating
DataRow row;
try {
row = SegmentTable.Rows.Cast<DataRow>().First(r => r.Field<string>("valid") == "1"
&& r.Field<string>("vehiclecategory") == vehicleCategory.ToString()
&& r.Field<string>("axleconf.") == axleConfiguration.GetName()
&& r.ParseDouble("gvw_min").SI<Ton>() < grossVehicleMassRating
&& r.ParseDouble("gvw_max").SI<Ton>() >= grossVehicleMassRating
);
} catch (InvalidOperationException e) {
var errorMessage = string.Format(
"ERROR: Could not find the declaration segment for vehicle. Category: {0}, AxleConfiguration: {1}, GrossVehicleMassRating: {2}",
vehicleCategory, axleConfiguration.GetName(), grossVehicleMassRating);
Log.Fatal(errorMessage);
throw new VectoException(errorMessage, e);
}
var segment = new Segment {
GrossVehicleWeightMin = row.ParseDouble("gvw_min").SI().Ton.Cast<Kilogram>(),
GrossVehicleWeightMax = row.ParseDouble("gvw_max").SI().Ton.Cast<Kilogram>(),
......
......@@ -166,12 +166,11 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
container[ModalResultField.P_trac] = CurrentState.VehicleTractionForce * averageVelocity;
// sanity check: is the vehicle in step with the cycle?
if (container[ModalResultField.dist] == DBNull.Value) {
Log.Warn("distance field is not set!");
Log.Warn("Distance field is not set!");
} else {
var distance = (SI)container[ModalResultField.dist];
if (!distance.IsEqual(CurrentState.Distance, 1e-12.SI<Meter>())) {
Log.Warn("distance diverges: {0}, distance: {1}", (distance - CurrentState.Distance).Value(),
distance);
Log.Warn("Vehicle Distance diverges from Cycle by {0} [m]. Distance: {1}", (distance - CurrentState.Distance).Value(), distance);
}
}
}
......
......@@ -135,7 +135,7 @@ namespace TUGraz.VectoCore.Utils
if (!string.IsNullOrWhiteSpace(message)) {
if (!skip(list[index]) || skip(list[index + 1])) {
LogManager.GetLogger(typeof(T).ToString()).Error(message);
LogManager.GetLogger(typeof(T).ToString()).Warn(message);
}
}
......
{
"Header": {
"CreatedBy": " ()",
"Date": "3/4/2015 2:09:13 PM",
"AppVersion": "2.0.4-beta3",
"FileVersion": 2
},
"Body": {
"SavedInDeclMode": false,
"VehicleFile": "../Components/24t Coach.vveh",
"EngineFile": "../Components/24t Coach.veng",
"GearboxFile": "../Components/24t Coach_smallLossMap.vgbx",
"Cycles": [
"../Cycles/Coach_24t_xshort.vdri"
],
"Aux": [
{
"ID": "ALT1",
"Type": "Alternator",
"Path": "../Components/24t_Coach_ALT.vaux",
"Technology": ""
},
{
"ID": "ALT2",
"Type": "Alternator",
"Path": "../Components/24t_Coach_ALT.vaux",
"Technology": ""
},
{
"ID": "ALT3",
"Type": "Alternator",
"Path": "../Components/24t_Coach_ALT.vaux",
"Technology": ""
}
],
"VACC": "../Components/Coach.vacc",
"EngineOnlyMode": false,
"StartStop": {
"Enabled": false,
"MaxSpeed": 5.0,
"MinTime": 0.0,
"Delay": 0
},
"LAC": {
"Enabled": true,
"Dec": -0.5,
"MinSpeed": 50.0
},
"OverSpeedEcoRoll": {
"Mode": "OverSpeed",
"MinSpeed": 70.0,
"OverSpeed": 5.0,
"UnderSpeed": 5.0
}
}
}
\ No newline at end of file
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