init
This commit is contained in:
36
Common/DTS.Common/Validators/CANArbBaseBitrateValidator.cs
Normal file
36
Common/DTS.Common/Validators/CANArbBaseBitrateValidator.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using DTS.Common.SharedResource.Strings;
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
using DTS.Common.Constant;
|
||||
|
||||
namespace DTS.Common.Validators
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S101:Types should be named in PascalCase", Justification = "acronyms")]
|
||||
public class CANArbBaseBitrateValidator : ValidationRule
|
||||
{
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
||||
{
|
||||
if (value is string s)
|
||||
{
|
||||
if (!long.TryParse(s, out var temp))
|
||||
{
|
||||
return new ValidationResult(false, StringResources.InvalidFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Since the Arb/Base Bitrate min/max is different for FD vs. non-FD CANs, use the widest range.
|
||||
if (temp > EmbeddedSensors.CANFD_ARB_BASE_BITRATE_MAX)
|
||||
{
|
||||
return new ValidationResult(false, $"{StringResources.MaxValueIs}{EmbeddedSensors.CANFD_ARB_BASE_BITRATE_MAX}");
|
||||
}
|
||||
if (temp < EmbeddedSensors.NON_CANFD_ARB_BASE_BITRATE_MIN)
|
||||
{
|
||||
return new ValidationResult(false, $"{StringResources.MinValueIs}{EmbeddedSensors.NON_CANFD_ARB_BASE_BITRATE_MIN}");
|
||||
}
|
||||
return new ValidationResult(true, null);
|
||||
}
|
||||
}
|
||||
return new ValidationResult(false, StringResources.InvalidFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
Common/DTS.Common/Validators/SensitivityValidator.cs
Normal file
29
Common/DTS.Common/Validators/SensitivityValidator.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using DTS.Common.SharedResource.Strings;
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace DTS.Common.Validators
|
||||
{
|
||||
public class SensitivityValidator : ValidationRule
|
||||
{
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
||||
{
|
||||
if (value is string s)
|
||||
{
|
||||
if (!double.TryParse(s, out var d))
|
||||
{
|
||||
return new ValidationResult(false, StringResources.InvalidFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (0D.Equals(d))
|
||||
{
|
||||
return new ValidationResult(false, StringResources.SensitivityCanNotBeZero);
|
||||
}
|
||||
return new ValidationResult(true, null);
|
||||
}
|
||||
}
|
||||
return new ValidationResult(false, StringResources.InvalidFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Common/DTS.Common/Validators/UARTBAUDRateValidator.cs
Normal file
34
Common/DTS.Common/Validators/UARTBAUDRateValidator.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using DTS.Common.SharedResource.Strings;
|
||||
using System.Globalization;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace DTS.Common.Validators
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Minor Code Smell", "S101:Types should be named in PascalCase", Justification = "acronyms")]
|
||||
public class UARTBAUDRateValidator : ValidationRule
|
||||
{
|
||||
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
|
||||
{
|
||||
if (value is string s)
|
||||
{
|
||||
if (!long.TryParse(s, out var temp))
|
||||
{
|
||||
return new ValidationResult(false, StringResources.InvalidFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (temp > Constant.EmbeddedSensors.BAUD_RATE_MAX)
|
||||
{
|
||||
return new ValidationResult(false, $"{StringResources.MaxValueIs}{Constant.EmbeddedSensors.BAUD_RATE_MAX}");
|
||||
}
|
||||
if ( temp < Constant.EmbeddedSensors.BAUD_RATE_MIN)
|
||||
{
|
||||
return new ValidationResult(false, $"{StringResources.MinValueIs}{Constant.EmbeddedSensors.BAUD_RATE_MIN}");
|
||||
}
|
||||
return new ValidationResult(true, null);
|
||||
}
|
||||
}
|
||||
return new ValidationResult(false, StringResources.InvalidFormat);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user