@* CSV tag export for a Raw-tree Device / TagGroup (B2-WP5). Reads the device's tags (via the WP5-owned RawTagCsvExportReader — no IRawTreeService extension) and renders them in the same column shape RawCsvImportModal consumes (T0-2 CsvWriter, per-driver CsvColumnMap). The download is a plain same-origin link to GET /api/raw/tags.csv (R04 P6) — the file used to be embedded in the circuit twice (textarea + base64 data: URI); the modal now shows only a bounded preview of the first RawTagCsvExport.PreviewLines lines. Modal contract (the RawTree coordinator wires this in place of the OnExportCsv stub): *@ @using ZB.MOM.WW.OtOpcUa.AdminUI.Uns @inject RawTagCsvExportReader ExportReader @if (Visible) { } @code { /// Whether the modal is shown (two-way bound). [Parameter] public bool Visible { get; set; } /// Raised when changes (supports @bind-Visible). [Parameter] public EventCallback VisibleChanged { get; set; } /// The device to export. May be blank when is supplied. [Parameter] public string DeviceId { get; set; } = ""; /// When set, only tags under this group's subtree are exported; null exports the whole device. [Parameter] public string? TagGroupId { get; set; } /// The device's driver-type string — selects the per-driver typed column set. [Parameter] public string DriverType { get; set; } = ""; private bool _loading; private bool _built; private string? _error; private string _preview = ""; private bool _truncated; private string _downloadUrl = ""; private string _fileName = "tags.csv"; private int _rowCount; private string? _groupFilter; // Bumped on every open and close so a superseded build can't install its CSV under another device's modal. private int _openGeneration; protected override async Task OnParametersSetAsync() { if (Visible && !_built) { _built = true; await BuildAsync(++_openGeneration); } else if (!Visible) { _built = false; _openGeneration++; } } private bool IsStale(int generation) => generation != _openGeneration || !Visible; private async Task BuildAsync(int generation) { _loading = true; _error = null; try { _groupFilter = null; // The same builder the download endpoint runs, so the preview matches the file — but mapping only // the preview's rows (the header takes the first line), never the whole export (review r0 M8). var export = await RawTagCsvExport.BuildAsync(ExportReader, DeviceId, TagGroupId, DriverType, maxRows: RawTagCsvExport.PreviewLines - 1); if (IsStale(generation)) { return; } if (export is null) { _error = "Could not resolve the target device."; return; } _groupFilter = export.GroupPath; _rowCount = export.RowCount; _fileName = export.FileName; // Only the bounded preview is kept on the component; the full CSV is not held by the circuit. (_preview, var cut) = RawTagCsvExport.Preview(export.Csv); _truncated = cut || export.RowCount > RawTagCsvExport.PreviewLines - 1; _downloadUrl = RawTagCsvExport.DownloadUrl(DeviceId, TagGroupId, DriverType); } catch (Exception ex) { if (!IsStale(generation)) { _error = ex.Message; } } finally { if (!IsStale(generation)) { _loading = false; } } } private async Task Close() { _built = false; _openGeneration++; _preview = ""; _truncated = false; _downloadUrl = ""; Visible = false; await VisibleChanged.InvokeAsync(false); } }