From 3e2fb15db0d841cafea401ed790e81dd68df4cc5 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Tue, 18 Mar 2025 08:57:43 -0700 Subject: [PATCH] Split Process Data Standard Format method into multiple methods --- .vscode/launch.json | 5 +++ ADO2025/PI5/Helper-2025-03-06.cs | 52 +++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 8c72f92..6c0830d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,11 @@ "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll", "args": [ + "s", + "X", + "L:/DevOps/EAF-Mesa-Integration/met08thftirqs408m/bin/Debug", + "Day-Helper-2025-03-06", + "*.pdsf", "s", "X", "D:/ProgramData/VisualStudioCode", diff --git a/ADO2025/PI5/Helper-2025-03-06.cs b/ADO2025/PI5/Helper-2025-03-06.cs index b38a591..128ce8b 100644 --- a/ADO2025/PI5/Helper-2025-03-06.cs +++ b/ADO2025/PI5/Helper-2025-03-06.cs @@ -5,7 +5,35 @@ namespace File_Folder_Helper.ADO2025.PI5; internal static partial class Helper20250306 { - private static string ProcessDataStandardFormatToJson(int columnsLine, string[] columns, string[] body) + private static int? GetProcessDataStandardFormatColumnTitlesLine(string[] lines) + { + int? result = null; + for (int i = 0; i < lines.Length; i++) + { + if (lines[i].StartsWith("END_OFFSET") && i + 2 < lines.Length) + { + result = i + 1; + break; + } + } + return result; + } + + private static string? ProcessDataStandardFormatToLastDataLine(string[] lines, int columnTitlesLine) + { + string? result = null; + for (int i = columnTitlesLine + 1; i < lines.Length; i++) + { + if (lines[i].StartsWith("NUM_DATA_ROWS")) + { + result = lines[i - 1]; + break; + } + } + return result; + } + + private static string ProcessDataStandardFormatToJson(int columnTitlesLine, string[] columns, string[] lines) { #pragma warning disable CA1845, IDE0057 string result = "[\n"; @@ -13,11 +41,11 @@ internal static partial class Helper20250306 string value; string[] segments; if (columns.Length == 0) - columns = body[columnsLine].Trim().Split('\t'); - for (int i = columnsLine + 1; i < body.Length; i++) + columns = lines[columnTitlesLine].Trim().Split('\t'); + for (int i = columnTitlesLine + 1; i < lines.Length; i++) { line = "{"; - segments = body[i].Trim().Split('\t'); + segments = lines[i].Trim().Split('\t'); if (segments.Length != columns.Length) break; for (int c = 1; c < segments.Length; c++) @@ -36,12 +64,20 @@ internal static partial class Helper20250306 private static void ProcessDataStandardFormatToJson(ILogger logger, string file) { string[] lines = File.ReadAllLines(file); - if (lines.Length < 7) - logger.LogWarning("<{lines}>(s)", lines.Length); + int? columnTitlesLine = GetProcessDataStandardFormatColumnTitlesLine(lines); + if (columnTitlesLine is null) + logger.LogWarning("<{columnTitlesLine}> is null", nameof(columnTitlesLine)); else { - string json = ProcessDataStandardFormatToJson(6, [], lines); - File.WriteAllText(".json", json); + string? text = ProcessDataStandardFormatToLastDataLine(lines, columnTitlesLine.Value); + File.WriteAllText(".lbl", text); + if (lines.Length < columnTitlesLine.Value + 1) + logger.LogWarning("<{lines}>(s)", lines.Length); + else + { + string json = ProcessDataStandardFormatToJson(columnTitlesLine.Value, [], lines); + File.WriteAllText(".json", json); + } } }