Split Process Data Standard Format method into multiple methods
This commit is contained in:
parent
6783621dab
commit
3e2fb15db0
5
.vscode/launch.json
vendored
5
.vscode/launch.json
vendored
@ -11,6 +11,11 @@
|
|||||||
"preLaunchTask": "build",
|
"preLaunchTask": "build",
|
||||||
"program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll",
|
"program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll",
|
||||||
"args": [
|
"args": [
|
||||||
|
"s",
|
||||||
|
"X",
|
||||||
|
"L:/DevOps/EAF-Mesa-Integration/met08thftirqs408m/bin/Debug",
|
||||||
|
"Day-Helper-2025-03-06",
|
||||||
|
"*.pdsf",
|
||||||
"s",
|
"s",
|
||||||
"X",
|
"X",
|
||||||
"D:/ProgramData/VisualStudioCode",
|
"D:/ProgramData/VisualStudioCode",
|
||||||
|
@ -5,7 +5,35 @@ namespace File_Folder_Helper.ADO2025.PI5;
|
|||||||
internal static partial class Helper20250306
|
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
|
#pragma warning disable CA1845, IDE0057
|
||||||
string result = "[\n";
|
string result = "[\n";
|
||||||
@ -13,11 +41,11 @@ internal static partial class Helper20250306
|
|||||||
string value;
|
string value;
|
||||||
string[] segments;
|
string[] segments;
|
||||||
if (columns.Length == 0)
|
if (columns.Length == 0)
|
||||||
columns = body[columnsLine].Trim().Split('\t');
|
columns = lines[columnTitlesLine].Trim().Split('\t');
|
||||||
for (int i = columnsLine + 1; i < body.Length; i++)
|
for (int i = columnTitlesLine + 1; i < lines.Length; i++)
|
||||||
{
|
{
|
||||||
line = "{";
|
line = "{";
|
||||||
segments = body[i].Trim().Split('\t');
|
segments = lines[i].Trim().Split('\t');
|
||||||
if (segments.Length != columns.Length)
|
if (segments.Length != columns.Length)
|
||||||
break;
|
break;
|
||||||
for (int c = 1; c < segments.Length; c++)
|
for (int c = 1; c < segments.Length; c++)
|
||||||
@ -36,12 +64,20 @@ internal static partial class Helper20250306
|
|||||||
private static void ProcessDataStandardFormatToJson(ILogger<Worker> logger, string file)
|
private static void ProcessDataStandardFormatToJson(ILogger<Worker> logger, string file)
|
||||||
{
|
{
|
||||||
string[] lines = File.ReadAllLines(file);
|
string[] lines = File.ReadAllLines(file);
|
||||||
if (lines.Length < 7)
|
int? columnTitlesLine = GetProcessDataStandardFormatColumnTitlesLine(lines);
|
||||||
logger.LogWarning("<{lines}>(s)", lines.Length);
|
if (columnTitlesLine is null)
|
||||||
|
logger.LogWarning("<{columnTitlesLine}> is null", nameof(columnTitlesLine));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string json = ProcessDataStandardFormatToJson(6, [], lines);
|
string? text = ProcessDataStandardFormatToLastDataLine(lines, columnTitlesLine.Value);
|
||||||
File.WriteAllText(".json", json);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user