diff --git a/Adaptation/.vscode/tasks.json b/Adaptation/.vscode/tasks.json index 25d7204..1c3230f 100644 --- a/Adaptation/.vscode/tasks.json +++ b/Adaptation/.vscode/tasks.json @@ -49,6 +49,16 @@ ], "problemMatcher": "$msCompile" }, + { + "label": "Format-Whitespaces", + "command": "dotnet", + "type": "process", + "args": [ + "format", + "whitespace" + ], + "problemMatcher": "$msCompile" + }, { "label": "Nuget Clear", "command": "dotnet", diff --git a/Adaptation/FileHandlers/pcl/Complete.cs b/Adaptation/FileHandlers/pcl/Complete.cs index e76420d..2772b6b 100644 --- a/Adaptation/FileHandlers/pcl/Complete.cs +++ b/Adaptation/FileHandlers/pcl/Complete.cs @@ -20,28 +20,28 @@ internal class Complete public Summary Summary { get; } public ReadOnlyCollection Points { get; } - public static Complete? Get(int take, string site, string multiple, string summaryLine, string lastUnits, string[] lines) + public static Complete? Get(int take, string site, string multiple, string summaryLine, string lastUnits, string lastUnitsB, ReadOnlyCollection lines) + { + Complete? result; + Header? header = Header.Get(lines, site, summaryLine); + if (header is null) + result = null; + else { - Complete? result; - Header? header = Header.Get(lines, site, summaryLine); - if (header is null) + Summary? summary = SummarySegment.Get(lines, site, summaryLine, lastUnits); + if (summary is null) result = null; else { - Summary? summary = SummarySegment.Get(lines, site, summaryLine); - if (summary is null) + ReadOnlyCollection points = Point.GetCollection(lines, take, site, multiple, summaryLine, lastUnitsB) ?? throw new NullReferenceException(nameof(summary)); + if (points.Count == 0) result = null; else - { - ReadOnlyCollection points = Point.GetCollection(lines, take, site, multiple, summaryLine, lastUnits) ?? throw new NullReferenceException(nameof(summary)); - if (points.Count == 0) - result = null; - else - result = new(header, summary, points); - } + result = new(header, summary, points); } - return result; } + return result; + } } @@ -49,4 +49,4 @@ internal class Complete [JsonSerializable(typeof(Complete))] internal partial class CompleteSourceGenerationContext : JsonSerializerContext { -} +} \ No newline at end of file diff --git a/Adaptation/FileHandlers/pcl/Header.cs b/Adaptation/FileHandlers/pcl/Header.cs index 03a4bfb..d855d15 100644 --- a/Adaptation/FileHandlers/pcl/Header.cs +++ b/Adaptation/FileHandlers/pcl/Header.cs @@ -128,7 +128,7 @@ internal class Header return new(results); } - public static Header? Get(string[] lines, string site, string summaryLine) + public static Header? Get(ReadOnlyCollection lines, string site, string summaryLine) { Header? result; string json; @@ -185,4 +185,4 @@ internal class Header [JsonSerializable(typeof(Header))] internal partial class HeaderSourceGenerationContext : JsonSerializerContext { -} +} \ No newline at end of file diff --git a/Adaptation/FileHandlers/pcl/Point.cs b/Adaptation/FileHandlers/pcl/Point.cs index 476e35d..7ec58bf 100644 --- a/Adaptation/FileHandlers/pcl/Point.cs +++ b/Adaptation/FileHandlers/pcl/Point.cs @@ -77,7 +77,7 @@ internal class Point string.Empty, string.Empty); - public static ReadOnlyCollection GetCollection(string[] lines, int take, string site, string multiple, string summaryLine, string lastUnits) + public static ReadOnlyCollection GetCollection(ReadOnlyCollection lines, int take, string site, string multiple, string summaryLine, string lastUnitsB) { List results = new(); string s; @@ -89,7 +89,7 @@ internal class Point bool foundB = false; string[] segmentsC; List sites = new(); - for (int i = 0; i < lines.Length; i++) + for (int i = 0; i < lines.Count; i++) { line = lines[i]; segmentsC = line.Split(new string[] { site }, StringSplitOptions.RemoveEmptyEntries); @@ -107,7 +107,7 @@ internal class Point continue; if (!foundB && line.Contains(multiple)) foundB = true; - if (line != lastUnits) + if (line != lastUnitsB) continue; if (foundB) { @@ -117,7 +117,7 @@ internal class Point for (int j = 0; j < sites.Count; j++) { s = sites[j]; - if (i + take > lines.Length) + if (i + take > lines.Count) break; segments = s.Split(new string[] { "(", ",", ")" }, StringSplitOptions.None); if (segments.Length < 2) @@ -154,4 +154,4 @@ internal class Point [JsonSerializable(typeof(Point))] internal partial class PointSourceGenerationContext : JsonSerializerContext { -} +} \ No newline at end of file diff --git a/Adaptation/FileHandlers/pcl/ProcessData.cs b/Adaptation/FileHandlers/pcl/ProcessData.cs index 3455af7..08823d3 100644 --- a/Adaptation/FileHandlers/pcl/ProcessData.cs +++ b/Adaptation/FileHandlers/pcl/ProcessData.cs @@ -3,6 +3,7 @@ using Adaptation.Shared.Methods; using log4net; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Data; using System.Diagnostics; using System.IO; @@ -540,13 +541,15 @@ public class ProcessData : IProcessData const string multiple = "MULTIPLE"; const string summaryLine = "SUMMARY A A"; const string lastUnits = "Flat Z: Grade : % Flat Z: Grade : % Flat Z: Grade : %"; + const string lastUnitsB = "Flat Z: Grade : % Flat Z: Grade : % Flat Z: Grade : %"; string[] lines = File.ReadAllLines(altHeaderFileName); - if (lines.Length > take) - result = Complete.Get(take, site, multiple, summaryLine, lastUnits, lines); + ReadOnlyCollection collection = new(lines); + if (collection.Count > take) + result = Complete.Get(take, site, multiple, summaryLine, lastUnits, lastUnitsB, collection); else { result = null; - _Log.Warn($"File {altHeaderFileName} has less than 5 lines"); + _Log.Warn($"File {altHeaderFileName} has less than {take} collection"); } return result; } diff --git a/Adaptation/FileHandlers/pcl/Summary.cs b/Adaptation/FileHandlers/pcl/Summary.cs index 77fca3f..ba80aa1 100644 --- a/Adaptation/FileHandlers/pcl/Summary.cs +++ b/Adaptation/FileHandlers/pcl/Summary.cs @@ -16,4 +16,4 @@ internal class Summary public SummarySegment? StandardDeviationPercentage { get; } public SummarySegment? RadialGradient { get; } -} +} \ No newline at end of file diff --git a/Adaptation/FileHandlers/pcl/SummarySegment.cs b/Adaptation/FileHandlers/pcl/SummarySegment.cs index 4086d37..e2eb487 100644 --- a/Adaptation/FileHandlers/pcl/SummarySegment.cs +++ b/Adaptation/FileHandlers/pcl/SummarySegment.cs @@ -66,7 +66,7 @@ internal class SummarySegment return new(results); } - public static Summary? Get(string[] lines, string site, string summaryLine) + public static Summary? Get(ReadOnlyCollection lines, string site, string summaryLine, string lastUnits) { Summary? result; string json; @@ -85,10 +85,12 @@ internal class SummarySegment continue; if (line.Contains(site)) break; + if (line.Contains(lastUnits)) + break; foreach (JsonProperty jsonProperty in jsonProperties) { segments = line.Split(new string[] { $"{jsonProperty.Name}:", $"{jsonProperty.Name} :" }, StringSplitOptions.None); - if (segments.Length < 2 || !line.StartsWith(jsonProperty.Name)) + if (segments.Length < 2 || (!line.StartsWith(jsonProperty.Name) && !line.StartsWith($"@ {jsonProperty.Name}"))) continue; segmentsB = segments[1].Trim().Split(' '); if (segmentsB.Length < 3) @@ -119,4 +121,4 @@ internal class SummarySegment [JsonSerializable(typeof(SummarySegment))] internal partial class SummarySegmentSourceGenerationContext : JsonSerializerContext { -} +} \ No newline at end of file