using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Adaptation.FileHandlers.csv; public class Setup { public string Finish { get; set; } public string NorthProbeID { get; set; } public string SouthProbeID { get; set; } public string MeasurementPolarity { get; set; } public string SineBevelAngle { get; set; } public string ContactRadius { get; set; } public string ProbeSpacing { get; set; } public string ProbeLoad { get; set; } public string Orientation { get; set; } public string NumberOfStepSizes { get; set; } public List Steps { get; set; } #nullable enable #pragma warning disable CA1834 internal static Setup? GetSetup(string[] lines, int start, int stop) { Setup? result; Step step; string first; string[] segments; int? secondStart = null; List steps = new(); List values = new(); StringBuilder stringBuilder = new(); for (int i = start; i < stop; i++) { segments = lines[i].Split(new string[] { "," }, StringSplitOptions.None); first = segments.First(); if (first == "Step") { secondStart = i + 1; break; } _ = stringBuilder.Append(first).Append(","); if (segments.Length > 1) values.Add(segments[1]); else values.Add(string.Empty); } string header = "Finish,North Probe ID,South Probe ID,Measurement Polarity,Sine Bevel Angle,Contact Radius (µm),Probe Spacing (µm),Probe Load (gm),Orientation,Number of Step Sizes,"; if (secondStart is null || stringBuilder.Length != header.Length || stringBuilder.ToString() != header) result = null; else { result = new() { Finish = values[0], NorthProbeID = values[1], SouthProbeID = values[2], MeasurementPolarity = values[3], SineBevelAngle = values[4], ContactRadius = values[5], ProbeSpacing = values[6], ProbeLoad = values[7], Orientation = values[8], NumberOfStepSizes = values[9], Steps = steps, }; for (int i = secondStart.Value; i < stop; i++) { segments = lines[i].Split(new string[] { "," }, StringSplitOptions.None); if (segments.Length < 4) continue; step = new() { Number = segments[0], Points = segments[1], X = segments[2], Y = segments[3], }; steps.Add(step); } } return result; } }