diff --git a/src/AzureIoTHub.Portal/Client/Validators/DeviceDetailsValidator.cs b/src/AzureIoTHub.Portal/Client/Validators/DeviceDetailsValidator.cs index 25faede43..57bfb7707 100644 --- a/src/AzureIoTHub.Portal/Client/Validators/DeviceDetailsValidator.cs +++ b/src/AzureIoTHub.Portal/Client/Validators/DeviceDetailsValidator.cs @@ -18,12 +18,22 @@ public DeviceDetailsValidator() .NotEmpty() .WithMessage("ModelId is required."); - _ = RuleFor(x => x.DeviceID) + When(x => x.IsLoraWan, () => + { + _ = RuleFor(x => x.DeviceID) + .NotEmpty() + .Length(1, 128) + .Matches("[A-Z0-9]{16}") + .WithMessage("DeviceID is required. It should be a 16 bit hex string."); + }).Otherwise(() => + { + _ = RuleFor(x => x.DeviceID) .NotEmpty() .WithMessage("DeviceID is required.") .Length(1, 128) .Matches("[a-zA-Z0-9\\-.+%_#*?!(),:=@$']") .WithMessage("DeviceID is required. It should be a case-sensitive string (up to 128 characters long) of ASCII 7-bit alphanumeric characters plus certain special characters: - . + % _ # * ? ! ( ) , : = @ $ '."); + }); } } } diff --git a/src/AzureIoTHub.Portal/Client/Validators/LoRaDeviceDetailsValidator.cs b/src/AzureIoTHub.Portal/Client/Validators/LoRaDeviceDetailsValidator.cs index 6b85bfd6b..20b429ce7 100644 --- a/src/AzureIoTHub.Portal/Client/Validators/LoRaDeviceDetailsValidator.cs +++ b/src/AzureIoTHub.Portal/Client/Validators/LoRaDeviceDetailsValidator.cs @@ -42,12 +42,6 @@ public LoRaDeviceDetailsValidator() .NotEmpty() .When(x => !x.UseOTAA) .WithMessage("DevAddr is required."); - - _ = RuleFor(x => x.DeviceID) - .NotEmpty() - .Length(1, 128) - .Matches("[A-Z0-9]{16}") - .WithMessage("DeviceID is required. It should be a 16 bit hex string."); } } } diff --git a/src/AzureIoTHub.Portal/Shared/Models/v1.0/DeviceDetails.cs b/src/AzureIoTHub.Portal/Shared/Models/v1.0/DeviceDetails.cs index 2de7ffb73..9ad9c5a3a 100644 --- a/src/AzureIoTHub.Portal/Shared/Models/v1.0/DeviceDetails.cs +++ b/src/AzureIoTHub.Portal/Shared/Models/v1.0/DeviceDetails.cs @@ -56,5 +56,10 @@ public class DeviceDetails /// List of custom device tags and their values. /// public Dictionary Tags { get; set; } = new(); + + /// + /// true if this instance is lorawan; otherwise, false. + /// + public virtual bool IsLoraWan { get; private set; } } } diff --git a/src/AzureIoTHub.Portal/Shared/Models/v1.0/LoRaWAN/LoRaDeviceDetails.cs b/src/AzureIoTHub.Portal/Shared/Models/v1.0/LoRaWAN/LoRaDeviceDetails.cs index f02e85327..ace9fc887 100644 --- a/src/AzureIoTHub.Portal/Shared/Models/v1.0/LoRaWAN/LoRaDeviceDetails.cs +++ b/src/AzureIoTHub.Portal/Shared/Models/v1.0/LoRaWAN/LoRaDeviceDetails.cs @@ -68,5 +68,7 @@ public class LoRaDeviceDetails : LoRaDeviceBase /// The Device Current RXDelay. /// public string ReportedRXDelay { get; set; } + + public override bool IsLoraWan => true; } }