From bc4a4c456c73d664be97c03610859a0f5f1ee6a1 Mon Sep 17 00:00:00 2001 From: Markus Quaritsch <markus.quaritsch@tugraz.at> Date: Mon, 25 Sep 2017 09:10:17 +0200 Subject: [PATCH] add validation of tyre dimension (declaration mode) --- .../VectoCore/Models/Declaration/Axle.cs | 71 +++++++++++-------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/VectoCore/VectoCore/Models/Declaration/Axle.cs b/VectoCore/VectoCore/Models/Declaration/Axle.cs index 371ac5231a..4ab3df7063 100644 --- a/VectoCore/VectoCore/Models/Declaration/Axle.cs +++ b/VectoCore/VectoCore/Models/Declaration/Axle.cs @@ -29,31 +29,46 @@ * Martin Rexeis, rexeis@ivt.tugraz.at, IVT, Graz University of Technology */ -using System.ComponentModel.DataAnnotations; -using TUGraz.VectoCommon.Models; -using TUGraz.VectoCommon.Utils; -using TUGraz.VectoCore.Models.SimulationComponent.Data; - -namespace TUGraz.VectoCore.Models.Declaration -{ - public class Axle : SimulationComponentData - { - public string WheelsDimension { get; internal set; } - - [Required, SIRange(0, 100)] - public KilogramSquareMeter Inertia { get; internal set; } - - [Required, SIRange(0.003, 0.015)] - public double RollResistanceCoefficient { get; internal set; } - - [Required, SIRange(500, 100000)] - public Newton TyreTestLoad { get; internal set; } - - [Required, SIRange(0, 1, ExecutionMode.Engineering), SIRange(double.MinValue, 1, ExecutionMode.Declaration)] - public double AxleWeightShare { get; internal set; } - - public bool TwinTyres { get; internal set; } - - public AxleType AxleType { get; internal set; } - } -} \ No newline at end of file +using System; +using System.ComponentModel.DataAnnotations; +using TUGraz.VectoCommon.Models; +using TUGraz.VectoCommon.Utils; +using TUGraz.VectoCore.Models.SimulationComponent.Data; + +namespace TUGraz.VectoCore.Models.Declaration +{ + [CustomValidation(typeof(Axle), "ValidateAxleData")] + public class Axle : SimulationComponentData + { + public string WheelsDimension { get; internal set; } + + [Required, SIRange(0, 100)] + public KilogramSquareMeter Inertia { get; internal set; } + + [Required, SIRange(0.003, 0.015)] + public double RollResistanceCoefficient { get; internal set; } + + [Required, SIRange(500, 100000)] + public Newton TyreTestLoad { get; internal set; } + + [Required, SIRange(0, 1, ExecutionMode.Engineering), SIRange(double.MinValue, 1, ExecutionMode.Declaration)] + public double AxleWeightShare { get; internal set; } + + public bool TwinTyres { get; internal set; } + + public AxleType AxleType { get; internal set; } + + public static ValidationResult ValidateAxleData(Axle axle, ValidationContext validationContext) + { + var execMode = GetExecutionMode(validationContext); + if (execMode == ExecutionMode.Engineering) + return ValidationResult.Success; + try { + DeclarationData.Wheels.Lookup(axle.WheelsDimension); + } catch (Exception) { + return new ValidationResult(string.Format("Unknown Tyre dimenstion '{0}'", axle.WheelsDimension)); + } + return ValidationResult.Success; + } + } +} -- GitLab