WriteNginxFileSystem

This commit is contained in:
Mike Phares 2025-04-29 15:12:17 -07:00
parent d23f802cdb
commit 8f22f188a2
6 changed files with 117 additions and 5 deletions

25
.vscode/launch.json vendored
View File

@ -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",

View File

@ -113,13 +113,14 @@ internal static partial class Helper20250219 {
List<string> columns = [];
JsonProperty jsonPropertyOld;
JsonProperty jsonPropertyNew;
List<string> columnPairs = [];
JsonProperty[] jsonPropertiesOld;
JsonProperty[] jsonPropertiesNew;
List<string> unknownColumns = [];
List<string> differentColumns = [];
int last = jsonElementsOld.Length - 1;
List<string> 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;

View File

@ -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<Worker> logger, List<string> args) {
string searchPattern = args[2];
string sourceDirectory = Path.GetFullPath(args[0]);
ReadOnlyCollection<Record> subDirectories = GetSubDirectories(searchPattern, sourceDirectory);
if (subDirectories.Count == 0)
logger.LogWarning("<{results}>(s)", subDirectories.Count);
else
WriteNginxFileSystem(searchPattern, subDirectories);
}
private static ReadOnlyCollection<Record> GetSubDirectories(string searchPattern, string sourceDirectory) {
List<Record> 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<Record> subDirectories) {
string lines;
string result;
string[] files;
FileInfo fileInfo;
List<string> 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);
}
}
}

View File

@ -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);
}

View File

@ -17,7 +17,7 @@
<PackageReference Include="MetadataExtractor" Version="2.8.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="8.0.14" />
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="8.0.15" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="TextCopy" Version="6.2.1" />
<PackageReference Include="WindowsShortcutFactory" Version="1.2.0" />

View File

@ -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