Skip to content

Commit

Permalink
Modification validator
Browse files Browse the repository at this point in the history
  • Loading branch information
crib authored and audserraCGI committed Jul 18, 2022
1 parent bae9886 commit bec1941
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: - . + % _ # * ? ! ( ) , : = @ $ '.");
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
}
5 changes: 5 additions & 0 deletions src/AzureIoTHub.Portal/Shared/Models/v1.0/DeviceDetails.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,10 @@ public class DeviceDetails
/// List of custom device tags and their values.
/// </summary>
public Dictionary<string, string> Tags { get; set; } = new();

/// <summary>
/// <c>true</c> if this instance is lorawan; otherwise, <c>false</c>.
/// </summary>
public virtual bool IsLoraWan { get; private set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,7 @@ public class LoRaDeviceDetails : LoRaDeviceBase
/// The Device Current RXDelay.
/// </summary>
public string ReportedRXDelay { get; set; }

public override bool IsLoraWan => true;
}
}

0 comments on commit bec1941

Please sign in to comment.