From b8f5accc650fd82029073e03df3eead87a4bad6f Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Tue, 19 Apr 2016 15:38:42 +0200 Subject: [PATCH] json input data handling: check if there are any gears before reading axle gear --- .../InputData/FileIO/JSON/JSONGearboxData.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs index 026a75c3cb..79efc445ba 100644 --- a/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs +++ b/VectoCore/VectoCore/InputData/FileIO/JSON/JSONGearboxData.cs @@ -33,6 +33,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; using Newtonsoft.Json.Linq; +using TUGraz.VectoCommon.Exceptions; using TUGraz.VectoCommon.InputData; using TUGraz.VectoCommon.Models; using TUGraz.VectoCommon.Utils; @@ -76,15 +77,26 @@ namespace TUGraz.VectoCore.InputData.FileIO.JSON public virtual double Ratio { - get { return Body.GetEx(JsonKeys.Gearbox_Gears)[0].GetEx<double>(JsonKeys.Gearbox_Gear_Ratio); } + get + { + var gears = Body.GetEx(JsonKeys.Gearbox_Gears); + if (!gears.Any()) { + throw new VectoSimulationException("At least one Gear-Entry must be defined in Gearbox!"); + } + return gears[0].GetEx<double>(JsonKeys.Gearbox_Gear_Ratio); + } } public DataTable LossMap { get { + var gears = Body.GetEx(JsonKeys.Gearbox_Gears); + if (!gears.Any()) { + throw new VectoSimulationException("At least one Gear-Entry must be defined in Gearbox!"); + } return ReadTableData( - Body.GetEx(JsonKeys.Gearbox_Gears)[0].GetEx<string>(JsonKeys.Gearbox_Gear_LossMapFile), "AxleGear"); + gears[0].GetEx<string>(JsonKeys.Gearbox_Gear_LossMapFile), "AxleGear"); } } -- GitLab