WriteNginxFileSystem
This commit is contained in:
@ -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;
|
||||
|
72
ADO2025/PI5/Helper-2025-04-29.cs
Normal file
72
ADO2025/PI5/Helper-2025-04-29.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user