From 8f22f188a2dac1483211b7c5dd5c769c9e28b97c Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Tue, 29 Apr 2025 15:12:17 -0700 Subject: [PATCH] WriteNginxFileSystem --- .vscode/launch.json | 25 +++++++++++ ADO2025/PI5/Helper-2025-02-19.cs | 15 +++++-- ADO2025/PI5/Helper-2025-04-29.cs | 72 ++++++++++++++++++++++++++++++++ Day/HelperDay.cs | 2 + File-Folder-Helper.csproj | 2 +- Models/NginxFileSystem.cs | 6 +++ 6 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 ADO2025/PI5/Helper-2025-04-29.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index b1aea38..d74e4fa 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,31 @@ "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll", "args": [ + "s", + "X", + "\\\\mesfs.infineon.com\\EC_Characterization_Si\\Archive", + "Day-Helper-2025-04-29", + "*.pdsf", + "333", + "444", + "555", + "666", + "777", + "888", + "999", + "s", + "X", + "\\\\mesfs.infineon.com\\EC_Characterization_Si\\Archive\\BIORAD4\\2025_Week_16\\2025-04-17", + "Day-Helper-2025-02-19", + "csv-*.pdsf", + "*.pdsf", + "Time,HeaderUniqueId,UniqueId,Date,Wafer,Position,BIORAD4", + ",BIORAD4", + ",BIORAD4", + "Test|EventId,Date|DateTime,Position|Slot,DeltaThicknessSlotsOneAndTwentyFive|Actual Delta Thick Pts 1 and 25,PercentDeltaThicknessSlotsOneAndTwentyFive|% Delta Thick Pts 1 and 25,MID|Cassette,Lot|Batch,Title|Batch,Wafer|Text,Thickness|Site,MeanThickness|GradeMean,|BIORAD4", + "Time,A_LOGISTICS,B_LOGISTICS,Test,Count,Index,MesEntity,MID,Date,Employee,Lot,PSN,Reactor,Recipe,Cassette,GradeStdDev,HeaderUniqueId,Layer,MeanThickness,PassFail,RDS,Slot,Title,UniqueId,Wafer,Zone,Mean,Position,StdDev,Thickness,ThicknessSlotOne,ThicknessSlotTwentyFive,DeltaThicknessSlotsOneAndTwentyFive,PercentDeltaThicknessSlotsOneAndTwentyFive", + "Time,A_LOGISTICS,B_LOGISTICS,Count,Sequence,MesEntity,Index,Batch,Cassette,DateTime,Destination,Mean,PassFail,Recipe,Reference,Site,Slot,Source,StdDev,Text,GradeMean,GradeStdDev,RDS,PSN,Reactor,Layer,Zone,Employee,InferredLot,Thickness First Slot,Thickness Last Slot,Actual Delta Thick Pts 1 and 25,% Delta Thick Pts 1 and 25,EventId", + "0,1,2,31,3,6,5,8,9,27,7,23,24,13,8,21,-1,25,20,12,22,16,7,-1,19,26,11,16,18,15,-1,-1,29,30", "s", "X", "C:/Users/phares/AppData/Roaming/FreeFileSync", diff --git a/ADO2025/PI5/Helper-2025-02-19.cs b/ADO2025/PI5/Helper-2025-02-19.cs index 57dc4e8..12ceca9 100644 --- a/ADO2025/PI5/Helper-2025-02-19.cs +++ b/ADO2025/PI5/Helper-2025-02-19.cs @@ -113,13 +113,14 @@ internal static partial class Helper20250219 { List columns = []; JsonProperty jsonPropertyOld; JsonProperty jsonPropertyNew; + List columnPairs = []; JsonProperty[] jsonPropertiesOld; JsonProperty[] jsonPropertiesNew; List unknownColumns = []; List differentColumns = []; int last = jsonElementsOld.Length - 1; List sameAfterSpaceSplitColumns = []; - for (int i = last; i > 0; i--) { + for (int i = last; i > -1; i--) { if (jsonElementsOld[i].ValueKind != JsonValueKind.Object) { unknownColumns.Add(string.Empty); break; @@ -144,19 +145,23 @@ internal static partial class Helper20250219 { if (processDataStandardFormatMapping.IgnoreColumns.Contains(jsonPropertyOld.Name)) { if (i == last) { columns.Add("-1"); + columnPairs.Add($"{jsonPropertyOld.Name}:"); logger.LogDebug("{p} )) {jsonPropertyOld.Name} **", p, jsonPropertyOld.Name); } continue; } if (i == last) { columns.Add("-1"); + columnPairs.Add($"{jsonPropertyOld.Name}:"); if (!string.IsNullOrEmpty(valueOld)) logger.LogDebug("{p} )) {jsonPropertyOld.Name} ??", p, jsonPropertyOld.Name); } } else { - if (i == last) - columns.Add(q.Value.ToString()); jsonPropertyNew = jsonPropertiesNew[q.Value]; + if (i == last) { + columns.Add(q.Value.ToString()); + columnPairs.Add($"{jsonPropertyOld.Name}:{jsonPropertyNew.Name}"); + } valueNew = jsonPropertyNew.Value.ToString(); if (i == last) logger.LogDebug("{p} )) {jsonPropertyOld.Name} ~~ {q.Value} => {jsonPropertyNew.Name}", p, jsonPropertyOld.Name, q.Value, jsonPropertyNew.Name); @@ -174,8 +179,10 @@ internal static partial class Helper20250219 { } } } - if (i == last) + if (i == last) { logger.LogInformation(string.Join(',', columns)); + logger.LogInformation($"{string.Join(';', columnPairs)};"); + } } result = unknownColumns.Count == 0 && differentColumns.Count == 0 && sameAfterSpaceSplitColumns.Count == 0; return result; diff --git a/ADO2025/PI5/Helper-2025-04-29.cs b/ADO2025/PI5/Helper-2025-04-29.cs new file mode 100644 index 0000000..f573e7f --- /dev/null +++ b/ADO2025/PI5/Helper-2025-04-29.cs @@ -0,0 +1,72 @@ +using System.Collections.ObjectModel; +using System.Text.Json; + +using File_Folder_Helper.Models; + +using Microsoft.Extensions.Logging; + +namespace File_Folder_Helper.ADO2025.PI5; + +internal static partial class Helper20250429 { + + private record Record(string Directory, string File, bool FileExists); + + internal static void WriteNginxFileSystem(ILogger logger, List args) { + string searchPattern = args[2]; + string sourceDirectory = Path.GetFullPath(args[0]); + ReadOnlyCollection subDirectories = GetSubDirectories(searchPattern, sourceDirectory); + if (subDirectories.Count == 0) + logger.LogWarning("<{results}>(s)", subDirectories.Count); + else + WriteNginxFileSystem(searchPattern, subDirectories); + } + + private static ReadOnlyCollection GetSubDirectories(string searchPattern, string sourceDirectory) { + List results = []; + bool exists; + Record record; + string checkFile; + string[] subDirectories; + string[] directories = Directory.GetDirectories(sourceDirectory, "*", SearchOption.TopDirectoryOnly); + foreach (string directory in directories) { + subDirectories = Directory.GetDirectories(directory, "*", SearchOption.TopDirectoryOnly); + foreach (string subDirectory in subDirectories) { + checkFile = Path.Combine(subDirectory, $"{searchPattern.Split('*')[^1]}.json"); + exists = File.Exists(checkFile); + record = new(Directory: subDirectory, File: checkFile, FileExists: exists); + results.Add(record); + } + } + return results.OrderByDescending(l => l.FileExists).ToArray().AsReadOnly(); + } + + private static void WriteNginxFileSystem(string searchPattern, ReadOnlyCollection subDirectories) { + string lines; + string result; + string[] files; + FileInfo fileInfo; + List results = []; + NginxFileSystem nginxFileSystem; + foreach (Record record in subDirectories) { + results.Clear(); + files = Directory.GetFiles(record.Directory, searchPattern, SearchOption.AllDirectories); + foreach (string file in files) { + fileInfo = new(file); + nginxFileSystem = new(Name: fileInfo.FullName, + LastModified: null, + MTime: fileInfo.LastWriteTime.ToUniversalTime().ToString(), + URI: null, + Type: "file", + Length: fileInfo.Length); + results.Add(JsonSerializer.Serialize(nginxFileSystem, NginxFileSystemSingleLineSourceGenerationContext.Default.NginxFileSystem)); + } + if (results.Count == 0) + continue; + result = $"[{Environment.NewLine}{string.Join($",{Environment.NewLine}", results)}{Environment.NewLine}]"; + lines = !record.FileExists ? string.Empty : File.ReadAllText(record.File); + if (result == lines) + continue; + File.WriteAllText(record.File, result); + } + } +} \ No newline at end of file diff --git a/Day/HelperDay.cs b/Day/HelperDay.cs index d155548..5850c68 100644 --- a/Day/HelperDay.cs +++ b/Day/HelperDay.cs @@ -157,6 +157,8 @@ internal static class HelperDay ADO2025.PI5.Helper20250407.Sync(logger, args); else if (args[1] == "Day-Helper-2025-04-21") ADO2025.PI5.Helper20250421.FreeFileSyncChangeCreatedDate(logger, args); + else if (args[1] == "Day-Helper-2025-04-29") + ADO2025.PI5.Helper20250429.WriteNginxFileSystem(logger, args); else throw new Exception(appSettings.Company); } diff --git a/File-Folder-Helper.csproj b/File-Folder-Helper.csproj index 8e9133e..35130fb 100644 --- a/File-Folder-Helper.csproj +++ b/File-Folder-Helper.csproj @@ -17,7 +17,7 @@ - + diff --git a/Models/NginxFileSystem.cs b/Models/NginxFileSystem.cs index db92c41..4822d14 100644 --- a/Models/NginxFileSystem.cs +++ b/Models/NginxFileSystem.cs @@ -45,6 +45,12 @@ internal partial class NginxFileSystemSourceGenerationContext : JsonSerializerCo { } +[JsonSourceGenerationOptions(WriteIndented = false, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] +[JsonSerializable(typeof(NginxFileSystem))] +internal partial class NginxFileSystemSingleLineSourceGenerationContext : JsonSerializerContext +{ +} + [JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] [JsonSerializable(typeof(NginxFileSystem[]))] internal partial class NginxFileSystemCollectionSourceGenerationContext : JsonSerializerContext