javascript methods for sequence to readable date

c# like java for PI5

Helper 2025-02-19 more updates for Compare
This commit is contained in:
2025-03-26 17:02:35 -07:00
parent 0621d0f07e
commit 919279a917
12 changed files with 1119 additions and 738 deletions

View File

@ -1,16 +1,35 @@
using Microsoft.Extensions.Logging;
using System.Collections.ObjectModel;
using System.Text.Json;
using Microsoft.Extensions.Logging;
namespace File_Folder_Helper.ADO2025.PI5;
internal static partial class Helper20250228
{
internal static partial class Helper20250228 {
private record Record(string TableName, ReadOnlyCollection<string> Columns, ReadOnlyCollection<string[]> Rows);
private static ReadOnlyCollection<Record> GetRecords(string headerA, string headerB, string file)
{
internal static void PostgresDumpToJson(ILogger<Worker> logger, List<string> args) {
string searchPattern = args[2];
string headerA = args[3].Replace('_', ' ');
string headerB = args[4].Replace('_', ' ');
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
PostgresDumpToJson(logger, headerA, headerB, files[0]);
}
private static void PostgresDumpToJson(ILogger<Worker> logger, string headerA, string headerB, string file) {
ReadOnlyCollection<Record> records = GetRecords(headerA, headerB, file);
if (records.Count > 0)
WriteFile(file, records);
else
logger.LogWarning("<{records}>(s)", records.Count);
}
private static ReadOnlyCollection<Record> GetRecords(string headerA, string headerB, string file) {
List<Record> results = [];
string line;
string[] segmentsA;
@ -23,11 +42,9 @@ internal static partial class Helper20250228
string? tableName = null;
string[] lines = File.ReadAllLines(file);
ReadOnlyCollection<string>? columns = null;
for (int i = 0; i < lines.Length; i++)
{
for (int i = 0; i < lines.Length; i++) {
line = lines[i];
if (tableName is null)
{
if (tableName is null) {
segmentsA = line.Split(headerA);
if (segmentsA.Length != 2)
continue;
@ -45,18 +62,14 @@ internal static partial class Helper20250228
continue;
segmentsE = segmentsB[0].Split(' ');
tableName = segmentsE[0];
}
else if (columns is null)
} else if (columns is null)
break;
else
{
else {
rows = [];
for (int j = i + 1; j < lines.Length; j++)
{
for (int j = i + 1; j < lines.Length; j++) {
i = j;
segmentsF = lines[j].Split('\t');
if (segmentsF.Length != columns.Count)
{
if (segmentsF.Length != columns.Count) {
if (rows.Count > 0)
results.Add(new(TableName: tableName, Columns: columns, Rows: rows.AsReadOnly()));
break;
@ -70,20 +83,16 @@ internal static partial class Helper20250228
return results.AsReadOnly();
}
private static void WriteFile(string file, ReadOnlyCollection<Record> records)
{
private static void WriteFile(string file, ReadOnlyCollection<Record> records) {
List<string> results = [];
string json;
string text;
Dictionary<string, string?> keyValuePairs = [];
foreach (Record record in records)
{
foreach (Record record in records) {
results.Clear();
foreach (string[] row in record.Rows)
{
foreach (string[] row in record.Rows) {
keyValuePairs.Clear();
for (int i = 0; i < row.Length; i++)
{
for (int i = 0; i < row.Length; i++) {
if (row[i] == "\\N")
keyValuePairs.Add(record.Columns[i], null);
else
@ -97,26 +106,4 @@ internal static partial class Helper20250228
}
}
private static void PostgresDumpToJson(ILogger<Worker> logger, string headerA, string headerB, string file)
{
ReadOnlyCollection<Record> records = GetRecords(headerA, headerB, file);
if (records.Count > 0)
WriteFile(file, records);
else
logger.LogWarning("<{records}>(s)", records.Count);
}
internal static void PostgresDumpToJson(ILogger<Worker> logger, List<string> args)
{
string searchPattern = args[2];
string headerA = args[3].Replace('_', ' ');
string headerB = args[4].Replace('_', ' ');
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
PostgresDumpToJson(logger, headerA, headerB, files[0]);
}
}