update
This commit is contained in:
@@ -132,17 +132,17 @@
|
||||
|
||||
try
|
||||
{
|
||||
using var doc = JsonDocument.Parse(JsonText);
|
||||
var root = doc.RootElement;
|
||||
|
||||
// ===== BASIC STRUCTURE CHECK =====
|
||||
if (!root.TryGetProperty("nodes", out _) ||
|
||||
!root.TryGetProperty("edges", out _))
|
||||
var order = JsonSerializer.Deserialize<OrderMsg>(JsonText, new JsonSerializerOptions
|
||||
{
|
||||
throw new Exception("Missing 'nodes' or 'edges' field.");
|
||||
WriteIndented = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
});
|
||||
if(order is null)
|
||||
{
|
||||
ShowWarning = true;
|
||||
ErrorMessage = "Can not convert file to Order message";
|
||||
return;
|
||||
}
|
||||
|
||||
var order = OrderMessage.FromSchemaObject(root);
|
||||
ValidateOrder(order);
|
||||
|
||||
MudDialog.Close(DialogResult.Ok(order));
|
||||
@@ -160,15 +160,15 @@
|
||||
}
|
||||
|
||||
// ================= DOMAIN VALIDATION =================
|
||||
private void ValidateOrder(OrderMessage order)
|
||||
private void ValidateOrder(OrderMsg order)
|
||||
{
|
||||
if (order.Nodes.Count == 0)
|
||||
if (order.Nodes.Length == 0)
|
||||
throw new Exception("Order must contain at least one node.");
|
||||
|
||||
if (order.Nodes.Count != order.Edges.Count + 1)
|
||||
if (order.Nodes.Length != order.Edges.Length + 1)
|
||||
throw new Exception(
|
||||
$"Invalid path structure: Nodes count ({order.Nodes.Count}) " +
|
||||
$"must equal Edges count + 1 ({order.Edges.Count + 1})."
|
||||
$"Invalid path structure: Nodes count ({order.Nodes.Length}) " +
|
||||
$"must equal Edges count + 1 ({order.Edges.Length + 1})."
|
||||
);
|
||||
|
||||
var nodeIds = order.Nodes
|
||||
|
||||
Reference in New Issue
Block a user