WriteNginxFileSystemDelta
ProcessDataStandardFormatToJson
This commit is contained in:
57
ADO2025/PI5/Helper-2025-03-06.cs
Normal file
57
ADO2025/PI5/Helper-2025-03-06.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI5;
|
||||
|
||||
internal static partial class Helper20250306
|
||||
{
|
||||
|
||||
private static string ProcessDataStandardFormatToJson(int columnsLine, string[] columns, string[] body)
|
||||
{
|
||||
string result = "[\n";
|
||||
string line;
|
||||
string value;
|
||||
string[] segments;
|
||||
if (columns.Length == 0)
|
||||
columns = body[columnsLine].Trim().Split('\t');
|
||||
for (int i = columnsLine + 1; i < body.Length; i++)
|
||||
{
|
||||
line = "{";
|
||||
segments = body[i].Trim().Split('\t');
|
||||
if (segments.Length != columns.Length)
|
||||
break;
|
||||
for (int c = 1; c < segments.Length; c++)
|
||||
{
|
||||
value = segments[c].Replace("\"", "\\\"").Replace("\\", "\\\\");
|
||||
line += '"' + columns[c].Trim('"') + '"' + ':' + '"' + value + '"' + ',';
|
||||
}
|
||||
line = line[..^1] + '}' + ',' + '\n';
|
||||
result += line;
|
||||
}
|
||||
result = result[..^2] + ']';
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void ProcessDataStandardFormatToJson(ILogger<Worker> logger, string file)
|
||||
{
|
||||
string[] lines = File.ReadAllLines(file);
|
||||
if (lines.Length < 7)
|
||||
logger.LogWarning("<{lines}>(s)", lines.Length);
|
||||
else
|
||||
{
|
||||
string json = ProcessDataStandardFormatToJson(6, [], lines);
|
||||
File.WriteAllText(".json", json);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ProcessDataStandardFormatToJson(ILogger<Worker> logger, List<string> args)
|
||||
{
|
||||
string searchPattern = args[2];
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
if (files.Length != 1)
|
||||
logger.LogWarning("<{files}>(s)", files.Length);
|
||||
else
|
||||
ProcessDataStandardFormatToJson(logger, files[0]);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user