From 9c858b7b51be2eb5b2f515912d436224d7e6483c Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 29 Sep 2025 05:46:38 +0300 Subject: Process Parameters Visual Representation. Filter RML by machine type on Research module. --- .../Visual_Studio/Tango.CSV/CsvDynamicReader.cs | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'Software/Visual_Studio/Tango.CSV') diff --git a/Software/Visual_Studio/Tango.CSV/CsvDynamicReader.cs b/Software/Visual_Studio/Tango.CSV/CsvDynamicReader.cs index 33ba859eb..d43b9ba3d 100644 --- a/Software/Visual_Studio/Tango.CSV/CsvDynamicReader.cs +++ b/Software/Visual_Studio/Tango.CSV/CsvDynamicReader.cs @@ -20,6 +20,48 @@ namespace Tango.CSV public char Delimiter { get; } + public static CsvDynamicReader FromString(String csv) + { + return new CsvDynamicReader(csv); + } + + private CsvDynamicReader(string csvContent) + { + Delimiter = ','; + _colIndex = new Dictionary(StringComparer.OrdinalIgnoreCase); + _rows = new List(); + + using (var sr = new StringReader(csvContent)) + { + // Read to first non-empty line for headers + string headerLine; + do + { + headerLine = sr.ReadLine(); + if (headerLine == null) + throw new InvalidDataException("CSV file has no header row."); + } while (string.IsNullOrWhiteSpace(headerLine)); + + var headers = ParseCsvLine(headerLine, Delimiter); + for (int i = 0; i < headers.Count; i++) + { + var clean = CleanHeader(headers[i]); + if (!_colIndex.ContainsKey(clean)) + _colIndex.Add(clean, i); + // If duplicate header name appears, first one wins. + } + + // Read all rows + string line; + while ((line = sr.ReadLine()) != null) + { + if (line.Length == 0) continue; // skip empty + var fields = ParseCsvLine(line, Delimiter).ToArray(); + _rows.Add(new Row(this, fields)); + } + } + } + public CsvDynamicReader(string path, char delimiter = ',') { if (path == null) throw new ArgumentNullException(nameof(path)); -- cgit v1.3.1