@using System.Text.Json @using MudBlazor Import Order JSON @if (ShowWarning) { Only valid VDA 5050 Order JSON is accepted.
Invalid structure will be rejected.
} @if (!string.IsNullOrEmpty(ErrorMessage)) { @ErrorMessage }
Cancel Import
@code { [CascadingParameter] public IMudDialogInstance MudDialog { get; set; } = default!; public string JsonText { get; set; } = ""; public string? ErrorMessage; public bool ShowWarning { get; set; } = false; private void Cancel() => MudDialog.Cancel(); private void ValidateAndImport() { ErrorMessage = null; ShowWarning = false; try { using var doc = JsonDocument.Parse(JsonText); var root = doc.RootElement; // ===== BASIC STRUCTURE CHECK ===== if (!root.TryGetProperty("nodes", out _) || !root.TryGetProperty("edges", out _)) throw new Exception("Missing 'nodes' or 'edges' field."); var order = OrderMessage.FromSchemaObject(root); ValidateOrder(order); MudDialog.Close(DialogResult.Ok(order)); } catch (JsonException) { ShowWarning = true; ErrorMessage = "Invalid JSON format."; } catch (Exception ex) { ShowWarning = true; ErrorMessage = ex.Message; } } private void ValidateOrder(OrderMessage order) { if (order.Nodes.Count == 0) throw new Exception("Order must contain at least one node."); var nodeIds = order.Nodes.Select(n => n.NodeId).ToHashSet(); foreach (var e in order.Edges) { if (!nodeIds.Contains(e.StartNodeId) || !nodeIds.Contains(e.EndNodeId)) throw new Exception( $"Edge '{e.EdgeId}' references unknown node." ); } } }