person-key-to-immich-import birthday json (Day-Helper-2024-05-18)
csharp_prefer_braces = true
This commit is contained in:
@ -28,7 +28,7 @@ csharp_new_line_before_members_in_anonymous_types = true
|
||||
csharp_new_line_before_members_in_object_initializers = true
|
||||
csharp_new_line_before_open_brace = none
|
||||
csharp_new_line_between_query_expression_clauses = true
|
||||
csharp_prefer_braces = false
|
||||
csharp_prefer_braces = true
|
||||
csharp_prefer_qualified_reference = true:error
|
||||
csharp_prefer_simple_default_expression = true:warning
|
||||
csharp_prefer_simple_using_statement = true:warning
|
||||
|
@ -5,41 +5,6 @@ namespace File_Folder_Helper.ADO2025.PI4;
|
||||
|
||||
internal static partial class Helper20250101 {
|
||||
|
||||
private static ReadOnlyDictionary<string, List<FileInfo>> GetKeyValuePairs(string directory, string searchPattern, string split) {
|
||||
string key;
|
||||
List<FileInfo>? collection;
|
||||
Dictionary<string, List<FileInfo>> results = [];
|
||||
string[] files = Directory.GetFiles(directory, searchPattern, SearchOption.TopDirectoryOnly);
|
||||
FileInfo[] fileInfoCollection = files.Select(l => new FileInfo(l)).ToArray();
|
||||
foreach (FileInfo fileInfo in fileInfoCollection.OrderBy(l => l.LastWriteTime)) {
|
||||
key = fileInfo.Name.Split(split)[0];
|
||||
if (!results.TryGetValue(key, out collection)) {
|
||||
results.Add(key, []);
|
||||
if (!results.TryGetValue(key, out collection))
|
||||
throw new Exception();
|
||||
}
|
||||
collection.Add(fileInfo);
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static void MoveToDelete(ILogger<Worker> logger, string appendage, ReadOnlyDictionary<string, List<FileInfo>> keyValuePairs) {
|
||||
string checkFile;
|
||||
FileInfo fileInfo;
|
||||
foreach (KeyValuePair<string, List<FileInfo>> keyValuePair in keyValuePairs) {
|
||||
if (keyValuePair.Value.Count < 3)
|
||||
continue;
|
||||
for (int i = 1; i < keyValuePair.Value.Count - 1; i++) {
|
||||
fileInfo = keyValuePair.Value[i];
|
||||
checkFile = Path.Combine($"{fileInfo.Directory}{appendage}", fileInfo.Name);
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
logger.LogInformation("Moving <{fileInfo.FullName}> to <{checkFile}>", fileInfo.FullName, checkFile);
|
||||
File.Move(fileInfo.FullName, checkFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void MoveToDelete(ILogger<Worker> logger, List<string> args) {
|
||||
string split = args[3];
|
||||
string appendage = args[4];
|
||||
@ -50,4 +15,42 @@ internal static partial class Helper20250101 {
|
||||
MoveToDelete(logger, appendage, keyValuePairs);
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<string, List<FileInfo>> GetKeyValuePairs(string directory, string searchPattern, string split) {
|
||||
string key;
|
||||
List<FileInfo>? collection;
|
||||
Dictionary<string, List<FileInfo>> results = [];
|
||||
string[] files = Directory.GetFiles(directory, searchPattern, SearchOption.TopDirectoryOnly);
|
||||
FileInfo[] fileInfoCollection = files.Select(l => new FileInfo(l)).ToArray();
|
||||
foreach (FileInfo fileInfo in fileInfoCollection.OrderBy(l => l.LastWriteTime)) {
|
||||
key = fileInfo.Name.Split(split)[0];
|
||||
if (!results.TryGetValue(key, out collection)) {
|
||||
results.Add(key, []);
|
||||
if (!results.TryGetValue(key, out collection)) {
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
collection.Add(fileInfo);
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static void MoveToDelete(ILogger<Worker> logger, string appendage, ReadOnlyDictionary<string, List<FileInfo>> keyValuePairs) {
|
||||
string checkFile;
|
||||
FileInfo fileInfo;
|
||||
foreach (KeyValuePair<string, List<FileInfo>> keyValuePair in keyValuePairs) {
|
||||
if (keyValuePair.Value.Count < 3) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 1; i < keyValuePair.Value.Count - 1; i++) {
|
||||
fileInfo = keyValuePair.Value[i];
|
||||
checkFile = Path.Combine($"{fileInfo.Directory}{appendage}", fileInfo.Name);
|
||||
if (File.Exists(checkFile)) {
|
||||
continue;
|
||||
}
|
||||
logger.LogInformation("Moving <{fileInfo.FullName}> to <{checkFile}>", fileInfo.FullName, checkFile);
|
||||
File.Move(fileInfo.FullName, checkFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,15 @@ namespace File_Folder_Helper.ADO2025.PI4;
|
||||
|
||||
internal static partial class Helper20250114 {
|
||||
|
||||
internal static void Rename(ILogger<Worker> logger, List<string> args) {
|
||||
string dateFormat = args[3];
|
||||
string[] searchPatterns = args[2].Split('~');
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
foreach (string searchPattern in searchPatterns) {
|
||||
Rename(logger, sourceDirectory, searchPattern, dateFormat);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Rename(string[] directories, string dateFormat) {
|
||||
string[] files;
|
||||
DateTime dateTime;
|
||||
@ -14,16 +23,19 @@ internal static partial class Helper20250114 {
|
||||
files = Directory.GetFiles(directory, "*", SearchOption.AllDirectories);
|
||||
foreach (string file in files) {
|
||||
fileInfo = new(file);
|
||||
if (dateTime > fileInfo.LastWriteTime)
|
||||
if (dateTime > fileInfo.LastWriteTime) {
|
||||
continue;
|
||||
}
|
||||
dateTime = fileInfo.LastWriteTime;
|
||||
}
|
||||
if (dateTime == DateTime.MinValue)
|
||||
if (dateTime == DateTime.MinValue) {
|
||||
continue;
|
||||
}
|
||||
checkDirectory = Path.Combine(Path.GetDirectoryName(directory) ?? throw new Exception(), dateTime.ToString(dateFormat));
|
||||
if (checkDirectory != directory) {
|
||||
if (Directory.Exists(checkDirectory))
|
||||
if (Directory.Exists(checkDirectory)) {
|
||||
continue;
|
||||
}
|
||||
Directory.Move(directory, checkDirectory);
|
||||
}
|
||||
Directory.SetLastWriteTime(checkDirectory, dateTime);
|
||||
@ -36,12 +48,4 @@ internal static partial class Helper20250114 {
|
||||
Rename(directories, dateFormat);
|
||||
}
|
||||
|
||||
internal static void Rename(ILogger<Worker> logger, List<string> args) {
|
||||
string dateFormat = args[3];
|
||||
string[] searchPatterns = args[2].Split('~');
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
foreach (string searchPattern in searchPatterns)
|
||||
Rename(logger, sourceDirectory, searchPattern, dateFormat);
|
||||
}
|
||||
|
||||
}
|
@ -6,62 +6,6 @@ namespace File_Folder_Helper.ADO2025.PI4;
|
||||
|
||||
internal static partial class Helper20250126 {
|
||||
|
||||
private static void Move(string file, string fileName, string checkFile, List<string> foundLines, ReadOnlyCollection<DateTime> dateTimes) {
|
||||
string checkDirectory = Path.Combine(Path.GetDirectoryName(file) ?? throw new Exception(), dateTimes[0].ToString("yyyy-MM"));
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
string fileNameB = Path.GetFileName(checkFile);
|
||||
string checkFileB = Path.Combine(checkDirectory, fileName);
|
||||
string checkFileC = Path.Combine(checkDirectory, fileNameB);
|
||||
string contents = string.Join(Environment.NewLine, foundLines);
|
||||
string checkFileD = Path.Combine(checkDirectory, $"{fileName}.txt");
|
||||
if (!File.Exists(checkFileB))
|
||||
File.Move(file, checkFileB);
|
||||
if (!File.Exists(checkFileC))
|
||||
File.Move(checkFile, checkFileC);
|
||||
File.WriteAllText(checkFileD, contents);
|
||||
}
|
||||
|
||||
private static void Move(ILogger<Worker> logger, string dateFormat, string file, string checkFile, string fileName, ReadOnlyCollection<string> statementPeriodSegments, List<string> foundLines) {
|
||||
DateTime dateTime;
|
||||
List<DateTime> dateTimes = [];
|
||||
foreach (string check in statementPeriodSegments) {
|
||||
if (!DateTime.TryParseExact(check, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
|
||||
continue;
|
||||
dateTimes.Add(dateTime);
|
||||
}
|
||||
if (dateTimes.Count != 2)
|
||||
logger.LogInformation($"Only {dateTimes.Count} date(s) were found in <{fileName}>!");
|
||||
else
|
||||
Move(file, fileName, checkFile, foundLines, dateTimes.AsReadOnly());
|
||||
}
|
||||
|
||||
private static void Move(ILogger<Worker> logger, string file, string checkFile, string dateFormat, string statementPeriod, string search) {
|
||||
List<string> foundLines = [];
|
||||
bool statementPeriodFound = false;
|
||||
string[]? statementPeriodSegments = null;
|
||||
string fileName = Path.GetFileName(file);
|
||||
string[] lines = File.ReadAllLines(file);
|
||||
foreach (string line in lines) {
|
||||
if (statementPeriodSegments is not null) {
|
||||
if (line.Contains(search))
|
||||
foundLines.Add(line);
|
||||
} else {
|
||||
if (statementPeriodFound) {
|
||||
statementPeriodSegments = line.Split(' ');
|
||||
continue;
|
||||
}
|
||||
if (!line.Contains(statementPeriod))
|
||||
continue;
|
||||
statementPeriodFound = true;
|
||||
}
|
||||
}
|
||||
if (statementPeriodSegments is null || statementPeriodSegments.Length < 4)
|
||||
logger.LogInformation($"{nameof(statementPeriod)}: {statementPeriod}; wasn't found in <{fileName}>!");
|
||||
else
|
||||
Move(logger, dateFormat, file, checkFile, fileName, statementPeriodSegments.AsReadOnly(), foundLines);
|
||||
}
|
||||
|
||||
internal static void Move(ILogger<Worker> logger, List<string> args) {
|
||||
string checkFile;
|
||||
string search = args[5];
|
||||
@ -72,10 +16,75 @@ internal static partial class Helper20250126 {
|
||||
string[] files = Directory.GetFiles(sourceDirectory, searchPatterns, SearchOption.AllDirectories);
|
||||
foreach (string file in files) {
|
||||
checkFile = Path.ChangeExtension(file, ".pdf");
|
||||
if (!File.Exists(checkFile))
|
||||
if (!File.Exists(checkFile)) {
|
||||
continue;
|
||||
}
|
||||
Move(logger, file, checkFile, dateFormat, statementPeriod, search);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Move(ILogger<Worker> logger, string file, string checkFile, string dateFormat, string statementPeriod, string search) {
|
||||
List<string> foundLines = [];
|
||||
bool statementPeriodFound = false;
|
||||
string[]? statementPeriodSegments = null;
|
||||
string fileName = Path.GetFileName(file);
|
||||
string[] lines = File.ReadAllLines(file);
|
||||
foreach (string line in lines) {
|
||||
if (statementPeriodSegments is not null) {
|
||||
if (line.Contains(search)) {
|
||||
foundLines.Add(line);
|
||||
}
|
||||
} else {
|
||||
if (statementPeriodFound) {
|
||||
statementPeriodSegments = line.Split(' ');
|
||||
continue;
|
||||
}
|
||||
if (!line.Contains(statementPeriod)) {
|
||||
continue;
|
||||
}
|
||||
statementPeriodFound = true;
|
||||
}
|
||||
}
|
||||
if (statementPeriodSegments is null || statementPeriodSegments.Length < 4) {
|
||||
logger.LogInformation($"{nameof(statementPeriod)}: {statementPeriod}; wasn't found in <{fileName}>!");
|
||||
} else {
|
||||
Move(logger, dateFormat, file, checkFile, fileName, statementPeriodSegments.AsReadOnly(), foundLines);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Move(ILogger<Worker> logger, string dateFormat, string file, string checkFile, string fileName, ReadOnlyCollection<string> statementPeriodSegments, List<string> foundLines) {
|
||||
DateTime dateTime;
|
||||
List<DateTime> dateTimes = [];
|
||||
foreach (string check in statementPeriodSegments) {
|
||||
if (!DateTime.TryParseExact(check, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime)) {
|
||||
continue;
|
||||
}
|
||||
dateTimes.Add(dateTime);
|
||||
}
|
||||
if (dateTimes.Count != 2) {
|
||||
logger.LogInformation($"Only {dateTimes.Count} date(s) were found in <{fileName}>!");
|
||||
} else {
|
||||
Move(file, fileName, checkFile, foundLines, dateTimes.AsReadOnly());
|
||||
}
|
||||
}
|
||||
|
||||
private static void Move(string file, string fileName, string checkFile, List<string> foundLines, ReadOnlyCollection<DateTime> dateTimes) {
|
||||
string checkDirectory = Path.Combine(Path.GetDirectoryName(file) ?? throw new Exception(), dateTimes[0].ToString("yyyy-MM"));
|
||||
if (!Directory.Exists(checkDirectory)) {
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
string fileNameB = Path.GetFileName(checkFile);
|
||||
string checkFileB = Path.Combine(checkDirectory, fileName);
|
||||
string checkFileC = Path.Combine(checkDirectory, fileNameB);
|
||||
string contents = string.Join(Environment.NewLine, foundLines);
|
||||
string checkFileD = Path.Combine(checkDirectory, $"{fileName}.txt");
|
||||
if (!File.Exists(checkFileB)) {
|
||||
File.Move(file, checkFileB);
|
||||
}
|
||||
if (!File.Exists(checkFileC)) {
|
||||
File.Move(checkFile, checkFileC);
|
||||
}
|
||||
File.WriteAllText(checkFileD, contents);
|
||||
}
|
||||
|
||||
}
|
@ -16,37 +16,6 @@ internal static partial class Helper20250204 {
|
||||
[GeneratedRegex("[\\s!?.,@:;|\\\\/\"'`£$%\\^&*{}[\\]()<>~#+\\-=_¬]+")]
|
||||
private static partial Regex InvalidCharacter();
|
||||
|
||||
private record H1ParamCaseAndState(string H1, string ParamCase, string State) {
|
||||
|
||||
private static string GetParamCase(string value) {
|
||||
string result;
|
||||
StringBuilder stringBuilder = new(value);
|
||||
Match[] matches = UpperCase().Matches(value).ToArray();
|
||||
for (int i = matches.Length - 1; i > -1; i--)
|
||||
_ = stringBuilder.Insert(matches[i].Index, '-');
|
||||
string[] segments = InvalidCharacter().Split(stringBuilder.ToString().ToLower());
|
||||
result = string.Join('-', segments).Trim('-');
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string GetState(string value) =>
|
||||
value switch {
|
||||
"New" => "ToDo",
|
||||
"Active" => "In Progress",
|
||||
"Closed" => "Done",
|
||||
_ => "Backlog",
|
||||
};
|
||||
|
||||
internal static H1ParamCaseAndState Get(WorkItem workItem) {
|
||||
H1ParamCaseAndState result;
|
||||
string paramCase = GetParamCase(workItem.Title);
|
||||
string state = GetState(workItem.State);
|
||||
result = new(workItem.Title, paramCase, state);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private record Attribute([property: JsonPropertyName("isLocked")] bool IsLocked,
|
||||
[property: JsonPropertyName("name")] string Name,
|
||||
[property: JsonPropertyName("parameterTitle")] string? ParameterTitle,
|
||||
@ -148,16 +117,6 @@ internal static partial class Helper20250204 {
|
||||
private static string GetTaskText(string directory, string rootDirectory) =>
|
||||
string.Join(Environment.NewLine, GetTaskLines(directory, rootDirectory));
|
||||
|
||||
private static void WriteTaskFile(string sourceDirectory, string rootDirectory) {
|
||||
string tasksFile = Path.Combine(sourceDirectory, ".vscode", "tasks.json");
|
||||
string oldText = File.ReadAllText(tasksFile);
|
||||
string jsonSafeDirectory = sourceDirectory.Replace('\\', '/');
|
||||
if (!oldText.Contains(jsonSafeDirectory)) {
|
||||
string text = GetTaskText(jsonSafeDirectory, rootDirectory);
|
||||
File.WriteAllText(tasksFile, text);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetFilter(ReadOnlyCollection<H1ParamCaseAndState> collection, string filter) =>
|
||||
string.Join(Environment.NewLine, from l in collection where l.State == filter select $"- [{l.ParamCase}](tasks/{l.ParamCase}.md)");
|
||||
|
||||
@ -192,6 +151,103 @@ internal static partial class Helper20250204 {
|
||||
private static string GetIndexText(WorkItem workItem, H1ParamCaseAndState h1ParamCaseAndState, ReadOnlyCollection<H1ParamCaseAndState> collection) =>
|
||||
string.Join(Environment.NewLine, GetIndexLines(workItem, h1ParamCaseAndState, collection));
|
||||
|
||||
internal static void ExtractKanban(ILogger<Worker> logger, List<string> args) {
|
||||
string searchPattern = "*.json";
|
||||
string fullPath = Path.GetFullPath(args[0]);
|
||||
string sourceDirectory = GetSourceDirectory(fullPath);
|
||||
string rootDirectory = args.Count < 3 || args[2].Length < 16 ? "D:/5-Other-Small/Kanban-mestsa003/{}" : args[2];
|
||||
WriteTaskFile(sourceDirectory, rootDirectory);
|
||||
string sourceDirectoryName = Path.GetFileName(sourceDirectory);
|
||||
DirectoryInfo directoryInfo = new(Path.Combine(sourceDirectory, ".kanbn"));
|
||||
FileInfo? fileInfo = !directoryInfo.Exists ? null : new(Path.Combine(directoryInfo.FullName, $"{sourceDirectoryName}.json"));
|
||||
if (directoryInfo.Exists && fileInfo is not null && fileInfo.Exists) {
|
||||
ExtractKanban(searchPattern, rootDirectory, directoryInfo, fileInfo);
|
||||
} else {
|
||||
logger.LogWarning("<{directoryInfo}> doesn't exist", directoryInfo.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetSourceDirectory(string directory) {
|
||||
string? result = null;
|
||||
DirectoryInfo directoryInfo;
|
||||
string? checkDirectory = directory;
|
||||
string? pathRoot = Path.GetPathRoot(directory);
|
||||
for (int i = 0; i < int.MaxValue; i++) {
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(checkDirectory) || checkDirectory == pathRoot) {
|
||||
break;
|
||||
}
|
||||
directoryInfo = new(checkDirectory);
|
||||
if (string.IsNullOrEmpty(directoryInfo.LinkTarget)) {
|
||||
continue;
|
||||
}
|
||||
result = directory.Replace(checkDirectory, directoryInfo.LinkTarget);
|
||||
break;
|
||||
}
|
||||
result ??= directory;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void WriteTaskFile(string sourceDirectory, string rootDirectory) {
|
||||
string tasksFile = Path.Combine(sourceDirectory, ".vscode", "tasks.json");
|
||||
string oldText = File.ReadAllText(tasksFile);
|
||||
string jsonSafeDirectory = sourceDirectory.Replace('\\', '/');
|
||||
if (!oldText.Contains(jsonSafeDirectory)) {
|
||||
string text = GetTaskText(jsonSafeDirectory, rootDirectory);
|
||||
File.WriteAllText(tasksFile, text);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ExtractKanban(string searchPattern, string rootDirectory, DirectoryInfo kanbanDirectory, FileInfo fileInfo) {
|
||||
string checkFile;
|
||||
string weekOfYear;
|
||||
string workItemDirectory;
|
||||
string line = Environment.NewLine;
|
||||
H1ParamCaseAndState h1ParamCaseAndState;
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
string tasksDirectory = Path.Combine(kanbanDirectory.FullName, "tasks");
|
||||
if (!Directory.Exists(tasksDirectory)) {
|
||||
_ = Directory.CreateDirectory(tasksDirectory);
|
||||
}
|
||||
string[] files = Directory.GetFiles(tasksDirectory, searchPattern, SearchOption.TopDirectoryOnly);
|
||||
ReadOnlyCollection<WorkItem> workItems = GetWorkItems(files);
|
||||
string markdown = GetIndexMarkdown(fileInfo, workItems);
|
||||
string indexFile = Path.Combine(kanbanDirectory.FullName, "index.md");
|
||||
string markdownOld = File.Exists(indexFile) ? File.ReadAllText(indexFile) : string.Empty;
|
||||
if (markdown != markdownOld) {
|
||||
File.WriteAllText(indexFile, markdown);
|
||||
}
|
||||
foreach (WorkItem workItem in workItems) {
|
||||
h1ParamCaseAndState = H1ParamCaseAndState.Get(workItem);
|
||||
checkFile = Path.Combine(tasksDirectory, $"{h1ParamCaseAndState.ParamCase}.md");
|
||||
markdownOld = File.Exists(checkFile) ? File.ReadAllText(checkFile) : string.Empty;
|
||||
if (markdownOld.Contains("](")) {
|
||||
continue;
|
||||
}
|
||||
weekOfYear = calendar.GetWeekOfYear(workItem.CreatedDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
workItemDirectory = Path.GetFullPath(Path.Combine(rootDirectory, $"{workItem.CreatedDate:yyyy}", $"{workItem.CreatedDate:yyyy}_Week_{weekOfYear}", $"{workItem.Id}"));
|
||||
markdown = $"# {h1ParamCaseAndState.H1}{line}{line}## Id {workItem.Id}{line}{line}## Code Insiders{line}{line}- [code-insiders]({workItemDirectory}){line}";
|
||||
if (markdown != markdownOld) {
|
||||
File.WriteAllText(checkFile, markdown);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<WorkItem> GetWorkItems(string[] files) {
|
||||
List<WorkItem> results = [];
|
||||
string json;
|
||||
WorkItem? workItem;
|
||||
foreach (string file in files) {
|
||||
json = File.ReadAllText(file);
|
||||
workItem = JsonSerializer.Deserialize(json, WorkItemSourceGenerationContext.Default.WorkItem);
|
||||
if (workItem is null) {
|
||||
continue;
|
||||
}
|
||||
results.Add(workItem);
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static string GetIndexMarkdown(FileInfo fileInfo, ReadOnlyCollection<WorkItem> workItems) {
|
||||
string result;
|
||||
H1ParamCaseAndState h1ParamCaseAndState;
|
||||
@ -210,83 +266,36 @@ internal static partial class Helper20250204 {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<WorkItem> GetWorkItems(string[] files) {
|
||||
List<WorkItem> results = [];
|
||||
string json;
|
||||
WorkItem? workItem;
|
||||
foreach (string file in files) {
|
||||
json = File.ReadAllText(file);
|
||||
workItem = JsonSerializer.Deserialize(json, WorkItemSourceGenerationContext.Default.WorkItem);
|
||||
if (workItem is null)
|
||||
continue;
|
||||
results.Add(workItem);
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
private record H1ParamCaseAndState(string H1, string ParamCase, string State) {
|
||||
|
||||
private static void ExtractKanban(string searchPattern, string rootDirectory, DirectoryInfo kanbanDirectory, FileInfo fileInfo) {
|
||||
string checkFile;
|
||||
string weekOfYear;
|
||||
string workItemDirectory;
|
||||
string line = Environment.NewLine;
|
||||
H1ParamCaseAndState h1ParamCaseAndState;
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
string tasksDirectory = Path.Combine(kanbanDirectory.FullName, "tasks");
|
||||
if (!Directory.Exists(tasksDirectory))
|
||||
_ = Directory.CreateDirectory(tasksDirectory);
|
||||
string[] files = Directory.GetFiles(tasksDirectory, searchPattern, SearchOption.TopDirectoryOnly);
|
||||
ReadOnlyCollection<WorkItem> workItems = GetWorkItems(files);
|
||||
string markdown = GetIndexMarkdown(fileInfo, workItems);
|
||||
string indexFile = Path.Combine(kanbanDirectory.FullName, "index.md");
|
||||
string markdownOld = File.Exists(indexFile) ? File.ReadAllText(indexFile) : string.Empty;
|
||||
if (markdown != markdownOld)
|
||||
File.WriteAllText(indexFile, markdown);
|
||||
foreach (WorkItem workItem in workItems) {
|
||||
h1ParamCaseAndState = H1ParamCaseAndState.Get(workItem);
|
||||
checkFile = Path.Combine(tasksDirectory, $"{h1ParamCaseAndState.ParamCase}.md");
|
||||
markdownOld = File.Exists(checkFile) ? File.ReadAllText(checkFile) : string.Empty;
|
||||
if (markdownOld.Contains("]("))
|
||||
continue;
|
||||
weekOfYear = calendar.GetWeekOfYear(workItem.CreatedDate, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
workItemDirectory = Path.GetFullPath(Path.Combine(rootDirectory, $"{workItem.CreatedDate:yyyy}", $"{workItem.CreatedDate:yyyy}_Week_{weekOfYear}", $"{workItem.Id}"));
|
||||
markdown = $"# {h1ParamCaseAndState.H1}{line}{line}## Id {workItem.Id}{line}{line}## Code Insiders{line}{line}- [code-insiders]({workItemDirectory}){line}";
|
||||
if (markdown != markdownOld)
|
||||
File.WriteAllText(checkFile, markdown);
|
||||
private static string GetParamCase(string value) {
|
||||
string result;
|
||||
StringBuilder stringBuilder = new(value);
|
||||
Match[] matches = UpperCase().Matches(value).ToArray();
|
||||
for (int i = matches.Length - 1; i > -1; i--) {
|
||||
_ = stringBuilder.Insert(matches[i].Index, '-');
|
||||
}
|
||||
string[] segments = InvalidCharacter().Split(stringBuilder.ToString().ToLower());
|
||||
result = string.Join('-', segments).Trim('-');
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetSourceDirectory(string directory) {
|
||||
string? result = null;
|
||||
DirectoryInfo directoryInfo;
|
||||
string? checkDirectory = directory;
|
||||
string? pathRoot = Path.GetPathRoot(directory);
|
||||
for (int i = 0; i < int.MaxValue; i++) {
|
||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||
if (string.IsNullOrEmpty(checkDirectory) || checkDirectory == pathRoot)
|
||||
break;
|
||||
directoryInfo = new(checkDirectory);
|
||||
if (string.IsNullOrEmpty(directoryInfo.LinkTarget))
|
||||
continue;
|
||||
result = directory.Replace(checkDirectory, directoryInfo.LinkTarget);
|
||||
break;
|
||||
private static string GetState(string value) =>
|
||||
value switch {
|
||||
"New" => "ToDo",
|
||||
"Active" => "In Progress",
|
||||
"Closed" => "Done",
|
||||
_ => "Backlog",
|
||||
};
|
||||
|
||||
internal static H1ParamCaseAndState Get(WorkItem workItem) {
|
||||
H1ParamCaseAndState result;
|
||||
string paramCase = GetParamCase(workItem.Title);
|
||||
string state = GetState(workItem.State);
|
||||
result = new(workItem.Title, paramCase, state);
|
||||
return result;
|
||||
}
|
||||
result ??= directory;
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static void ExtractKanban(ILogger<Worker> logger, List<string> args) {
|
||||
string searchPattern = "*.json";
|
||||
string fullPath = Path.GetFullPath(args[0]);
|
||||
string sourceDirectory = GetSourceDirectory(fullPath);
|
||||
string rootDirectory = args.Count < 3 || args[2].Length < 16 ? "D:/5-Other-Small/Kanban-mestsa003/{}" : args[2];
|
||||
WriteTaskFile(sourceDirectory, rootDirectory);
|
||||
string sourceDirectoryName = Path.GetFileName(sourceDirectory);
|
||||
DirectoryInfo directoryInfo = new(Path.Combine(sourceDirectory, ".kanbn"));
|
||||
FileInfo? fileInfo = !directoryInfo.Exists ? null : new(Path.Combine(directoryInfo.FullName, $"{sourceDirectoryName}.json"));
|
||||
if (directoryInfo.Exists && fileInfo is not null && fileInfo.Exists)
|
||||
ExtractKanban(searchPattern, rootDirectory, directoryInfo, fileInfo);
|
||||
else
|
||||
logger.LogWarning("<{directoryInfo}> doesn't exist", directoryInfo.FullName);
|
||||
}
|
||||
|
||||
}
|
@ -28,7 +28,7 @@ csharp_new_line_before_members_in_anonymous_types = true
|
||||
csharp_new_line_before_members_in_object_initializers = true
|
||||
csharp_new_line_before_open_brace = none
|
||||
csharp_new_line_between_query_expression_clauses = true
|
||||
csharp_prefer_braces = false
|
||||
csharp_prefer_braces = true
|
||||
csharp_prefer_qualified_reference = true:error
|
||||
csharp_prefer_simple_default_expression = true:warning
|
||||
csharp_prefer_simple_using_statement = true:warning
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Globalization;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Globalization;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI5;
|
||||
|
||||
@ -17,18 +16,20 @@ internal static partial class Helper20250218 {
|
||||
string[] directories = Directory.GetDirectories(sourceDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string directory in directories) {
|
||||
checkDirectory = Path.Combine(directory, checkDirectoryName);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
if (!Directory.Exists(checkDirectory)) {
|
||||
continue;
|
||||
}
|
||||
MoveToArchive(logger, searchPattern, searchMES, searchSequence, destinationRoot, checkDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
private static void MoveToArchive(ILogger<Worker> logger, string searchPattern, string searchMES, string searchSequence, string destinationRoot, string checkDirectory) {
|
||||
string[] files = Directory.GetFiles(checkDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
if (files.Length == 0)
|
||||
if (files.Length == 0) {
|
||||
logger.LogInformation("<{files}>(s)", files.Length);
|
||||
else
|
||||
} else {
|
||||
MoveToArchive(logger, searchMES, searchSequence, destinationRoot, files);
|
||||
}
|
||||
}
|
||||
|
||||
private static void MoveToArchive(ILogger<Worker> logger, string searchMES, string searchSequence, string destinationRoot, string[] files) {
|
||||
@ -46,15 +47,18 @@ internal static partial class Helper20250218 {
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
foreach (string file in files) {
|
||||
fileInfo = new(file);
|
||||
if (string.IsNullOrEmpty(fileInfo.DirectoryName))
|
||||
if (string.IsNullOrEmpty(fileInfo.DirectoryName)) {
|
||||
continue;
|
||||
}
|
||||
text = File.ReadAllText(file);
|
||||
segments = text.Split(searchMES);
|
||||
if (segments.Length < 2)
|
||||
if (segments.Length < 2) {
|
||||
continue;
|
||||
}
|
||||
segmentsB = text.Split(searchSequence);
|
||||
if (segmentsB.Length < 2)
|
||||
if (segmentsB.Length < 2) {
|
||||
continue;
|
||||
}
|
||||
mes = segments[1].Split(';')[0];
|
||||
sequence = segmentsB[1].Split(';')[0];
|
||||
segmentsC = Path.GetFileName(fileInfo.DirectoryName).Split('-');
|
||||
|
@ -1,10 +1,9 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI5;
|
||||
|
||||
internal static partial class Helper20250219 {
|
||||
@ -42,10 +41,12 @@ internal static partial class Helper20250219 {
|
||||
ReadOnlyCollection<int> columnIndices = args[10].Split(',').Select(int.Parse).ToArray().AsReadOnly();
|
||||
foreach (string segment in segments) {
|
||||
segmentsB = segment.Split('|');
|
||||
if (segmentsB.Length != 2)
|
||||
if (segmentsB.Length != 2) {
|
||||
continue;
|
||||
if (distinct.Contains(segmentsB[0]))
|
||||
}
|
||||
if (distinct.Contains(segmentsB[0])) {
|
||||
continue;
|
||||
}
|
||||
distinct.Add(segmentsB[0]);
|
||||
keyValuePairs.Add(segmentsB[0], segmentsB[1]);
|
||||
}
|
||||
@ -77,13 +78,15 @@ internal static partial class Helper20250219 {
|
||||
directory = fileInfo.DirectoryName ?? throw new Exception();
|
||||
directoryFiles = Directory.GetFiles(directory, searchPattern, SearchOption.TopDirectoryOnly);
|
||||
matches = (from l in directoryFiles where l != fileInfo.FullName select l).ToArray();
|
||||
if (matches.Length < 1)
|
||||
if (matches.Length < 1) {
|
||||
continue;
|
||||
}
|
||||
directorySegment = directory[sourceDirectoryLength..];
|
||||
processDataStandardFormat = GetProcessDataStandardFormat(logger, fileInfo.LastWriteTime, pdsfMapping.NewColumnNames.Count, columnsLine, fileInfo.FullName, lines: null);
|
||||
jsonElementsNew = GetArray(logger, pdsfMapping.NewColumnNames.Count, processDataStandardFormat, lookForNumbers: false);
|
||||
if (jsonElementsNew is null)
|
||||
if (jsonElementsNew is null) {
|
||||
continue;
|
||||
}
|
||||
if (pdsfMapping.OldColumnNames.Count == pdsfMapping.ColumnIndices.Count) {
|
||||
processDataStandardFormat = GetProcessDataStandardFormat(logger, pdsfMapping, jsonElementsNew, processDataStandardFormat);
|
||||
Write(logger, fileInfo, processDataStandardFormat);
|
||||
@ -132,13 +135,15 @@ internal static partial class Helper20250219 {
|
||||
valueOld = jsonPropertyOld.Value.ToString();
|
||||
if (processDataStandardFormatMapping.KeyValuePairs.TryGetValue(jsonPropertyOld.Name, out string? name) && !string.IsNullOrEmpty(name)) {
|
||||
q = TryGetPropertyIndex(jsonPropertiesNew, name);
|
||||
if (q is null && i == 0)
|
||||
if (q is null && i == 0) {
|
||||
unknownColumns.Add($"{jsonPropertyOld.Name}|{name}");
|
||||
}
|
||||
} else {
|
||||
q = TryGetPropertyIndex(jsonPropertiesNew, jsonPropertyOld.Name);
|
||||
if (q is null) {
|
||||
if (i == 0)
|
||||
if (i == 0) {
|
||||
unknownColumns.Add(jsonPropertyOld.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (q is null) {
|
||||
@ -153,8 +158,9 @@ internal static partial class Helper20250219 {
|
||||
if (i == last) {
|
||||
columns.Add("-1");
|
||||
columnPairs.Add($"{jsonPropertyOld.Name}:");
|
||||
if (!string.IsNullOrEmpty(valueOld))
|
||||
if (!string.IsNullOrEmpty(valueOld)) {
|
||||
logger.LogDebug("{p} )) {jsonPropertyOld.Name} ??", p, jsonPropertyOld.Name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
jsonPropertyNew = jsonPropertiesNew[q.Value];
|
||||
@ -163,16 +169,19 @@ internal static partial class Helper20250219 {
|
||||
columnPairs.Add($"{jsonPropertyOld.Name}:{jsonPropertyNew.Name}");
|
||||
}
|
||||
valueNew = jsonPropertyNew.Value.ToString();
|
||||
if (i == last)
|
||||
if (i == last) {
|
||||
logger.LogDebug("{p} )) {jsonPropertyOld.Name} ~~ {q.Value} => {jsonPropertyNew.Name}", p, jsonPropertyOld.Name, q.Value, jsonPropertyNew.Name);
|
||||
}
|
||||
if (valueNew != valueOld && !differentColumns.Contains(jsonPropertyOld.Name)) {
|
||||
if (valueNew.Length >= 2 && valueNew.Split(' ')[0] == valueOld)
|
||||
if (valueNew.Length >= 2 && valueNew.Split(' ')[0] == valueOld) {
|
||||
sameAfterSpaceSplitColumns.Add(jsonPropertyOld.Name);
|
||||
else {
|
||||
if (processDataStandardFormatMapping.BackfillColumns.Contains(jsonPropertyOld.Name) && i != last)
|
||||
} else {
|
||||
if (processDataStandardFormatMapping.BackfillColumns.Contains(jsonPropertyOld.Name) && i != last) {
|
||||
continue;
|
||||
if (processDataStandardFormatMapping.IndexOnlyColumns.Contains(jsonPropertyOld.Name) && int.TryParse(jsonPropertyOld.Name[^2..], out int index) && i != index - 1)
|
||||
}
|
||||
if (processDataStandardFormatMapping.IndexOnlyColumns.Contains(jsonPropertyOld.Name) && int.TryParse(jsonPropertyOld.Name[^2..], out int index) && i != index - 1) {
|
||||
continue;
|
||||
}
|
||||
logger.LogWarning("For [{jsonProperty.Name}] <{directory}> doesn't match (valueNew:{valueNew} != valueOld:{valueOld})!", jsonPropertyOld.Name, directory, valueNew, valueOld);
|
||||
differentColumns.Add(jsonPropertyOld.Name);
|
||||
}
|
||||
@ -191,19 +200,23 @@ internal static partial class Helper20250219 {
|
||||
private static int? TryGetPropertyIndex(JsonProperty[] jsonProperties, string propertyName) {
|
||||
int? result = null;
|
||||
for (int i = 0; i < jsonProperties.Length; i++) {
|
||||
if (jsonProperties[i].Name != propertyName)
|
||||
if (jsonProperties[i].Name != propertyName) {
|
||||
continue;
|
||||
}
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
if (result is null) {
|
||||
for (int i = 0; i < jsonProperties.Length; i++) {
|
||||
if (jsonProperties[i].Name[0] != propertyName[0])
|
||||
if (jsonProperties[i].Name[0] != propertyName[0]) {
|
||||
continue;
|
||||
if (jsonProperties[i].Name.Length != propertyName.Length)
|
||||
}
|
||||
if (jsonProperties[i].Name.Length != propertyName.Length) {
|
||||
continue;
|
||||
if (jsonProperties[i].Name != propertyName)
|
||||
}
|
||||
if (jsonProperties[i].Name != propertyName) {
|
||||
continue;
|
||||
}
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
@ -219,9 +232,9 @@ internal static partial class Helper20250219 {
|
||||
List<string> logistics = [];
|
||||
bool lookForLogistics = false;
|
||||
lines ??= File.ReadAllLines(path);
|
||||
if (lines.Length <= columnsLine)
|
||||
if (lines.Length <= columnsLine) {
|
||||
segments = [];
|
||||
else {
|
||||
} else {
|
||||
segments = lines[columnsLine].Split('\t');
|
||||
if (segments.Length != expectedColumns) {
|
||||
logger.LogWarning("{segments} != {expectedColumns}", segments.Length, expectedColumns);
|
||||
@ -230,24 +243,26 @@ internal static partial class Helper20250219 {
|
||||
}
|
||||
string[] columns = segments.Select(l => l.Trim('"')).ToArray();
|
||||
for (int r = columnsLine + 1; r < lines.Length; r++) {
|
||||
if (lines[r].StartsWith("NUM_DATA_ROWS"))
|
||||
if (lines[r].StartsWith("NUM_DATA_ROWS")) {
|
||||
lookForLogistics = true;
|
||||
}
|
||||
if (!lookForLogistics) {
|
||||
body.Add(lines[r]);
|
||||
continue;
|
||||
}
|
||||
if (lines[r].StartsWith("LOGISTICS_1")) {
|
||||
for (int i = r; i < lines.Length; i++) {
|
||||
if (lines[r].StartsWith("END_HEADER"))
|
||||
if (lines[r].StartsWith("END_HEADER")) {
|
||||
break;
|
||||
}
|
||||
logistics.Add(lines[i]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (logistics.Count == 0)
|
||||
if (logistics.Count == 0) {
|
||||
sequence = lastWriteTime.Ticks;
|
||||
else {
|
||||
} else {
|
||||
segments = logistics[0].Split("SEQUENCE=");
|
||||
sequence = segments.Length < 2 || !long.TryParse(segments[1].Split(';')[0], out long s) ? lastWriteTime.Ticks : s;
|
||||
}
|
||||
@ -260,9 +275,9 @@ internal static partial class Helper20250219 {
|
||||
|
||||
private static JsonElement[]? GetArray(ILogger<Worker> logger, int expectedColumns, ProcessDataStandardFormat processDataStandardFormat, bool lookForNumbers) {
|
||||
JsonElement[]? results;
|
||||
if (processDataStandardFormat.Body.Count == 0 || !processDataStandardFormat.Body[0].Contains('\t'))
|
||||
if (processDataStandardFormat.Body.Count == 0 || !processDataStandardFormat.Body[0].Contains('\t')) {
|
||||
results = JsonSerializer.Deserialize("[]", JsonElementCollectionSourceGenerationContext.Default.JsonElementArray) ?? throw new Exception();
|
||||
else {
|
||||
} else {
|
||||
string value;
|
||||
string[] segments;
|
||||
List<string> lines = [];
|
||||
@ -283,12 +298,13 @@ internal static partial class Helper20250219 {
|
||||
} else {
|
||||
for (int c = 0; c < segments.Length; c++) {
|
||||
value = segments[c].Replace("\\", "\\\\").Replace("\"", "\\\"");
|
||||
if (string.IsNullOrEmpty(value))
|
||||
if (string.IsNullOrEmpty(value)) {
|
||||
_ = stringBuilder.Append('"').Append(processDataStandardFormat.Columns[c]).Append("\":").Append(value).Append("null,");
|
||||
else if (value.All(char.IsDigit))
|
||||
} else if (value.All(char.IsDigit)) {
|
||||
_ = stringBuilder.Append('"').Append(processDataStandardFormat.Columns[c]).Append("\":").Append(value).Append(',');
|
||||
else
|
||||
} else {
|
||||
_ = stringBuilder.Append('"').Append(processDataStandardFormat.Columns[c]).Append("\":\"").Append(value).Append("\",");
|
||||
}
|
||||
}
|
||||
}
|
||||
_ = stringBuilder.Remove(stringBuilder.Length - 1, 1);
|
||||
@ -323,9 +339,9 @@ internal static partial class Helper20250219 {
|
||||
}
|
||||
for (int c = 0; c < processDataStandardFormatMapping.ColumnIndices.Count; c++) {
|
||||
column = processDataStandardFormatMapping.ColumnIndices[c];
|
||||
if (column == -1)
|
||||
if (column == -1) {
|
||||
value = processDataStandardFormatMapping.OldColumnNames[c];
|
||||
else {
|
||||
} else {
|
||||
jsonProperty = jsonProperties[column];
|
||||
value = jsonProperty.Value.ToString();
|
||||
}
|
||||
@ -342,8 +358,9 @@ internal static partial class Helper20250219 {
|
||||
|
||||
private static void Write(ILogger<Worker> logger, FileInfo fileInfo, ProcessDataStandardFormat processDataStandardFormat) {
|
||||
List<string> results = [];
|
||||
if (processDataStandardFormat.Sequence is null)
|
||||
if (processDataStandardFormat.Sequence is null) {
|
||||
throw new NullReferenceException(nameof(processDataStandardFormat.Sequence));
|
||||
}
|
||||
string endOffset = "E#######T";
|
||||
string dataOffset = "D#######T";
|
||||
string headerOffset = "H#######T";
|
||||
|
@ -1,8 +1,7 @@
|
||||
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 {
|
||||
@ -15,18 +14,20 @@ internal static partial class Helper20250228 {
|
||||
string headerB = args[4].Replace('_', ' ');
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
if (files.Length != 1)
|
||||
if (files.Length != 1) {
|
||||
logger.LogWarning("<{files}>(s)", files.Length);
|
||||
else
|
||||
} 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)
|
||||
if (records.Count > 0) {
|
||||
WriteFile(file, records);
|
||||
else
|
||||
} else {
|
||||
logger.LogWarning("<{records}>(s)", records.Count);
|
||||
}
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<Record> GetRecords(string headerA, string headerB, string file) {
|
||||
@ -46,32 +47,38 @@ internal static partial class Helper20250228 {
|
||||
line = lines[i];
|
||||
if (tableName is null) {
|
||||
segmentsA = line.Split(headerA);
|
||||
if (segmentsA.Length != 2)
|
||||
if (segmentsA.Length != 2) {
|
||||
continue;
|
||||
}
|
||||
segmentsB = segmentsA[1].Split(headerB);
|
||||
if (segmentsB.Length != 2)
|
||||
if (segmentsB.Length != 2) {
|
||||
continue;
|
||||
}
|
||||
segmentsC = segmentsB[0].Split('(');
|
||||
if (segmentsC.Length != 2)
|
||||
if (segmentsC.Length != 2) {
|
||||
continue;
|
||||
}
|
||||
segmentsD = segmentsC[1].Split(')');
|
||||
if (segmentsD.Length != 2)
|
||||
if (segmentsD.Length != 2) {
|
||||
continue;
|
||||
}
|
||||
columns = segmentsD[0].Split(',').Select(l => l.Trim(' ').Trim('"')).ToArray().AsReadOnly();
|
||||
if (columns.Count == 0)
|
||||
if (columns.Count == 0) {
|
||||
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++) {
|
||||
i = j;
|
||||
segmentsF = lines[j].Split('\t');
|
||||
if (segmentsF.Length != columns.Count) {
|
||||
if (rows.Count > 0)
|
||||
if (rows.Count > 0) {
|
||||
results.Add(new(TableName: tableName, Columns: columns, Rows: rows.AsReadOnly()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
rows.Add(segmentsF);
|
||||
@ -93,10 +100,11 @@ internal static partial class Helper20250228 {
|
||||
foreach (string[] row in record.Rows) {
|
||||
keyValuePairs.Clear();
|
||||
for (int i = 0; i < row.Length; i++) {
|
||||
if (row[i] == "\\N")
|
||||
if (row[i] == "\\N") {
|
||||
keyValuePairs.Add(record.Columns[i], null);
|
||||
else
|
||||
} else {
|
||||
keyValuePairs.Add(record.Columns[i], row[i]);
|
||||
}
|
||||
}
|
||||
#pragma warning disable IL3050, IL2026
|
||||
json = JsonSerializer.Serialize(keyValuePairs);
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI5;
|
||||
|
||||
@ -14,23 +13,25 @@ internal static partial class Helper20250301 {
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
string workingDirectory = Path.GetFullPath(args[4]);
|
||||
string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
if (files.Length == 0)
|
||||
if (files.Length == 0) {
|
||||
logger.LogWarning("<{files}>(s)", files.Length);
|
||||
else
|
||||
} else {
|
||||
PocketBaseImportWithDeno(logger, split, workingDirectory, scriptName, directory, files);
|
||||
}
|
||||
}
|
||||
|
||||
private static void PocketBaseImportWithDeno(ILogger<Worker> logger, char split, string workingDirectory, string scriptName, string directory, string[] files) {
|
||||
string checkFile = Path.Combine(workingDirectory, scriptName);
|
||||
if (!File.Exists(checkFile))
|
||||
if (!File.Exists(checkFile)) {
|
||||
logger.LogWarning("<{checkFile}> doesn't exist!", checkFile);
|
||||
else {
|
||||
} else {
|
||||
ReadOnlyCollection<string> fileNames = CopyFiles(split, workingDirectory, directory, files);
|
||||
if (fileNames.Count == 0)
|
||||
if (fileNames.Count == 0) {
|
||||
logger.LogWarning("<{fileNames}>(s)", fileNames.Count);
|
||||
else {
|
||||
foreach (string fileName in fileNames)
|
||||
} else {
|
||||
foreach (string fileName in fileNames) {
|
||||
logger.LogInformation("deno run --unstable --allow-read --allow-env --allow-net {scriptName} --id=true --input={fileName}", scriptName, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -40,13 +41,15 @@ internal static partial class Helper20250301 {
|
||||
string fileName;
|
||||
string checkFile;
|
||||
string checkDirectory = Path.Combine(workingDirectory, directory);
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
if (!Directory.Exists(checkDirectory)) {
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
foreach (string file in files) {
|
||||
fileName = Path.GetFileName(file).Split(split)[^1];
|
||||
checkFile = Path.Combine(checkDirectory, fileName);
|
||||
if (File.Exists(checkFile))
|
||||
if (File.Exists(checkFile)) {
|
||||
File.Delete(checkFile);
|
||||
}
|
||||
File.Copy(file, checkFile);
|
||||
results.Add(fileName);
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
using File_Folder_Helper.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
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 Helper20250305 {
|
||||
@ -28,14 +26,15 @@ internal static partial class Helper20250305 {
|
||||
#if ShellProgressBar
|
||||
progressBar.Tick();
|
||||
#endif
|
||||
if (record.TotalSeconds is null)
|
||||
if (record.TotalSeconds is null) {
|
||||
Download(record);
|
||||
else if (record.TotalSeconds.Value == 0)
|
||||
} else if (record.TotalSeconds.Value == 0) {
|
||||
logger.LogInformation("Different lengths");
|
||||
else if (record.TotalSeconds.Value > 0)
|
||||
} else if (record.TotalSeconds.Value > 0) {
|
||||
logger.LogInformation("Overwrite remote (https)");
|
||||
else
|
||||
} else {
|
||||
logger.LogInformation("Overwrite local");
|
||||
}
|
||||
}
|
||||
#if ShellProgressBar
|
||||
progressBar.Dispose();
|
||||
@ -50,18 +49,21 @@ internal static partial class Helper20250305 {
|
||||
NginxFileSystem nginxFileSystem;
|
||||
ReadOnlyCollection<Record> records;
|
||||
string checkDirectory = $"{compareDirectory}\\{string.Join('\\', directoryNames)}";
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
if (!Directory.Exists(checkDirectory)) {
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
for (int i = 0; i < nginxFileSystems.Count; i++) {
|
||||
nginxFileSystem = NginxFileSystem.Get(format, timeZoneInfo, uri, nginxFileSystems[i]);
|
||||
if (nginxFileSystem.Type == "file") {
|
||||
Record? record = CompareFile(host, directoryNames, compareDirectory, nginxFileSystem);
|
||||
if (record is not null)
|
||||
if (record is not null) {
|
||||
results.Add(record);
|
||||
}
|
||||
} else {
|
||||
records = CompareDirectory(format, timeZoneInfo, host, directoryNames, compareDirectory, nginxFileSystem);
|
||||
foreach (Record record in records)
|
||||
foreach (Record record in records) {
|
||||
results.Add(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -72,18 +74,18 @@ internal static partial class Helper20250305 {
|
||||
List<NginxFileSystem>? results;
|
||||
Task<HttpResponseMessage> taskHttpResponseMessage = _HttpClient.GetAsync(uri);
|
||||
taskHttpResponseMessage.Wait();
|
||||
if (!taskHttpResponseMessage.Result.IsSuccessStatusCode)
|
||||
if (!taskHttpResponseMessage.Result.IsSuccessStatusCode) {
|
||||
results = null;
|
||||
else {
|
||||
} else {
|
||||
Task<string> taskString = taskHttpResponseMessage.Result.Content.ReadAsStringAsync();
|
||||
taskString.Wait();
|
||||
if (taskString.Result.StartsWith('<'))
|
||||
if (taskString.Result.StartsWith('<')) {
|
||||
results = null;
|
||||
else {
|
||||
} else {
|
||||
NginxFileSystem[]? nginxFileSystems = JsonSerializer.Deserialize(taskString.Result, NginxFileSystemCollectionSourceGenerationContext.Default.NginxFileSystemArray);
|
||||
if (nginxFileSystems is null)
|
||||
if (nginxFileSystems is null) {
|
||||
results = null;
|
||||
else {
|
||||
} else {
|
||||
results = [];
|
||||
NginxFileSystem nginxFileSystem;
|
||||
for (int i = 0; i < nginxFileSystems.Length; i++) {
|
||||
@ -98,21 +100,22 @@ internal static partial class Helper20250305 {
|
||||
|
||||
private static Record? CompareFile(string host, ReadOnlyCollection<string> directoryNames, string compareDirectory, NginxFileSystem nginxFileSystem) {
|
||||
Record? result;
|
||||
if (nginxFileSystem.LastModified is null || nginxFileSystem.Length is null)
|
||||
if (nginxFileSystem.LastModified is null || nginxFileSystem.Length is null) {
|
||||
result = null;
|
||||
else {
|
||||
} else {
|
||||
Uri uri = new($"https://{host}/{string.Join('/', directoryNames)}/{nginxFileSystem.Name}");
|
||||
FileInfo fileInfo = new($"{compareDirectory}\\{string.Join('\\', directoryNames)}\\{nginxFileSystem.Name}");
|
||||
if (!fileInfo.Exists)
|
||||
if (!fileInfo.Exists) {
|
||||
result = new(URI: uri, Path: fileInfo.FullName, LastModified: nginxFileSystem.LastModified.Value, TotalSeconds: null);
|
||||
else {
|
||||
} else {
|
||||
int totalSeconds = (int)new TimeSpan(fileInfo.LastWriteTime.Ticks - nginxFileSystem.LastModified.Value.Ticks).TotalSeconds;
|
||||
if (totalSeconds is not < 2 or not > -2)
|
||||
if (totalSeconds is not < 2 or not > -2) {
|
||||
result = new(URI: uri, Path: fileInfo.FullName, LastModified: nginxFileSystem.LastModified.Value, TotalSeconds: totalSeconds);
|
||||
else if (fileInfo.Length != nginxFileSystem.Length.Value)
|
||||
} else if (fileInfo.Length != nginxFileSystem.Length.Value) {
|
||||
result = new(URI: uri, Path: fileInfo.FullName, LastModified: nginxFileSystem.LastModified.Value, TotalSeconds: 0);
|
||||
else
|
||||
} else {
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -8,23 +8,24 @@ internal static partial class Helper20250306 {
|
||||
string searchPattern = args[2];
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.TopDirectoryOnly);
|
||||
if (files.Length != 1)
|
||||
if (files.Length != 1) {
|
||||
logger.LogWarning("<{files}>(s)", files.Length);
|
||||
else
|
||||
} else {
|
||||
ProcessDataStandardFormatToJson(logger, files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ProcessDataStandardFormatToJson(ILogger<Worker> logger, string file) {
|
||||
string[] lines = File.ReadAllLines(file);
|
||||
int? columnTitlesLine = GetProcessDataStandardFormatColumnTitlesLine(lines);
|
||||
if (columnTitlesLine is null)
|
||||
if (columnTitlesLine is null) {
|
||||
logger.LogWarning("<{columnTitlesLine}> is null", nameof(columnTitlesLine));
|
||||
else {
|
||||
} else {
|
||||
string? text = ProcessDataStandardFormatToLastDataLine(lines, columnTitlesLine.Value);
|
||||
File.WriteAllText(Path.Combine(".vscode", "helper", ".lbl"), text);
|
||||
if (lines.Length < columnTitlesLine.Value + 1)
|
||||
if (lines.Length < columnTitlesLine.Value + 1) {
|
||||
logger.LogWarning("<{lines}>(s)", lines.Length);
|
||||
else {
|
||||
} else {
|
||||
string json = ProcessDataStandardFormatToJson(columnTitlesLine.Value, [], lines);
|
||||
File.WriteAllText(Path.Combine(".vscode", "helper", ".json"), json);
|
||||
}
|
||||
@ -35,8 +36,9 @@ internal static partial class Helper20250306 {
|
||||
int? result = null;
|
||||
bool foundEndOfFile = false;
|
||||
for (int i = 0; i < lines.Length; i++) {
|
||||
if (lines[i] == "EOF")
|
||||
if (lines[i] == "EOF") {
|
||||
foundEndOfFile = true;
|
||||
}
|
||||
if (foundEndOfFile && lines[i].StartsWith("END_OFFSET") && i + 3 < lines.Length) {
|
||||
result = i + 2;
|
||||
break;
|
||||
@ -62,14 +64,16 @@ internal static partial class Helper20250306 {
|
||||
string line;
|
||||
string value;
|
||||
string[] segments;
|
||||
if (columns.Length == 0)
|
||||
if (columns.Length == 0) {
|
||||
columns = lines[columnTitlesLine].Trim().Split('|');
|
||||
}
|
||||
int columnsLength = columns.Length - 2;
|
||||
for (int i = columnTitlesLine + 1; i < lines.Length; i++) {
|
||||
line = "{";
|
||||
segments = lines[i].Trim().Split('|');
|
||||
if (segments.Length != columnsLength)
|
||||
if (segments.Length != columnsLength) {
|
||||
continue;
|
||||
}
|
||||
for (int c = 1; c < segments.Length; c++) {
|
||||
value = segments[c].Replace("\\", "\\\\").Replace("\"", "\\\"");
|
||||
line += '"' + columns[c].Trim('"') + '"' + ':' + '"' + value + '"' + ',';
|
||||
|
@ -11,16 +11,17 @@ internal static partial class Helper20250315 {
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
if (searchPatterns.Length == 1) {
|
||||
string[] files = Directory.GetFiles(sourceDirectory, searchPatterns[0], SearchOption.AllDirectories);
|
||||
if (files.Length == 0)
|
||||
if (files.Length == 0) {
|
||||
logger.LogWarning("<{files}>(s)", files.Length);
|
||||
else {
|
||||
} else {
|
||||
string directoryName;
|
||||
string[] directories;
|
||||
foreach (string file in files) {
|
||||
directoryName = Path.GetDirectoryName(file) ?? throw new Exception();
|
||||
directories = Directory.GetDirectories(directoryName, "*", SearchOption.TopDirectoryOnly);
|
||||
foreach (string directory in directories)
|
||||
foreach (string directory in directories) {
|
||||
HelperDeleteEmptyDirectories.DeleteEmptyDirectories(logger, directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -29,13 +30,14 @@ internal static partial class Helper20250315 {
|
||||
HelperDeleteEmptyDirectories.DeleteEmptyDirectories(logger, sourceDirectory);
|
||||
foreach (string searchPattern in searchPatterns) {
|
||||
files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
if (files.Length == 0)
|
||||
if (files.Length == 0) {
|
||||
logger.LogWarning("<{files}>(s)", files.Length);
|
||||
else {
|
||||
} else {
|
||||
foreach (string file in files) {
|
||||
checkFile = $"{file}.json";
|
||||
if (File.Exists(checkFile))
|
||||
if (File.Exists(checkFile)) {
|
||||
continue;
|
||||
}
|
||||
File.Move(file, checkFile);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI5;
|
||||
|
||||
internal static partial class Helper20250320 {
|
||||
@ -40,7 +39,6 @@ internal static partial class Helper20250320 {
|
||||
string result = JsonSerializer.Serialize(this, MethodCollectionCommonSourceGenerationContext.Default.Method);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
@ -63,7 +61,6 @@ internal static partial class Helper20250320 {
|
||||
string result = JsonSerializer.Serialize(this, MethodCollectionCommonSourceGenerationContext.Default.Method);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
@ -102,8 +99,9 @@ internal static partial class Helper20250320 {
|
||||
string[] cSharpFiles = Directory.GetFiles(repositoryDirectory, "*.cs", SearchOption.AllDirectories);
|
||||
ReadOnlyCollection<string> gitOthersModifiedAndDeletedExcludingStandardFiles = logOnly ? new(cSharpFiles) : Helpers.HelperGit.GetOthersModifiedAndDeletedExcludingStandardFiles(repositoryDirectory, usePathCombine, cancellationToken);
|
||||
foreach (string cSharpFile in cSharpFiles) {
|
||||
if (!gitOthersModifiedAndDeletedExcludingStandardFiles.Contains(cSharpFile))
|
||||
if (!gitOthersModifiedAndDeletedExcludingStandardFiles.Contains(cSharpFile)) {
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < 10; i++) {
|
||||
lines = File.ReadAllLines(cSharpFile);
|
||||
check = SortFile(logger, logOnly, scopeSpaces, cSharpFile, lines);
|
||||
@ -111,34 +109,38 @@ internal static partial class Helper20250320 {
|
||||
Thread.Sleep(500);
|
||||
changed.Add($"{i + 1:00}) {cSharpFile}");
|
||||
}
|
||||
if (logOnly || !check)
|
||||
if (logOnly || !check) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changed.Count == 0)
|
||||
if (changed.Count == 0) {
|
||||
logger.LogInformation("No changes :)");
|
||||
else {
|
||||
} else {
|
||||
changed.Reverse();
|
||||
foreach (string c in changed)
|
||||
foreach (string c in changed) {
|
||||
logger.LogInformation(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool SortFile(ILogger<Worker> logger, bool logOnly, int scopeSpaces, string cSharpFile, string[] lines) {
|
||||
bool result;
|
||||
ReadOnlyCollection<Method> methods = GetMethods(logger, scopeSpaces, cSharpFile, lines);
|
||||
if (methods.Count == 0)
|
||||
if (methods.Count == 0) {
|
||||
result = false;
|
||||
else if (methods.Any(l => l.EndLine is null))
|
||||
} else if (methods.Any(l => l.EndLine is null)) {
|
||||
result = false;
|
||||
else if (logOnly) {
|
||||
foreach (Method method in methods)
|
||||
} else if (logOnly) {
|
||||
foreach (Method method in methods) {
|
||||
logger.LogInformation("{cSharpFile} - {Name} has {lines} line(s)", cSharpFile, method.Match.Name, (method.EndLine is null ? 999999 : method.EndLine.Value - method.StartLine).ToString("000000"));
|
||||
}
|
||||
result = false;
|
||||
} else {
|
||||
ReadOnlyCollection<Method> sortedMethods = GetSortedMethods(methods);
|
||||
if (Debugger.IsAttached)
|
||||
if (Debugger.IsAttached) {
|
||||
File.WriteAllText(Path.Combine(".vscode", "helper", ".json"), JsonSerializer.Serialize(sortedMethods.ToArray(), MethodCollectionCommonSourceGenerationContext.Default.MethodArray));
|
||||
}
|
||||
ReadOnlyCollection<MethodWith> collection = GetCollection(logger, lines, sortedMethods);
|
||||
result = WriteAllLines(cSharpFile, lines, collection);
|
||||
}
|
||||
@ -166,18 +168,23 @@ internal static partial class Helper20250320 {
|
||||
System.Text.RegularExpressions.Match regularExpressionsMatch;
|
||||
for (int i = 0; i < lines.Length; i++) {
|
||||
check = GetNumberOfStartSpaces(lines, i);
|
||||
if (check != scopeSpaces)
|
||||
if (check != scopeSpaces) {
|
||||
continue;
|
||||
}
|
||||
line = lines[i].Trim();
|
||||
if (string.IsNullOrEmpty(line))
|
||||
if (string.IsNullOrEmpty(line)) {
|
||||
continue;
|
||||
if (line.Length < 5)
|
||||
}
|
||||
if (line.Length < 5) {
|
||||
continue;
|
||||
if (line.EndsWith(','))
|
||||
}
|
||||
if (line.EndsWith(',')) {
|
||||
continue;
|
||||
}
|
||||
regularExpressionsMatch = CSharpMethodLine().Match(line);
|
||||
if (!regularExpressionsMatch.Success)
|
||||
if (!regularExpressionsMatch.Success) {
|
||||
continue;
|
||||
}
|
||||
match = new(Async: regularExpressionsMatch.Groups[_Async].Value,
|
||||
Name: regularExpressionsMatch.Groups[_Name].Value,
|
||||
Parameters: regularExpressionsMatch.Groups[_Parameters].Value,
|
||||
@ -194,50 +201,61 @@ internal static partial class Helper20250320 {
|
||||
Not: $"!{match.Name}(",
|
||||
Wrap: $"({match.Name}(");
|
||||
logger.LogInformation("{line} {a} // {results}", line.Split(" =>")[0], "{ }", results.Count);
|
||||
if (string.IsNullOrEmpty(match.Name))
|
||||
if (string.IsNullOrEmpty(match.Name)) {
|
||||
continue;
|
||||
}
|
||||
blocks = 0;
|
||||
startLine = GetStartLine(lines, i);
|
||||
if (!lines[startLine].StartsWith("#pragma") && !lines[startLine].StartsWith("#nullable"))
|
||||
if (!lines[startLine].StartsWith("#pragma") && !lines[startLine].StartsWith("#nullable")) {
|
||||
firstLine = lines[startLine].Trim();
|
||||
else
|
||||
} else {
|
||||
firstLine = lines[startLine + 1].Trim();
|
||||
}
|
||||
isLinq = !lines[i + 1].StartsWith("#pragma") && !lines[i + 1].StartsWith("#nullable") && lines[i].Trim()[^1] != '{' && lines[i + 1].Trim() != "{";
|
||||
if (isLinq)
|
||||
if (isLinq) {
|
||||
blocks++;
|
||||
}
|
||||
endLine = null;
|
||||
if (lines[i].Trim()[^1] == '{')
|
||||
if (lines[i].Trim()[^1] == '{') {
|
||||
blocks++;
|
||||
}
|
||||
for (int j = i + 1; j < lines.Length; j++) {
|
||||
innerLine = lines[j].Trim();
|
||||
if (innerLine.StartsWith("#pragma") || innerLine.StartsWith("#nullable"))
|
||||
if (innerLine.StartsWith("#pragma") || innerLine.StartsWith("#nullable")) {
|
||||
continue;
|
||||
}
|
||||
if (isLinq && string.IsNullOrEmpty(innerLine)) {
|
||||
if (line.EndsWith(';'))
|
||||
if (line.EndsWith(';')) {
|
||||
blocks--;
|
||||
}
|
||||
}
|
||||
blocks += GetLineBlockCount(innerLine, isLinq);
|
||||
if (blocks != 0)
|
||||
if (blocks != 0) {
|
||||
continue;
|
||||
}
|
||||
endLine = j;
|
||||
if (lines.Length > j + 1 && string.IsNullOrEmpty(lines[j + 1].Trim()))
|
||||
if (lines.Length > j + 1 && string.IsNullOrEmpty(lines[j + 1].Trim())) {
|
||||
endLine++;
|
||||
if (j > lines.Length - 2)
|
||||
}
|
||||
if (j > lines.Length - 2) {
|
||||
throw new Exception();
|
||||
}
|
||||
break;
|
||||
}
|
||||
referenceToLineNumbers = GetReferenceToLineNumbers(lines: lines, start: 0, end: lines.Length, i: i, search: search, parameters: parameters);
|
||||
if (referenceToLineNumbers.Count == 0) {
|
||||
lineSegmentFirst = line.Split(match.Name)[0];
|
||||
if (!lines[i - 1].Trim().StartsWith("[Obsolete")) {
|
||||
if (lineSegmentFirst.StartsWith("private"))
|
||||
if (lineSegmentFirst.StartsWith("private")) {
|
||||
logger.LogWarning("// <{cSharpFileName}> {name} with {parameters} parameter(s) <{line}>", Path.GetFileName(cSharpFile), match.Name, parameters, lineSegmentFirst);
|
||||
else
|
||||
} else {
|
||||
logger.LogInformation("// <{cSharpFileName}> {name} with {parameters} parameter(s) <{line}>", Path.GetFileName(cSharpFile), match.Name, parameters, lineSegmentFirst);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (referenceToLineNumbers.Count == 0)
|
||||
if (referenceToLineNumbers.Count == 0) {
|
||||
referenceToLineNumbers.Add(-1);
|
||||
}
|
||||
logger.LogInformation("{line} {a} // {results} ~~~ {startLine} => {firstUsedLine}", line.Split(" =>")[0], "{ }", results.Count, startLine, referenceToLineNumbers.First());
|
||||
method = new(EndLine: endLine,
|
||||
FirstLine: firstLine,
|
||||
@ -257,8 +275,9 @@ internal static partial class Helper20250320 {
|
||||
private static int GetNumberOfStartSpaces(string[] lines, int i) {
|
||||
int result = 0;
|
||||
foreach (char @char in lines[i]) {
|
||||
if (@char != ' ')
|
||||
if (@char != ' ') {
|
||||
break;
|
||||
}
|
||||
result += 1;
|
||||
}
|
||||
return result;
|
||||
@ -289,8 +308,9 @@ internal static partial class Helper20250320 {
|
||||
System.Text.RegularExpressions.Match[] matches = parameterRegex.Matches($"{match.Parameters},").ToArray();
|
||||
try {
|
||||
foreach (System.Text.RegularExpressions.Match m in matches) {
|
||||
if (!m.Success)
|
||||
if (!m.Success) {
|
||||
continue;
|
||||
}
|
||||
value = m.Value.Trim()[..^1];
|
||||
segments = value.Split(' ');
|
||||
results.Add(segments[^1], value);
|
||||
@ -300,8 +320,9 @@ internal static partial class Helper20250320 {
|
||||
System.Text.RegularExpressions.Match m;
|
||||
for (int i = 0; i < matches.Length; i++) {
|
||||
m = matches[i];
|
||||
if (!m.Success)
|
||||
if (!m.Success) {
|
||||
continue;
|
||||
}
|
||||
results.Add(i.ToString(), i.ToString());
|
||||
}
|
||||
}
|
||||
@ -313,8 +334,9 @@ internal static partial class Helper20250320 {
|
||||
string line;
|
||||
for (int j = i - 1; j > -1; j--) {
|
||||
line = lines[j].Trim();
|
||||
if (!line.StartsWith('[') && !line.StartsWith('#') && !line.StartsWith("/// "))
|
||||
if (!line.StartsWith('[') && !line.StartsWith('#') && !line.StartsWith("/// ")) {
|
||||
break;
|
||||
}
|
||||
result--;
|
||||
}
|
||||
return result;
|
||||
@ -324,16 +346,17 @@ internal static partial class Helper20250320 {
|
||||
int result = 0;
|
||||
bool ignore = false;
|
||||
for (int i = 0; i < line.Length; i++) {
|
||||
if (line[i] == '\'')
|
||||
if (line[i] == '\'') {
|
||||
i++;
|
||||
else if (!isLinq && !ignore && line[i] == '{')
|
||||
} else if (!isLinq && !ignore && line[i] == '{') {
|
||||
result++;
|
||||
else if (!isLinq && !ignore && line[i] == '}')
|
||||
} else if (!isLinq && !ignore && line[i] == '}') {
|
||||
result--;
|
||||
else if (isLinq && !ignore && line[i] == ';')
|
||||
} else if (isLinq && !ignore && line[i] == ';') {
|
||||
result--;
|
||||
else if (i > 0 && line[i] == '"' && line[i - 1] != '\\')
|
||||
} else if (i > 0 && line[i] == '"' && line[i - 1] != '\\') {
|
||||
ignore = !ignore;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -344,8 +367,9 @@ internal static partial class Helper20250320 {
|
||||
string[] afterSegments;
|
||||
string lastSegmentBeforeDot;
|
||||
for (int j = start; j < end; j++) {
|
||||
if (j == i)
|
||||
if (j == i) {
|
||||
continue;
|
||||
}
|
||||
segments = lines[j].Split(search.Name);
|
||||
if (segments.Length == 1) {
|
||||
segments = lines[j].Split(search.Not);
|
||||
@ -354,23 +378,26 @@ internal static partial class Helper20250320 {
|
||||
if (segments.Length == 1) {
|
||||
if (!lines[j].EndsWith(search.Delegate)) {
|
||||
segments = lines[j].Split(search.Constructor);
|
||||
if (segments.Length == 1)
|
||||
if (segments.Length == 1) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (lines[j].EndsWith(search.Delegate))
|
||||
if (lines[j].EndsWith(search.Delegate)) {
|
||||
results.Add(j);
|
||||
else {
|
||||
} else {
|
||||
lastSegmentBeforeDot = segments[^1].Split(").")[0];
|
||||
if (parameters.Count == 0) {
|
||||
if (lastSegmentBeforeDot.Contains(','))
|
||||
if (lastSegmentBeforeDot.Contains(',')) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
afterSegments = lastSegmentBeforeDot.Split(',');
|
||||
if (afterSegments.Length != parameters.Count)
|
||||
if (afterSegments.Length != parameters.Count) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
results.Add(j);
|
||||
}
|
||||
@ -383,10 +410,12 @@ internal static partial class Helper20250320 {
|
||||
List<Method> check = sortedMethods.ToList();
|
||||
foreach (Method method in sortedMethods) {
|
||||
logger.LogInformation($"{method.Match.Name} => {method.Parameters.Count}");
|
||||
if (method.EndLine is null)
|
||||
if (method.EndLine is null) {
|
||||
continue;
|
||||
if (!check.Remove(method))
|
||||
}
|
||||
if (!check.Remove(method)) {
|
||||
continue;
|
||||
}
|
||||
MethodWith methodWith = GetMethodWith(lines, sortedMethods, check, method, method.EndLine.Value);
|
||||
results.Add(methodWith);
|
||||
}
|
||||
@ -399,27 +428,32 @@ internal static partial class Helper20250320 {
|
||||
MethodWith[] sortedReferences;
|
||||
Dictionary<int, MethodWith> references = [];
|
||||
foreach (Method m in methods) {
|
||||
if (m.EndLine is null)
|
||||
if (m.EndLine is null) {
|
||||
continue;
|
||||
if (m == method)
|
||||
}
|
||||
if (m == method) {
|
||||
continue;
|
||||
}
|
||||
referenceToLineNumbers = GetReferenceToLineNumbers(lines: lines, start: method.StartLine, end: methodEndLineValue, i: -1, search: m.Search, parameters: m.Parameters);
|
||||
if (referenceToLineNumbers.Count > 0) {
|
||||
if (!check.Remove(m))
|
||||
if (!check.Remove(m)) {
|
||||
continue;
|
||||
}
|
||||
foreach (int i in referenceToLineNumbers) {
|
||||
if (references.ContainsKey(i))
|
||||
if (references.ContainsKey(i)) {
|
||||
continue;
|
||||
}
|
||||
methodWith = GetMethodWith(lines, methods, check, m, m.EndLine.Value);
|
||||
references.Add(i, methodWith);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (references.Count < 2)
|
||||
if (references.Count < 2) {
|
||||
sortedReferences = (from l in references select l.Value).ToArray();
|
||||
else
|
||||
} else {
|
||||
sortedReferences = (from l in references orderby l.Key select l.Value).ToArray();
|
||||
}
|
||||
methodWith = new(EndLine: method.EndLine,
|
||||
FirstLine: method.FirstLine,
|
||||
Line: method.Line,
|
||||
@ -435,29 +469,33 @@ internal static partial class Helper20250320 {
|
||||
|
||||
private static bool WriteAllLines(string cSharpFile, string[] lines, ReadOnlyCollection<MethodWith> collection) {
|
||||
bool result;
|
||||
if (Debugger.IsAttached)
|
||||
if (Debugger.IsAttached) {
|
||||
WriteDebug(collection);
|
||||
}
|
||||
List<string> results = [];
|
||||
ReadOnlyCollection<int> methodLines = GetMethodLines(collection);
|
||||
int maxMethodLines = methodLines.Max();
|
||||
for (int i = 0; i < maxMethodLines; i++) {
|
||||
if (methodLines.Contains(i))
|
||||
if (methodLines.Contains(i)) {
|
||||
continue;
|
||||
}
|
||||
results.Add(lines[i]);
|
||||
}
|
||||
List<bool> nests = [true];
|
||||
foreach (MethodWith methodWith in collection) {
|
||||
if (methodWith.EndLine is null)
|
||||
if (methodWith.EndLine is null) {
|
||||
continue;
|
||||
}
|
||||
AppendLines(results, nests, lines, methodWith, methodWith.EndLine.Value);
|
||||
}
|
||||
for (int i = maxMethodLines + 1; i < lines.Length; i++)
|
||||
for (int i = maxMethodLines + 1; i < lines.Length; i++) {
|
||||
results.Add(lines[i]);
|
||||
}
|
||||
string text = File.ReadAllText(cSharpFile);
|
||||
string join = string.Join(Environment.NewLine, results);
|
||||
if (join == text)
|
||||
if (join == text) {
|
||||
result = false;
|
||||
else {
|
||||
} else {
|
||||
result = true;
|
||||
File.WriteAllText(cSharpFile, join);
|
||||
}
|
||||
@ -467,16 +505,18 @@ internal static partial class Helper20250320 {
|
||||
private static void WriteDebug(ReadOnlyCollection<MethodWith> collection) {
|
||||
List<string> results = [];
|
||||
List<bool> nests = [true];
|
||||
foreach (MethodWith methodWith in collection)
|
||||
foreach (MethodWith methodWith in collection) {
|
||||
AppendLines(results, nests, methodWith);
|
||||
}
|
||||
File.WriteAllText(Path.Combine(".vscode", "helper", ".md"), string.Join(Environment.NewLine, results));
|
||||
}
|
||||
|
||||
private static void AppendLines(List<string> results, List<bool> nests, MethodWith methodWith) {
|
||||
nests.Add(true);
|
||||
results.Add($" - {new string('#', nests.Count)} {methodWith.Match.Name} => {methodWith.Parameters.Count}");
|
||||
foreach (MethodWith m in methodWith.References)
|
||||
foreach (MethodWith m in methodWith.References) {
|
||||
AppendLines(results, nests, m);
|
||||
}
|
||||
nests.RemoveAt(nests.Count - 1);
|
||||
}
|
||||
|
||||
@ -484,23 +524,27 @@ internal static partial class Helper20250320 {
|
||||
List<int> results = [];
|
||||
List<bool> nests = [true];
|
||||
foreach (MethodWith methodWith in collection) {
|
||||
if (methodWith.EndLine is null)
|
||||
if (methodWith.EndLine is null) {
|
||||
continue;
|
||||
}
|
||||
AppendLineNumbers(results, nests, methodWith, methodWith.EndLine.Value);
|
||||
}
|
||||
int[] distinct = results.Distinct().ToArray();
|
||||
if (distinct.Length != results.Count)
|
||||
if (distinct.Length != results.Count) {
|
||||
throw new Exception();
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static void AppendLineNumbers(List<int> results, List<bool> nests, MethodWith methodWith, int methodWithEndLineValue) {
|
||||
nests.Add(true);
|
||||
for (int i = methodWith.StartLine; i < methodWithEndLineValue + 1; i++)
|
||||
for (int i = methodWith.StartLine; i < methodWithEndLineValue + 1; i++) {
|
||||
results.Add(i);
|
||||
}
|
||||
foreach (MethodWith m in methodWith.References) {
|
||||
if (m.EndLine is null)
|
||||
if (m.EndLine is null) {
|
||||
continue;
|
||||
}
|
||||
AppendLineNumbers(results, nests, m, m.EndLine.Value);
|
||||
}
|
||||
nests.RemoveAt(nests.Count - 1);
|
||||
@ -508,11 +552,13 @@ internal static partial class Helper20250320 {
|
||||
|
||||
private static void AppendLines(List<string> results, List<bool> nests, string[] lines, MethodWith methodWith, int methodWithEndLineValue) {
|
||||
nests.Add(true);
|
||||
for (int i = methodWith.StartLine; i < methodWithEndLineValue + 1; i++)
|
||||
for (int i = methodWith.StartLine; i < methodWithEndLineValue + 1; i++) {
|
||||
results.Add(lines[i]);
|
||||
}
|
||||
foreach (MethodWith m in methodWith.References) {
|
||||
if (m.EndLine is null)
|
||||
if (m.EndLine is null) {
|
||||
continue;
|
||||
}
|
||||
AppendLines(results, nests, lines, m, m.EndLine.Value);
|
||||
}
|
||||
nests.RemoveAt(nests.Count - 1);
|
||||
|
@ -1,8 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
using File_Folder_Helper.Helpers;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI5;
|
||||
|
||||
@ -21,14 +19,15 @@ internal static partial class Helper20250321 {
|
||||
bool check = searchPattern.Split('.').Length == 3;
|
||||
ReadOnlyCollection<ThreeDeep> collection = ThreeDeep.GetCollection(files);
|
||||
foreach (ThreeDeep threeDeep in collection) {
|
||||
if (!json && check)
|
||||
if (!json && check) {
|
||||
fileNameWithoutExtension = threeDeep.DirectoryName;
|
||||
else if (!json && !check)
|
||||
} else if (!json && !check) {
|
||||
fileNameWithoutExtension = threeDeep.FileNameWithoutExtension;
|
||||
else if (json)
|
||||
} else if (json) {
|
||||
fileNameWithoutExtension = Path.GetFileNameWithoutExtension(threeDeep.FileNameWithoutExtension);
|
||||
else
|
||||
} else {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
directory = $"{fileNameWithoutExtension[^1]}{fileNameWithoutExtension[^3..][..2]}";
|
||||
if (json || (!json && !check)) {
|
||||
record = new(Directory: Path.Combine(sourceDirectory, "new-a", directory),
|
||||
@ -38,13 +37,13 @@ internal static partial class Helper20250321 {
|
||||
record = new(Directory: Path.Combine(sourceDirectory, "new-b", directory, threeDeep.DirectoryName),
|
||||
File: $"{threeDeep.FileNameWithoutExtension}{threeDeep.Extension}",
|
||||
ThreeDeep: threeDeep);
|
||||
} else
|
||||
} else {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
results.Add(record);
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private record ThreeDeep(string Extension,
|
||||
@ -83,17 +82,19 @@ internal static partial class Helper20250321 {
|
||||
internal static void MoveToLast(ILogger<Worker> logger, List<string> args) {
|
||||
string[] searchPatterns = args[2].Split('~');
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
if (searchPatterns.Length == 1)
|
||||
if (searchPatterns.Length == 1) {
|
||||
logger.LogInformation("No code for just one!");
|
||||
else {
|
||||
} else {
|
||||
HelperDeleteEmptyDirectories.DeleteEmptyDirectories(logger, sourceDirectory);
|
||||
ReadOnlyCollection<Record> collection = GetCollection(logger, searchPatterns, sourceDirectory);
|
||||
if (collection.Count != 0)
|
||||
if (collection.Count != 0) {
|
||||
UseCollection(collection);
|
||||
else
|
||||
} else {
|
||||
logger.LogInformation("No files!");
|
||||
if (collection.Count != 0)
|
||||
}
|
||||
if (collection.Count != 0) {
|
||||
HelperDeleteEmptyDirectories.DeleteEmptyDirectories(logger, sourceDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,9 +103,9 @@ internal static partial class Helper20250321 {
|
||||
List<Record> results = [];
|
||||
foreach (string searchPattern in searchPatterns) {
|
||||
files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
if (files.Length == 0)
|
||||
if (files.Length == 0) {
|
||||
logger.LogWarning("<{files}>(s)", files.Length);
|
||||
else {
|
||||
} else {
|
||||
ReadOnlyCollection<Record> collection = Record.GetCollection(sourceDirectory, searchPattern, files);
|
||||
results.AddRange(collection);
|
||||
}
|
||||
@ -117,19 +118,22 @@ internal static partial class Helper20250321 {
|
||||
string checkFile;
|
||||
List<string> distinct = [];
|
||||
foreach (Record record in collection) {
|
||||
if (distinct.Contains(record.Directory))
|
||||
if (distinct.Contains(record.Directory)) {
|
||||
continue;
|
||||
}
|
||||
distinct.Add(record.Directory);
|
||||
}
|
||||
foreach (string directory in distinct) {
|
||||
if (Directory.Exists(directory))
|
||||
if (Directory.Exists(directory)) {
|
||||
continue;
|
||||
}
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
}
|
||||
foreach (Record record in collection) {
|
||||
checkFile = Path.Combine(record.Directory, record.File);
|
||||
if (File.Exists(checkFile))
|
||||
if (File.Exists(checkFile)) {
|
||||
continue;
|
||||
}
|
||||
fullPath = ThreeDeep.GetFullPath(record.ThreeDeep);
|
||||
File.Move(fullPath, checkFile);
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI5;
|
||||
|
||||
internal static partial class Helper20250404 {
|
||||
@ -128,10 +127,11 @@ internal static partial class Helper20250404 {
|
||||
ParseMetrics(logger, fileName, url);
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
if (files.Length == 0)
|
||||
if (files.Length == 0) {
|
||||
logger.LogWarning("<{files}>(s)", files.Length);
|
||||
else
|
||||
} else {
|
||||
KumaToGatus(files);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ParseMetrics(ILogger<Worker> logger, string fileName, string url) {
|
||||
@ -174,12 +174,14 @@ internal static partial class Helper20250404 {
|
||||
string checkFile;
|
||||
foreach (string file in files) {
|
||||
checkFile = file.ToLower().Replace('_', '-');
|
||||
if (checkFile != file)
|
||||
if (checkFile != file) {
|
||||
File.Move(file, checkFile);
|
||||
}
|
||||
json = File.ReadAllText(checkFile);
|
||||
kuma = JsonSerializer.Deserialize(json, KumaCommonSourceGenerationContext.Default.Kuma);
|
||||
if (kuma is null)
|
||||
if (kuma is null) {
|
||||
continue;
|
||||
}
|
||||
WriteGatus(checkFile, kuma);
|
||||
}
|
||||
}
|
||||
@ -193,8 +195,9 @@ internal static partial class Helper20250404 {
|
||||
];
|
||||
string[] segments;
|
||||
foreach (MonitorList monitorList in kuma.MonitorList) {
|
||||
if (monitorList.Type is not "http" and not "postgres")
|
||||
if (monitorList.Type is not "http" and not "postgres") {
|
||||
continue;
|
||||
}
|
||||
results.Add($" - name: {monitorList.Name}");
|
||||
results.Add($" group: {monitorList.PathName.Split(' ')[0]}");
|
||||
results.Add($" enabled: {monitorList.Active.ToString().ToLower()}");
|
||||
@ -208,19 +211,22 @@ internal static partial class Helper20250404 {
|
||||
}
|
||||
results.Add(" conditions:");
|
||||
results.Add(" - \"[STATUS] < 300\"");
|
||||
if (monitorList.Url.Contains("https"))
|
||||
if (monitorList.Url.Contains("https")) {
|
||||
results.Add(" - \"[CERTIFICATE_EXPIRATION] > 48h\"");
|
||||
}
|
||||
results.Add($" - \"[RESPONSE_TIME] < {monitorList.Timeout}\"");
|
||||
} else if (monitorList.Type == "postgres") {
|
||||
segments = monitorList.DatabaseConnectionString.Split('@');
|
||||
if (segments.Length != 2)
|
||||
if (segments.Length != 2) {
|
||||
continue;
|
||||
}
|
||||
results.Add($" # connectionString: \"{monitorList.DatabaseConnectionString}\"");
|
||||
results.Add($" url: \"tcp://{segments[1].Split('/')[0]}\"");
|
||||
results.Add(" conditions:");
|
||||
results.Add(" - \"[CONNECTED] == true\"");
|
||||
} else
|
||||
} else {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
results.Add(" alerts:");
|
||||
results.Add(" - type: email");
|
||||
results.Add(" description: \"healthcheck failed\"");
|
||||
|
@ -1,12 +1,10 @@
|
||||
using File_Folder_Helper.Models;
|
||||
using Microsoft.Extensions.FileSystemGlobbing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using File_Folder_Helper.Models;
|
||||
|
||||
using Microsoft.Extensions.FileSystemGlobbing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
#if ShellProgressBar
|
||||
using ShellProgressBar;
|
||||
#endif
|
||||
@ -65,53 +63,53 @@ internal static partial class Helper20250407 {
|
||||
const int rightSideOnlyIndex = 4;
|
||||
const int leftSideIsNewerIndex = 1;
|
||||
const int rightSideIsNewerIndex = 3;
|
||||
if (string.IsNullOrEmpty(segments[leftSideOnlyIndex]))
|
||||
if (string.IsNullOrEmpty(segments[leftSideOnlyIndex])) {
|
||||
leftSideOnly = null;
|
||||
else if (segments[leftSideOnlyIndex][0] == plus)
|
||||
} else if (segments[leftSideOnlyIndex][0] == plus) {
|
||||
leftSideOnly = true;
|
||||
else if (segments[leftSideOnlyIndex][0] == minus)
|
||||
} else if (segments[leftSideOnlyIndex][0] == minus) {
|
||||
leftSideOnly = false;
|
||||
else {
|
||||
} else {
|
||||
check = false;
|
||||
leftSideOnly = null;
|
||||
}
|
||||
if (string.IsNullOrEmpty(segments[leftSideIsNewerIndex]))
|
||||
if (string.IsNullOrEmpty(segments[leftSideIsNewerIndex])) {
|
||||
leftSideIsNewer = null;
|
||||
else if (segments[leftSideIsNewerIndex][0] == greaterThan)
|
||||
} else if (segments[leftSideIsNewerIndex][0] == greaterThan) {
|
||||
leftSideIsNewer = true;
|
||||
else if (segments[leftSideIsNewerIndex][0] == lessThan)
|
||||
} else if (segments[leftSideIsNewerIndex][0] == lessThan) {
|
||||
leftSideIsNewer = false;
|
||||
else {
|
||||
} else {
|
||||
check = false;
|
||||
leftSideIsNewer = null;
|
||||
}
|
||||
if (string.IsNullOrEmpty(segments[notEqualButIndex]))
|
||||
if (string.IsNullOrEmpty(segments[notEqualButIndex])) {
|
||||
notEqualBut = null;
|
||||
else if (segments[notEqualButIndex][0] == greaterThan)
|
||||
} else if (segments[notEqualButIndex][0] == greaterThan) {
|
||||
notEqualBut = true;
|
||||
else if (segments[notEqualButIndex][0] == lessThan)
|
||||
} else if (segments[notEqualButIndex][0] == lessThan) {
|
||||
notEqualBut = false;
|
||||
else {
|
||||
} else {
|
||||
check = false;
|
||||
notEqualBut = null;
|
||||
}
|
||||
if (string.IsNullOrEmpty(segments[rightSideIsNewerIndex]))
|
||||
if (string.IsNullOrEmpty(segments[rightSideIsNewerIndex])) {
|
||||
rightSideIsNewer = null;
|
||||
else if (segments[rightSideIsNewerIndex][0] == greaterThan)
|
||||
} else if (segments[rightSideIsNewerIndex][0] == greaterThan) {
|
||||
rightSideIsNewer = true;
|
||||
else if (segments[rightSideIsNewerIndex][0] == lessThan)
|
||||
} else if (segments[rightSideIsNewerIndex][0] == lessThan) {
|
||||
rightSideIsNewer = false;
|
||||
else {
|
||||
} else {
|
||||
check = false;
|
||||
rightSideIsNewer = null;
|
||||
}
|
||||
if (string.IsNullOrEmpty(segments[rightSideOnlyIndex]))
|
||||
if (string.IsNullOrEmpty(segments[rightSideOnlyIndex])) {
|
||||
rightSideOnly = null;
|
||||
else if (segments[rightSideOnlyIndex][0] == plus)
|
||||
} else if (segments[rightSideOnlyIndex][0] == plus) {
|
||||
rightSideOnly = true;
|
||||
else if (segments[rightSideOnlyIndex][0] == minus)
|
||||
} else if (segments[rightSideOnlyIndex][0] == minus) {
|
||||
rightSideOnly = false;
|
||||
else {
|
||||
} else {
|
||||
check = false;
|
||||
rightSideOnly = null;
|
||||
}
|
||||
@ -160,9 +158,9 @@ internal static partial class Helper20250407 {
|
||||
matcher.AddIncludePatterns(!File.Exists(includePatternsFile) ? ["*"] : File.ReadAllLines(includePatternsFile));
|
||||
matcher.AddExcludePatterns(!File.Exists(excludePatternsFile) ? ["System Volume Information"] : File.ReadAllLines(excludePatternsFile));
|
||||
ReadOnlyCollection<Record> rightRecords = GetRecords(rightDirectory, matcher);
|
||||
if (rightRecords.Count == 0)
|
||||
if (rightRecords.Count == 0) {
|
||||
logger.LogInformation("No source records");
|
||||
else {
|
||||
} else {
|
||||
string checkFile = Path.Combine(rightDirectory, fileName);
|
||||
Review review = new(AreEqual: null,
|
||||
LeftSideIsNewer: null,
|
||||
@ -173,9 +171,9 @@ internal static partial class Helper20250407 {
|
||||
RightSideOnly: null);
|
||||
string json = JsonSerializer.Serialize(review, ReviewCommonSourceGenerationContext.Default.Review);
|
||||
WriteAllText(checkFile, json);
|
||||
if (rootUniformResourceLocators.Length == 0)
|
||||
if (rootUniformResourceLocators.Length == 0) {
|
||||
logger.LogInformation("No urls");
|
||||
else {
|
||||
} else {
|
||||
string format = NginxFileSystem.GetFormat();
|
||||
TimeZoneInfo timeZoneInfo = TimeZoneInfo.Local;
|
||||
Sync(logger, rightDirectory, fileName, logic, rootUniformResourceLocators, rightRecords, format, timeZoneInfo);
|
||||
@ -194,11 +192,13 @@ internal static partial class Helper20250407 {
|
||||
ReadOnlyCollection<ReadOnlyCollection<string>> collection = Helpers.HelperDirectory.GetFilesCollection(rightDirectory, "*", "*");
|
||||
foreach (ReadOnlyCollection<string> c in collection) {
|
||||
foreach (string f in c) {
|
||||
if (!matcher.Match(rightDirectory, f).HasMatches)
|
||||
if (!matcher.Match(rightDirectory, f).HasMatches) {
|
||||
continue;
|
||||
}
|
||||
fileInfo = new(f);
|
||||
if (fileInfo.Length == 0)
|
||||
if (fileInfo.Length == 0) {
|
||||
continue;
|
||||
}
|
||||
relativePath = Path.GetRelativePath(rightDirectory, fileInfo.FullName);
|
||||
record = new(RelativePath: relativePath,
|
||||
Size: fileInfo.Length,
|
||||
@ -211,20 +211,21 @@ internal static partial class Helper20250407 {
|
||||
|
||||
private static void WriteAllText(string path, string text) {
|
||||
string check = !File.Exists(path) ? string.Empty : File.ReadAllText(path);
|
||||
if (check != text)
|
||||
if (check != text) {
|
||||
File.WriteAllText(path, text);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Sync(ILogger<Worker> logger, string rightDirectory, string fileName, Logic? logic, string[] rootUniformResourceLocators, ReadOnlyCollection<Record> rightRecords, string format, TimeZoneInfo timeZoneInfo) {
|
||||
Review? review;
|
||||
foreach (string rootUniformResourceLocator in rootUniformResourceLocators) {
|
||||
if (!rootUniformResourceLocator.StartsWith("https:"))
|
||||
if (!rootUniformResourceLocator.StartsWith("https:")) {
|
||||
logger.LogInformation("Not supported URL <{url}>", rootUniformResourceLocator);
|
||||
else {
|
||||
} else {
|
||||
review = GetJsonResponse(logger, fileName, rootUniformResourceLocator, format, timeZoneInfo);
|
||||
if (review?.Records is null || review.Records.Length == 0)
|
||||
if (review?.Records is null || review.Records.Length == 0) {
|
||||
logger.LogInformation("No response records");
|
||||
else {
|
||||
} else {
|
||||
ReadOnlyCollection<Record> leftRecords = review.Records.AsReadOnly();
|
||||
Sync(logger, rightDirectory, fileName, logic, rightRecords, rootUniformResourceLocator, leftRecords);
|
||||
}
|
||||
@ -285,8 +286,9 @@ internal static partial class Helper20250407 {
|
||||
match = nginxFileSystem.LastModified.Value;
|
||||
continue;
|
||||
}
|
||||
if (nginxFileSystem.LastModified is null || nginxFileSystem.LastModified <= dateTime)
|
||||
if (nginxFileSystem.LastModified is null || nginxFileSystem.LastModified <= dateTime) {
|
||||
continue;
|
||||
}
|
||||
dateTime = nginxFileSystem.LastModified.Value;
|
||||
}
|
||||
result = match is not null && match.Value > dateTime;
|
||||
@ -298,8 +300,9 @@ internal static partial class Helper20250407 {
|
||||
string checkFile;
|
||||
HttpClient httpClient = new();
|
||||
checkFile = Path.Combine(rightDirectory, fileName);
|
||||
if (File.Exists(checkFile))
|
||||
if (File.Exists(checkFile)) {
|
||||
File.Delete(checkFile);
|
||||
}
|
||||
ReadOnlyCollection<Segment> areEqual = GetAreEqual(rightDirectory, fileName, rightRecords, rootUniformResourceLocators, leftRecords);
|
||||
ReadOnlyCollection<Segment> notEqualBut = GetNotEqualBut(rightDirectory, fileName, rightRecords, rootUniformResourceLocators, leftRecords);
|
||||
ReadOnlyCollection<Segment> leftSideOnly = GetLeftSideOnly(rightDirectory, fileName, rightRecords, rootUniformResourceLocators, leftRecords);
|
||||
@ -316,26 +319,36 @@ internal static partial class Helper20250407 {
|
||||
json = JsonSerializer.Serialize(review, ReviewCommonSourceGenerationContext.Default.Review);
|
||||
checkFile = Path.Combine(rightDirectory, fileName);
|
||||
WriteAllText(checkFile, json);
|
||||
if (notEqualBut.Count > 0 && l is not null && l.NotEqualBut is not null && l.Raw[l.NotEqualButIndex][0] == l.Minus && !l.NotEqualBut.Value)
|
||||
if (notEqualBut.Count > 0 && l is not null && l.NotEqualBut is not null && l.Raw[l.NotEqualButIndex][0] == l.Minus && !l.NotEqualBut.Value) {
|
||||
logger.LogDebug("Doing nothing with {name}", nameof(Logic.NotEqualBut));
|
||||
if (leftSideOnly.Count > 0 && l is not null && l.LeftSideOnly is not null && l.Raw[l.LeftSideOnlyIndex][0] == l.Minus && !l.LeftSideOnly.Value)
|
||||
}
|
||||
if (leftSideOnly.Count > 0 && l is not null && l.LeftSideOnly is not null && l.Raw[l.LeftSideOnlyIndex][0] == l.Minus && !l.LeftSideOnly.Value) {
|
||||
throw new NotImplementedException("Not possible with https!");
|
||||
if (leftSideIsNewer.Count > 0 && l is not null && l.LeftSideIsNewer is not null && l.Raw[l.LeftSideIsNewerIndex][0] == l.LessThan && !l.LeftSideIsNewer.Value)
|
||||
}
|
||||
if (leftSideIsNewer.Count > 0 && l is not null && l.LeftSideIsNewer is not null && l.Raw[l.LeftSideIsNewerIndex][0] == l.LessThan && !l.LeftSideIsNewer.Value) {
|
||||
throw new NotImplementedException("Not possible with https!");
|
||||
if (rightSideIsNewer.Count > 0 && l is not null && l.RightSideIsNewer is not null && l.Raw[l.RightSideIsNewerIndex][0] == l.LessThan && !l.RightSideIsNewer.Value)
|
||||
}
|
||||
if (rightSideIsNewer.Count > 0 && l is not null && l.RightSideIsNewer is not null && l.Raw[l.RightSideIsNewerIndex][0] == l.LessThan && !l.RightSideIsNewer.Value) {
|
||||
throw new NotImplementedException("Not possible with https!");
|
||||
if (rightSideOnly.Count > 0 && l is not null && l.RightSideOnly is not null && l.Raw[l.RightSideOnlyIndex][0] == l.Plus && l.RightSideOnly.Value)
|
||||
}
|
||||
if (rightSideOnly.Count > 0 && l is not null && l.RightSideOnly is not null && l.Raw[l.RightSideOnlyIndex][0] == l.Plus && l.RightSideOnly.Value) {
|
||||
throw new NotImplementedException("Not possible with https!");
|
||||
if (rightSideOnly.Count > 0 && l is not null && l.RightSideOnly is not null && l.Raw[l.RightSideOnlyIndex][0] == l.Minus && !l.RightSideOnly.Value)
|
||||
}
|
||||
if (rightSideOnly.Count > 0 && l is not null && l.RightSideOnly is not null && l.Raw[l.RightSideOnlyIndex][0] == l.Minus && !l.RightSideOnly.Value) {
|
||||
DoWork(logger, rightDirectory, httpClient, rightSideOnly, delete: true, download: false);
|
||||
if (leftSideOnly.Count > 0 && l is not null && l.LeftSideOnly is not null && l.Raw[l.LeftSideOnlyIndex][0] == l.Plus && l.LeftSideOnly.Value)
|
||||
}
|
||||
if (leftSideOnly.Count > 0 && l is not null && l.LeftSideOnly is not null && l.Raw[l.LeftSideOnlyIndex][0] == l.Plus && l.LeftSideOnly.Value) {
|
||||
DoWork(logger, rightDirectory, httpClient, leftSideOnly, delete: false, download: true);
|
||||
if (leftSideIsNewer.Count > 0 && l is not null && l.LeftSideIsNewer is not null && l.Raw[l.LeftSideIsNewerIndex][0] == l.GreaterThan && l.LeftSideIsNewer.Value)
|
||||
}
|
||||
if (leftSideIsNewer.Count > 0 && l is not null && l.LeftSideIsNewer is not null && l.Raw[l.LeftSideIsNewerIndex][0] == l.GreaterThan && l.LeftSideIsNewer.Value) {
|
||||
DoWork(logger, rightDirectory, httpClient, leftSideIsNewer, delete: true, download: true);
|
||||
if (notEqualBut.Count > 0 && l is not null && l.NotEqualBut is not null && l.Raw[l.NotEqualButIndex][0] == l.Plus && l.NotEqualBut.Value)
|
||||
}
|
||||
if (notEqualBut.Count > 0 && l is not null && l.NotEqualBut is not null && l.Raw[l.NotEqualButIndex][0] == l.Plus && l.NotEqualBut.Value) {
|
||||
DoWork(logger, rightDirectory, httpClient, notEqualBut, delete: true, download: true);
|
||||
if (rightSideIsNewer.Count > 0 && l is not null && l.RightSideIsNewer is not null && l.Raw[l.RightSideIsNewerIndex][0] == l.GreaterThan && l.RightSideIsNewer.Value)
|
||||
}
|
||||
if (rightSideIsNewer.Count > 0 && l is not null && l.RightSideIsNewer is not null && l.Raw[l.RightSideIsNewerIndex][0] == l.GreaterThan && l.RightSideIsNewer.Value) {
|
||||
DoWork(logger, rightDirectory, httpClient, rightSideIsNewer, delete: true, download: true);
|
||||
}
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<Segment> GetAreEqual(string rightDirectory, string fileName, ReadOnlyCollection<Record> rightRecords, string rootUniformResourceLocators, ReadOnlyCollection<Record> leftRecords) {
|
||||
@ -350,13 +363,16 @@ internal static partial class Helper20250407 {
|
||||
checkDirectory = r.RelativePath;
|
||||
continue;
|
||||
}
|
||||
if (r.RelativePath == rightDirectory || r.RelativePath == fileName)
|
||||
if (r.RelativePath == rightDirectory || r.RelativePath == fileName) {
|
||||
continue;
|
||||
if (!keyValuePairs.TryGetValue(r.RelativePath, out record))
|
||||
}
|
||||
if (!keyValuePairs.TryGetValue(r.RelativePath, out record)) {
|
||||
continue;
|
||||
}
|
||||
totalSeconds = new TimeSpan(record.Ticks - r.Ticks).TotalSeconds;
|
||||
if (record.Size != r.Size || totalSeconds is > 2 or < -2)
|
||||
if (record.Size != r.Size || totalSeconds is > 2 or < -2) {
|
||||
continue;
|
||||
}
|
||||
segment = new(Left: r,
|
||||
LeftDirectory: checkDirectory,
|
||||
Right: record,
|
||||
@ -369,8 +385,9 @@ internal static partial class Helper20250407 {
|
||||
|
||||
private static ReadOnlyDictionary<string, Record> GetKeyValuePairs(ReadOnlyCollection<Record> records) {
|
||||
Dictionary<string, Record> results = [];
|
||||
foreach (Record record in records)
|
||||
foreach (Record record in records) {
|
||||
results.Add(record.RelativePath, record);
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
@ -386,15 +403,19 @@ internal static partial class Helper20250407 {
|
||||
checkDirectory = r.RelativePath;
|
||||
continue;
|
||||
}
|
||||
if (r.RelativePath == rightDirectory || r.RelativePath == fileName)
|
||||
if (r.RelativePath == rightDirectory || r.RelativePath == fileName) {
|
||||
continue;
|
||||
if (!keyValuePairs.TryGetValue(r.RelativePath, out record))
|
||||
}
|
||||
if (!keyValuePairs.TryGetValue(r.RelativePath, out record)) {
|
||||
continue;
|
||||
if (record.Size == r.Size)
|
||||
}
|
||||
if (record.Size == r.Size) {
|
||||
continue;
|
||||
}
|
||||
totalSeconds = new TimeSpan(record.Ticks - r.Ticks).TotalSeconds;
|
||||
if (totalSeconds is >= 2 or <= -2)
|
||||
if (totalSeconds is >= 2 or <= -2) {
|
||||
continue;
|
||||
}
|
||||
segment = new(Left: r,
|
||||
LeftDirectory: checkDirectory,
|
||||
Right: record,
|
||||
@ -416,10 +437,12 @@ internal static partial class Helper20250407 {
|
||||
checkDirectory = r.RelativePath;
|
||||
continue;
|
||||
}
|
||||
if (r.RelativePath == rightDirectory || r.RelativePath == fileName)
|
||||
if (r.RelativePath == rightDirectory || r.RelativePath == fileName) {
|
||||
continue;
|
||||
if (keyValuePairs.TryGetValue(r.RelativePath, out record))
|
||||
}
|
||||
if (keyValuePairs.TryGetValue(r.RelativePath, out record)) {
|
||||
continue;
|
||||
}
|
||||
segment = new(Left: r,
|
||||
LeftDirectory: checkDirectory,
|
||||
Right: record,
|
||||
@ -441,10 +464,12 @@ internal static partial class Helper20250407 {
|
||||
checkDirectory = r.RelativePath;
|
||||
continue;
|
||||
}
|
||||
if (r.RelativePath == rightDirectory || r.RelativePath == fileName)
|
||||
if (r.RelativePath == rightDirectory || r.RelativePath == fileName) {
|
||||
continue;
|
||||
if (keyValuePairs.TryGetValue(r.RelativePath, out record))
|
||||
}
|
||||
if (keyValuePairs.TryGetValue(r.RelativePath, out record)) {
|
||||
continue;
|
||||
}
|
||||
segment = new(Left: record,
|
||||
LeftDirectory: null,
|
||||
Right: r,
|
||||
@ -467,13 +492,16 @@ internal static partial class Helper20250407 {
|
||||
checkDirectory = r.RelativePath;
|
||||
continue;
|
||||
}
|
||||
if (r.RelativePath == rightDirectory || r.RelativePath == fileName)
|
||||
if (r.RelativePath == rightDirectory || r.RelativePath == fileName) {
|
||||
continue;
|
||||
if (!keyValuePairs.TryGetValue(r.RelativePath, out record))
|
||||
}
|
||||
if (!keyValuePairs.TryGetValue(r.RelativePath, out record)) {
|
||||
continue;
|
||||
}
|
||||
totalSeconds = new TimeSpan(record.Ticks - r.Ticks).TotalSeconds;
|
||||
if (totalSeconds is > -2)
|
||||
if (totalSeconds is > -2) {
|
||||
continue;
|
||||
}
|
||||
segment = new(Left: r,
|
||||
LeftDirectory: checkDirectory,
|
||||
Right: record,
|
||||
@ -496,13 +524,16 @@ internal static partial class Helper20250407 {
|
||||
checkDirectory = r.RelativePath;
|
||||
continue;
|
||||
}
|
||||
if (r.RelativePath == rightDirectory || r.RelativePath == fileName)
|
||||
if (r.RelativePath == rightDirectory || r.RelativePath == fileName) {
|
||||
continue;
|
||||
if (!keyValuePairs.TryGetValue(r.RelativePath, out record))
|
||||
}
|
||||
if (!keyValuePairs.TryGetValue(r.RelativePath, out record)) {
|
||||
continue;
|
||||
}
|
||||
totalSeconds = new TimeSpan(record.Ticks - r.Ticks).TotalSeconds;
|
||||
if (totalSeconds is > -2)
|
||||
if (totalSeconds is > -2) {
|
||||
continue;
|
||||
}
|
||||
segment = new(Left: record,
|
||||
LeftDirectory: null,
|
||||
Right: r,
|
||||
@ -546,20 +577,6 @@ internal static partial class Helper20250407 {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string GetDurationWithSuffix(long ticks) {
|
||||
string result;
|
||||
TimeSpan timeSpan = new(DateTime.Now.Ticks - ticks);
|
||||
if (timeSpan.TotalMilliseconds < 1000)
|
||||
result = $"{timeSpan.Milliseconds} ms";
|
||||
else if (timeSpan.TotalMilliseconds < 60000)
|
||||
result = $"{Math.Floor(timeSpan.TotalSeconds)} s";
|
||||
else if (timeSpan.TotalMilliseconds < 3600000)
|
||||
result = $"{Math.Floor(timeSpan.TotalMinutes)} m";
|
||||
else
|
||||
result = $"{Math.Floor(timeSpan.TotalHours)} h";
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void DoDeletes(ILogger<Worker> logger, string rightDirectory, ReadOnlyCollection<Segment> segments) {
|
||||
Record? record;
|
||||
string size;
|
||||
@ -572,8 +589,9 @@ internal static partial class Helper20250407 {
|
||||
progressBar.Tick();
|
||||
#endif
|
||||
record = segments[i].Right;
|
||||
if (record is null)
|
||||
if (record is null) {
|
||||
continue;
|
||||
}
|
||||
size = GetSizeWithSuffix(record.Size);
|
||||
try {
|
||||
File.Delete(Path.Combine(rightDirectory, record.RelativePath));
|
||||
@ -609,9 +627,9 @@ internal static partial class Helper20250407 {
|
||||
size = GetSizeWithSuffix(download.Size);
|
||||
httpResponseMessage = httpClient.GetAsync(download.UniformResourceLocator);
|
||||
httpResponseMessage.Wait(-1);
|
||||
if (!httpResponseMessage.Result.IsSuccessStatusCode)
|
||||
if (!httpResponseMessage.Result.IsSuccessStatusCode) {
|
||||
logger.LogInformation("Failed to download: <{checkURL}> - {size};", download.UniformResourceLocator, size);
|
||||
else {
|
||||
} else {
|
||||
response = httpResponseMessage.Result.Content.ReadAsStringAsync();
|
||||
response.Wait();
|
||||
try {
|
||||
@ -643,19 +661,24 @@ internal static partial class Helper20250407 {
|
||||
List<Download> collection = [];
|
||||
string? checkUniformResourceLocator;
|
||||
foreach (Segment segment in segments) {
|
||||
if (segment.Left is null)
|
||||
if (segment.Left is null) {
|
||||
continue;
|
||||
}
|
||||
checkFile = Path.Combine(rightDirectory, segment.Left.RelativePath);
|
||||
checkDirectory = Path.GetDirectoryName(checkFile);
|
||||
if (string.IsNullOrEmpty(checkDirectory))
|
||||
if (string.IsNullOrEmpty(checkDirectory)) {
|
||||
continue;
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
}
|
||||
if (!Directory.Exists(checkDirectory)) {
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
if (File.Exists(checkFile) && new FileInfo(checkFile).Length == 0)
|
||||
}
|
||||
if (File.Exists(checkFile) && new FileInfo(checkFile).Length == 0) {
|
||||
File.Delete(checkFile);
|
||||
}
|
||||
checkUniformResourceLocator = ConvertTo(segment.RootUniformResourceLocator, segment.Left.RelativePath);
|
||||
if (string.IsNullOrEmpty(checkUniformResourceLocator))
|
||||
if (string.IsNullOrEmpty(checkUniformResourceLocator)) {
|
||||
continue;
|
||||
}
|
||||
download = new(Directory: checkDirectory,
|
||||
Display: checkUniformResourceLocator[segment.RootUniformResourceLocator.Length..],
|
||||
File: checkFile,
|
||||
@ -666,12 +689,15 @@ internal static partial class Helper20250407 {
|
||||
}
|
||||
Download[] sorted = (from l in collection orderby l.Size select l).ToArray();
|
||||
int stop = sorted.Length < 100 ? sorted.Length : 100;
|
||||
for (int i = 0; i < stop; i++)
|
||||
for (int i = 0; i < stop; i++) {
|
||||
results.Add(sorted[i]);
|
||||
for (int i = sorted.Length - 1; i > stop - 1; i--)
|
||||
}
|
||||
for (int i = sorted.Length - 1; i > stop - 1; i--) {
|
||||
results.Add(sorted[i]);
|
||||
if (collection.Count != results.Count)
|
||||
}
|
||||
if (collection.Count != results.Count) {
|
||||
throw new Exception();
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
@ -682,12 +708,28 @@ internal static partial class Helper20250407 {
|
||||
string fileName = Path.GetFileName(windowsMock);
|
||||
ReadOnlyCollection<string> directoryNames = Helpers.HelperDirectory.GetDirectoryNames(windowsMock);
|
||||
foreach (string directoryName in directoryNames) {
|
||||
if (directoryName == windowsRoot || directoryName == fileName)
|
||||
if (directoryName == windowsRoot || directoryName == fileName) {
|
||||
continue;
|
||||
}
|
||||
result = $"{result}/{directoryName}";
|
||||
}
|
||||
result = result == rootURL ? null : $"{result}/{fileName}";
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string GetDurationWithSuffix(long ticks) {
|
||||
string result;
|
||||
TimeSpan timeSpan = new(DateTime.Now.Ticks - ticks);
|
||||
if (timeSpan.TotalMilliseconds < 1000) {
|
||||
result = $"{timeSpan.Milliseconds} ms";
|
||||
} else if (timeSpan.TotalMilliseconds < 60000) {
|
||||
result = $"{Math.Floor(timeSpan.TotalSeconds)} s";
|
||||
} else if (timeSpan.TotalMilliseconds < 3600000) {
|
||||
result = $"{Math.Floor(timeSpan.TotalMinutes)} m";
|
||||
} else {
|
||||
result = $"{Math.Floor(timeSpan.TotalHours)} h";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -8,15 +8,17 @@ internal static partial class Helper20250421 {
|
||||
string searchPattern = args[2];
|
||||
string[] searchPatterns = args[3].Split('~');
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
if (searchPatterns.Length != 2)
|
||||
if (searchPatterns.Length != 2) {
|
||||
throw new NotImplementedException($"Not the correct number of {searchPatterns} were passed!");
|
||||
}
|
||||
string lastSyncSearch = $"{searchPatterns[0]}=\"";
|
||||
string configurationFileSearch = $"{searchPatterns[1]}=\"";
|
||||
string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
|
||||
if (files.Length != 1)
|
||||
if (files.Length != 1) {
|
||||
logger.LogWarning("<{files}>(s)", files.Length);
|
||||
else
|
||||
} else {
|
||||
ChangeCreatedDate(lastSyncSearch, configurationFileSearch, files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ChangeCreatedDate(string lastSyncSearch, string configurationFileSearch, string sourceFile) {
|
||||
@ -29,17 +31,21 @@ internal static partial class Helper20250421 {
|
||||
string[] lines = File.ReadAllLines(sourceFile);
|
||||
foreach (string line in lines) {
|
||||
segments = line.Split(lastSyncSearch);
|
||||
if (segments.Length != 2)
|
||||
if (segments.Length != 2) {
|
||||
continue;
|
||||
}
|
||||
segmentsB = line.Split(configurationFileSearch);
|
||||
if (segmentsB.Length != 2)
|
||||
if (segmentsB.Length != 2) {
|
||||
continue;
|
||||
}
|
||||
lastSync = segments[1].Split('"')[0];
|
||||
if (!long.TryParse(lastSync, out epoch) || epoch == 0)
|
||||
if (!long.TryParse(lastSync, out epoch) || epoch == 0) {
|
||||
continue;
|
||||
}
|
||||
configurationFile = segmentsB[1].Split('"')[0];
|
||||
if (!File.Exists(configurationFile))
|
||||
if (!File.Exists(configurationFile)) {
|
||||
continue;
|
||||
}
|
||||
creationTime = new(DateTimeOffset.UnixEpoch.AddSeconds(epoch).ToLocalTime().Ticks);
|
||||
File.SetCreationTime(configurationFile, creationTime);
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
using File_Folder_Helper.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
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 {
|
||||
@ -15,29 +13,11 @@ internal static partial class Helper20250429 {
|
||||
string searchPattern = args[2];
|
||||
string sourceDirectory = Path.GetFullPath(args[0]);
|
||||
ReadOnlyCollection<Record> subDirectories = GetSubDirectories(searchPattern, sourceDirectory);
|
||||
if (subDirectories.Count == 0)
|
||||
if (subDirectories.Count == 0) {
|
||||
logger.LogWarning("<{results}>(s)", subDirectories.Count);
|
||||
else
|
||||
} 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) {
|
||||
@ -60,13 +40,34 @@ internal static partial class Helper20250429 {
|
||||
Length: fileInfo.Length);
|
||||
results.Add(JsonSerializer.Serialize(nginxFileSystem, NginxFileSystemSingleLineSourceGenerationContext.Default.NginxFileSystem));
|
||||
}
|
||||
if (results.Count == 0)
|
||||
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)
|
||||
if (result == lines) {
|
||||
continue;
|
||||
}
|
||||
File.WriteAllText(record.File, result);
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
@ -21,12 +21,15 @@ internal static partial class Helper20250505 {
|
||||
// <PackageReference Include="iText.pdfhtml" Version="6.1.0" />
|
||||
|
||||
internal static void HyperTextMarkupLanguageToPortableDocumentFormat(ILogger<Worker> logger, List<string> args) {
|
||||
if (args.Count == 999)
|
||||
if (args.Count == 999) {
|
||||
TestA();
|
||||
if (args.Count == 999)
|
||||
}
|
||||
if (args.Count == 999) {
|
||||
TestB();
|
||||
if (args.Count != 999)
|
||||
}
|
||||
if (args.Count != 999) {
|
||||
TestC(logger);
|
||||
}
|
||||
}
|
||||
|
||||
private static void TestA() {
|
||||
|
@ -28,7 +28,7 @@ csharp_new_line_before_members_in_anonymous_types = true
|
||||
csharp_new_line_before_members_in_object_initializers = true
|
||||
csharp_new_line_before_open_brace = none
|
||||
csharp_new_line_between_query_expression_clauses = true
|
||||
csharp_prefer_braces = false
|
||||
csharp_prefer_braces = true
|
||||
csharp_prefer_qualified_reference = true:error
|
||||
csharp_prefer_simple_default_expression = true:warning
|
||||
csharp_prefer_simple_using_statement = true:warning
|
||||
|
@ -18,7 +18,6 @@ internal static partial class Helper20250519 {
|
||||
string result = JsonSerializer.Serialize(this, Helper20250519RelativePath.Default.RelativePath);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
@ -38,7 +37,6 @@ internal static partial class Helper20250519 {
|
||||
string result = JsonSerializer.Serialize(this, Helper20250519Review.Default.Review);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
@ -342,22 +340,6 @@ internal static partial class Helper20250519 {
|
||||
}
|
||||
}
|
||||
|
||||
private static void LiveSync(ILogger<Worker> logger, string page, RelativePath relativePath, HttpClient httpClient, string? directory, ReadOnlyCollection<Record> records, HttpMethod? httpMethod, bool delete) {
|
||||
long sum;
|
||||
try { sum = records.Sum(l => l.Size); } catch (Exception) { sum = 0; }
|
||||
string size = GetSizeWithSuffix(sum);
|
||||
if (delete) {
|
||||
logger.LogInformation("Starting to delete {count} file(s) [{sum}]", records.Count, size);
|
||||
PreformDeletes(logger, relativePath.RightDirectory, records);
|
||||
logger.LogInformation("Deleted {count} file(s) [{sum}]", records.Count, size);
|
||||
}
|
||||
if (httpMethod is not null) {
|
||||
logger.LogInformation("Starting to {httpMethod} {count} file(s) [{sum}]", httpMethod.ToString().ToLower(), records.Count, size);
|
||||
Preform(logger, page, directory, records, httpClient, httpMethod);
|
||||
logger.LogInformation("{httpMethod}'ed {count} file(s) [{sum}]", httpMethod.ToString(), records.Count, size);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetSizeWithSuffix(long value) {
|
||||
string result;
|
||||
int i = 0;
|
||||
@ -374,6 +356,68 @@ internal static partial class Helper20250519 {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string GetDurationWithSuffix(long ticks) {
|
||||
string result;
|
||||
TimeSpan timeSpan = new(DateTime.Now.Ticks - ticks);
|
||||
if (timeSpan.TotalMilliseconds < 1000) {
|
||||
result = $"{timeSpan.Milliseconds} ms";
|
||||
} else if (timeSpan.TotalMilliseconds < 60000) {
|
||||
result = $"{Math.Floor(timeSpan.TotalSeconds)} s";
|
||||
} else if (timeSpan.TotalMilliseconds < 3600000) {
|
||||
result = $"{Math.Floor(timeSpan.TotalMinutes)} m";
|
||||
} else {
|
||||
result = $"{Math.Floor(timeSpan.TotalHours)} h";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<Verb> GetVerbCollection(string? directory, ReadOnlyCollection<Record> records) {
|
||||
List<Verb> results = [];
|
||||
Verb verb;
|
||||
string checkFile;
|
||||
string checkFileName;
|
||||
string? checkDirectory;
|
||||
List<Verb> collection = [];
|
||||
foreach (Record record in records) {
|
||||
if (string.IsNullOrEmpty(directory)) {
|
||||
continue;
|
||||
}
|
||||
checkFile = Path.Combine(directory, record.RelativePath);
|
||||
checkFileName = Path.GetFileName(checkFile);
|
||||
checkDirectory = Path.GetDirectoryName(checkFile);
|
||||
if (string.IsNullOrEmpty(checkDirectory)) {
|
||||
continue;
|
||||
}
|
||||
if (!Directory.Exists(checkDirectory)) {
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
if (File.Exists(checkFile) && new FileInfo(checkFile).Length == 0) {
|
||||
File.Delete(checkFile);
|
||||
}
|
||||
verb = new(Directory: checkDirectory,
|
||||
Display: $"{checkFileName}{Environment.NewLine}{checkDirectory}",
|
||||
File: checkFile,
|
||||
Multipart: $"RelativePath:{record.RelativePath}|Size:{record.Size}|Ticks:{record.Ticks};",
|
||||
RelativePath: record.RelativePath,
|
||||
Size: record.Size,
|
||||
Ticks: record.Ticks,
|
||||
UrlEncodedFile: HttpUtility.UrlEncode(checkFile));
|
||||
collection.Add(verb);
|
||||
}
|
||||
Verb[] sorted = (from l in collection orderby l.Size select l).ToArray();
|
||||
int stop = sorted.Length < 100 ? sorted.Length : 100;
|
||||
for (int i = 0; i < stop; i++) {
|
||||
results.Add(sorted[i]);
|
||||
}
|
||||
for (int i = sorted.Length - 1; i > stop - 1; i--) {
|
||||
results.Add(sorted[i]);
|
||||
}
|
||||
if (collection.Count != results.Count) {
|
||||
throw new Exception();
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static void PreformDeletes(ILogger<Worker> logger, string? directory, ReadOnlyCollection<Record> records) {
|
||||
string size;
|
||||
Record? record;
|
||||
@ -435,8 +479,9 @@ internal static partial class Helper20250519 {
|
||||
{ new StringContent(verb.Directory), "path", iValue }
|
||||
};
|
||||
httpRequestMessage.Content = multipartFormDataContent;
|
||||
} else
|
||||
} else {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
httpResponseMessage = httpClient.SendAsync(httpRequestMessage);
|
||||
httpResponseMessage.Wait(-1);
|
||||
if (!httpResponseMessage.Result.IsSuccessStatusCode) {
|
||||
@ -470,66 +515,20 @@ internal static partial class Helper20250519 {
|
||||
#endif
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<Verb> GetVerbCollection(string? directory, ReadOnlyCollection<Record> records) {
|
||||
List<Verb> results = [];
|
||||
Verb verb;
|
||||
string checkFile;
|
||||
string checkFileName;
|
||||
string? checkDirectory;
|
||||
List<Verb> collection = [];
|
||||
foreach (Record record in records) {
|
||||
if (string.IsNullOrEmpty(directory)) {
|
||||
continue;
|
||||
}
|
||||
checkFile = Path.Combine(directory, record.RelativePath);
|
||||
checkFileName = Path.GetFileName(checkFile);
|
||||
checkDirectory = Path.GetDirectoryName(checkFile);
|
||||
if (string.IsNullOrEmpty(checkDirectory)) {
|
||||
continue;
|
||||
}
|
||||
if (!Directory.Exists(checkDirectory)) {
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
}
|
||||
if (File.Exists(checkFile) && new FileInfo(checkFile).Length == 0) {
|
||||
File.Delete(checkFile);
|
||||
}
|
||||
verb = new(Directory: checkDirectory,
|
||||
Display: $"{checkFileName}{Environment.NewLine}{checkDirectory}",
|
||||
File: checkFile,
|
||||
Multipart: $"RelativePath:{record.RelativePath}|Size:{record.Size}|Ticks:{record.Ticks};",
|
||||
RelativePath: record.RelativePath,
|
||||
Size: record.Size,
|
||||
Ticks: record.Ticks,
|
||||
UrlEncodedFile: HttpUtility.UrlEncode(checkFile));
|
||||
collection.Add(verb);
|
||||
private static void LiveSync(ILogger<Worker> logger, string page, RelativePath relativePath, HttpClient httpClient, string? directory, ReadOnlyCollection<Record> records, HttpMethod? httpMethod, bool delete) {
|
||||
long sum;
|
||||
try { sum = records.Sum(l => l.Size); } catch (Exception) { sum = 0; }
|
||||
string size = GetSizeWithSuffix(sum);
|
||||
if (delete) {
|
||||
logger.LogInformation("Starting to delete {count} file(s) [{sum}]", records.Count, size);
|
||||
PreformDeletes(logger, relativePath.RightDirectory, records);
|
||||
logger.LogInformation("Deleted {count} file(s) [{sum}]", records.Count, size);
|
||||
}
|
||||
Verb[] sorted = (from l in collection orderby l.Size select l).ToArray();
|
||||
int stop = sorted.Length < 100 ? sorted.Length : 100;
|
||||
for (int i = 0; i < stop; i++) {
|
||||
results.Add(sorted[i]);
|
||||
if (httpMethod is not null) {
|
||||
logger.LogInformation("Starting to {httpMethod} {count} file(s) [{sum}]", httpMethod.ToString().ToLower(), records.Count, size);
|
||||
Preform(logger, page, directory, records, httpClient, httpMethod);
|
||||
logger.LogInformation("{httpMethod}'ed {count} file(s) [{sum}]", httpMethod.ToString(), records.Count, size);
|
||||
}
|
||||
for (int i = sorted.Length - 1; i > stop - 1; i--) {
|
||||
results.Add(sorted[i]);
|
||||
}
|
||||
if (collection.Count != results.Count) {
|
||||
throw new Exception();
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static string GetDurationWithSuffix(long ticks) {
|
||||
string result;
|
||||
TimeSpan timeSpan = new(DateTime.Now.Ticks - ticks);
|
||||
if (timeSpan.TotalMilliseconds < 1000) {
|
||||
result = $"{timeSpan.Milliseconds} ms";
|
||||
} else if (timeSpan.TotalMilliseconds < 60000) {
|
||||
result = $"{Math.Floor(timeSpan.TotalSeconds)} s";
|
||||
} else if (timeSpan.TotalMilliseconds < 3600000) {
|
||||
result = $"{Math.Floor(timeSpan.TotalMinutes)} m";
|
||||
} else {
|
||||
result = $"{Math.Floor(timeSpan.TotalHours)} h";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI6;
|
||||
|
||||
internal static partial class Helper20250521 {
|
||||
@ -19,24 +18,6 @@ internal static partial class Helper20250521 {
|
||||
|
||||
private record Record(string Directory, string FileNameWithoutExtension);
|
||||
|
||||
private record LineCheck(string[] Segments, DateTime TransactionDate, DateTime EffectiveDate) {
|
||||
|
||||
internal static LineCheck Get(int dateLineSegmentCount, string datePattern, string line) {
|
||||
LineCheck result;
|
||||
string[] segments = line.Split(' ');
|
||||
if (segments.Length >= dateLineSegmentCount
|
||||
&& segments[0].Length == datePattern.Length
|
||||
&& segments[1].Length == datePattern.Length
|
||||
&& DateTime.TryParseExact(segments[0], datePattern, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime transactionDate)
|
||||
&& DateTime.TryParseExact(segments[1], datePattern, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime effectiveDate)) {
|
||||
result = new(Segments: segments, TransactionDate: transactionDate, EffectiveDate: effectiveDate);
|
||||
} else {
|
||||
result = new(Segments: segments, TransactionDate: DateTime.MinValue, EffectiveDate: DateTime.MinValue);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private record RecordB(int I,
|
||||
DateTime TransactionDate,
|
||||
DateTime EffectiveDate,
|
||||
@ -82,11 +63,13 @@ internal static partial class Helper20250521 {
|
||||
string[] files = Directory.GetFiles(sourceDirectory, searchPatternB, SearchOption.AllDirectories);
|
||||
foreach (string file in files) {
|
||||
fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
|
||||
if (!keyValuePairs.TryGetValue(fileNameWithoutExtension, out string? match))
|
||||
if (!keyValuePairs.TryGetValue(fileNameWithoutExtension, out string? match)) {
|
||||
continue;
|
||||
}
|
||||
checkFile = Path.Combine(match, Path.GetFileName(file));
|
||||
if (File.Exists(checkFile))
|
||||
if (File.Exists(checkFile)) {
|
||||
continue;
|
||||
}
|
||||
File.Move(file, checkFile);
|
||||
}
|
||||
}
|
||||
@ -179,9 +162,28 @@ internal static partial class Helper20250521 {
|
||||
private static void WriteRecords(string sourceDirectory, ReadOnlyCollection<RecordB> records) {
|
||||
string json = JsonSerializer.Serialize(records.ToArray(), Helper20250521RecordB.Default.RecordBArray);
|
||||
string sourceDirectoryVsCode = Path.Combine(sourceDirectory, ".vscode");
|
||||
if (!Directory.Exists(sourceDirectoryVsCode))
|
||||
if (!Directory.Exists(sourceDirectoryVsCode)) {
|
||||
_ = Directory.CreateDirectory(sourceDirectoryVsCode);
|
||||
}
|
||||
File.WriteAllText(Path.Combine(sourceDirectoryVsCode, $"{DateTime.Now.Ticks}.json"), json);
|
||||
}
|
||||
|
||||
private record LineCheck(string[] Segments, DateTime TransactionDate, DateTime EffectiveDate) {
|
||||
|
||||
internal static LineCheck Get(int dateLineSegmentCount, string datePattern, string line) {
|
||||
LineCheck result;
|
||||
string[] segments = line.Split(' ');
|
||||
if (segments.Length >= dateLineSegmentCount
|
||||
&& segments[0].Length == datePattern.Length
|
||||
&& segments[1].Length == datePattern.Length
|
||||
&& DateTime.TryParseExact(segments[0], datePattern, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime transactionDate)
|
||||
&& DateTime.TryParseExact(segments[1], datePattern, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime effectiveDate)) {
|
||||
result = new(Segments: segments, TransactionDate: transactionDate, EffectiveDate: effectiveDate);
|
||||
} else {
|
||||
result = new(Segments: segments, TransactionDate: DateTime.MinValue, EffectiveDate: DateTime.MinValue);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
|
||||
using IFX.Shared.PasteSpecialXml.EAF.XML.API.Envelope;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
@ -6,10 +8,6 @@ using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
using IFX.Shared.PasteSpecialXml.EAF.XML.API.Envelope;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI6;
|
||||
|
||||
internal static partial class Helper20250601 {
|
||||
@ -33,6 +31,24 @@ internal static partial class Helper20250601 {
|
||||
string StopTime,
|
||||
string Text);
|
||||
|
||||
private static T? ParseXML<T>(string value, bool throwExceptions) where T : class {
|
||||
object? result = null;
|
||||
try {
|
||||
Stream stream = ToStream(value.Trim());
|
||||
XmlReader xmlReader = XmlReader.Create(stream, new XmlReaderSettings() { ConformanceLevel = ConformanceLevel.Document });
|
||||
#pragma warning disable IL2026, IL2090
|
||||
XmlSerializer xmlSerializer = new(typeof(T), typeof(T).GetNestedTypes());
|
||||
result = xmlSerializer.Deserialize(xmlReader);
|
||||
#pragma warning restore IL2026, IL2090
|
||||
stream.Dispose();
|
||||
} catch (Exception) {
|
||||
if (throwExceptions) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return result as T;
|
||||
}
|
||||
|
||||
internal static void EquipmentAutomationFrameworkStatus(ILogger<Worker> logger, List<string> args) {
|
||||
Status status;
|
||||
Record? record;
|
||||
@ -141,41 +157,6 @@ internal static partial class Helper20250601 {
|
||||
return results;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetUrls(bool development, bool staging, bool production) {
|
||||
List<string> results = [];
|
||||
if (development) {
|
||||
results.Add("eaf-dev.mes.infineon.com:9003");
|
||||
}
|
||||
if (staging) {
|
||||
results.Add("eaf-staging.mes.infineon.com:9003");
|
||||
}
|
||||
if (production) {
|
||||
results.Add("eaf-prod.mes.infineon.com:9003");
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static List<UnicodeCategory> GetUnicodeCategory() {
|
||||
List<UnicodeCategory> unicodeCategories = [
|
||||
// UnicodeCategory.Control, // 33 - <20>
|
||||
UnicodeCategory.UppercaseLetter, // 25 - ABCDEFGHIJKLMNOPQRSTUVWXY
|
||||
UnicodeCategory.LowercaseLetter, // 25 - abcdefghiklmnopqrstuvwxyz
|
||||
UnicodeCategory.DecimalDigitNumber, // 10 - 0123456789
|
||||
UnicodeCategory.OtherPunctuation, // 10 - !"#%&,./:@
|
||||
UnicodeCategory.ClosePunctuation, // 2 - )]
|
||||
UnicodeCategory.MathSymbol, // 2 - |؈
|
||||
UnicodeCategory.OpenPunctuation, // 2 - ([
|
||||
// UnicodeCategory.OtherSymbol, // 1 - <20>
|
||||
UnicodeCategory.DashPunctuation, // 1 - -
|
||||
UnicodeCategory.ConnectorPunctuation, // 1 - _
|
||||
UnicodeCategory.ModifierSymbol, // 1 - `
|
||||
UnicodeCategory.NonSpacingMark, // 1 - ̵
|
||||
UnicodeCategory.SpaceSeparator, // 1 -
|
||||
UnicodeCategory.CurrencySymbol, // 1 - $
|
||||
];
|
||||
return unicodeCategories;
|
||||
}
|
||||
|
||||
private static void EquipmentAutomationFrameworkCellInstanceParseCheck() {
|
||||
Envelope? envelope;
|
||||
string xmlStart621 = "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\"><s:Header><a:Action s:mustUnderstand=\"1\">http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequenceResponse</a:Action><a:RelatesTo>urn:uuid:6eb7a538-0b2b-4d04-8f2a-ab50e1e5338a</a:RelatesTo></s:Header><s:Body><CreateSequenceResponse xmlns=\"http://schemas.xmlsoap.org/ws/2005/02/rm\"><Identifier>urn:uuid:31c290af-2312-4b00-a57c-d5e1ab51e02a</Identifier><Accept><AcksTo><a:Address>http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:Address></AcksTo></Accept></CreateSequenceResponse></s:Body></s:Envelope>";
|
||||
@ -196,33 +177,6 @@ internal static partial class Helper20250601 {
|
||||
}
|
||||
}
|
||||
|
||||
private static T? ParseXML<T>(string value, bool throwExceptions) where T : class {
|
||||
object? result = null;
|
||||
try {
|
||||
Stream stream = ToStream(value.Trim());
|
||||
XmlReader xmlReader = XmlReader.Create(stream, new XmlReaderSettings() { ConformanceLevel = ConformanceLevel.Document });
|
||||
#pragma warning disable IL2026, IL2090
|
||||
XmlSerializer xmlSerializer = new(typeof(T), typeof(T).GetNestedTypes());
|
||||
result = xmlSerializer.Deserialize(xmlReader);
|
||||
#pragma warning restore IL2026, IL2090
|
||||
stream.Dispose();
|
||||
} catch (Exception) {
|
||||
if (throwExceptions) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return result as T;
|
||||
}
|
||||
|
||||
private static Stream ToStream(string value) {
|
||||
MemoryStream memoryStream = new();
|
||||
StreamWriter streamWriter = new(memoryStream);
|
||||
streamWriter.Write(value);
|
||||
streamWriter.Flush();
|
||||
memoryStream.Position = 0;
|
||||
return memoryStream;
|
||||
}
|
||||
|
||||
private static Dictionary<char, char> GetUnicodeReplaces() {
|
||||
Dictionary<char, char> results = new() {
|
||||
{ '\u0000', ' ' },
|
||||
@ -295,6 +249,41 @@ internal static partial class Helper20250601 {
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<UnicodeCategory> GetUnicodeCategory() {
|
||||
List<UnicodeCategory> unicodeCategories = [
|
||||
// UnicodeCategory.Control, // 33 - <20>
|
||||
UnicodeCategory.UppercaseLetter, // 25 - ABCDEFGHIJKLMNOPQRSTUVWXY
|
||||
UnicodeCategory.LowercaseLetter, // 25 - abcdefghiklmnopqrstuvwxyz
|
||||
UnicodeCategory.DecimalDigitNumber, // 10 - 0123456789
|
||||
UnicodeCategory.OtherPunctuation, // 10 - !"#%&,./:@
|
||||
UnicodeCategory.ClosePunctuation, // 2 - )]
|
||||
UnicodeCategory.MathSymbol, // 2 - |؈
|
||||
UnicodeCategory.OpenPunctuation, // 2 - ([
|
||||
// UnicodeCategory.OtherSymbol, // 1 - <20>
|
||||
UnicodeCategory.DashPunctuation, // 1 - -
|
||||
UnicodeCategory.ConnectorPunctuation, // 1 - _
|
||||
UnicodeCategory.ModifierSymbol, // 1 - `
|
||||
UnicodeCategory.NonSpacingMark, // 1 - ̵
|
||||
UnicodeCategory.SpaceSeparator, // 1 -
|
||||
UnicodeCategory.CurrencySymbol, // 1 - $
|
||||
];
|
||||
return unicodeCategories;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetUrls(bool development, bool staging, bool production) {
|
||||
List<string> results = [];
|
||||
if (development) {
|
||||
results.Add("eaf-dev.mes.infineon.com:9003");
|
||||
}
|
||||
if (staging) {
|
||||
results.Add("eaf-staging.mes.infineon.com:9003");
|
||||
}
|
||||
if (production) {
|
||||
results.Add("eaf-prod.mes.infineon.com:9003");
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static Status EquipmentAutomationFrameworkCellInstanceStatus(string cellInstanceName, Record record) {
|
||||
Status result;
|
||||
bool stop = false;
|
||||
@ -390,4 +379,13 @@ internal static partial class Helper20250601 {
|
||||
return results;
|
||||
}
|
||||
|
||||
private static Stream ToStream(string value) {
|
||||
MemoryStream memoryStream = new();
|
||||
StreamWriter streamWriter = new(memoryStream);
|
||||
streamWriter.Write(value);
|
||||
streamWriter.Flush();
|
||||
memoryStream.Position = 0;
|
||||
return memoryStream;
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
|
||||
using IFX.Shared.PasteSpecialXml.EAF.XML.API.Envelope;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
@ -6,10 +8,6 @@ using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
using IFX.Shared.PasteSpecialXml.EAF.XML.API.Envelope;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI6;
|
||||
|
||||
internal static partial class Helper20250602 {
|
||||
@ -31,6 +29,24 @@ internal static partial class Helper20250602 {
|
||||
string StopTime,
|
||||
string Text);
|
||||
|
||||
private static T? ParseXML<T>(string value, bool throwExceptions) where T : class {
|
||||
object? result = null;
|
||||
try {
|
||||
Stream stream = ToStream(value.Trim());
|
||||
XmlReader xmlReader = XmlReader.Create(stream, new XmlReaderSettings() { ConformanceLevel = ConformanceLevel.Document });
|
||||
#pragma warning disable IL2026, IL2090
|
||||
XmlSerializer xmlSerializer = new(typeof(T), typeof(T).GetNestedTypes());
|
||||
result = xmlSerializer.Deserialize(xmlReader);
|
||||
#pragma warning restore IL2026, IL2090
|
||||
stream.Dispose();
|
||||
} catch (Exception) {
|
||||
if (throwExceptions) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return result as T;
|
||||
}
|
||||
|
||||
internal static void EquipmentAutomationFrameworkCellInstanceStateImageVerbIf(ILogger<Worker> logger, List<string> args) {
|
||||
string path;
|
||||
Status status;
|
||||
@ -56,25 +72,6 @@ internal static partial class Helper20250602 {
|
||||
}
|
||||
}
|
||||
|
||||
private static Status GetEquipmentAutomationFrameworkCellInstanceStateImageVerbIf(ILogger<Worker> logger, string verbBy, string cellInstanceName, Record record) {
|
||||
Status result;
|
||||
Dictionary<string, DateTime> equipmentAutomationFrameworkTriggers = [];
|
||||
if (!equipmentAutomationFrameworkTriggers.ContainsKey(cellInstanceName)) {
|
||||
equipmentAutomationFrameworkTriggers.Add(cellInstanceName, DateTime.MinValue);
|
||||
}
|
||||
result = EquipmentAutomationFrameworkCellInstanceStatus(cellInstanceName, record);
|
||||
if (equipmentAutomationFrameworkTriggers[cellInstanceName] < DateTime.Now.AddSeconds(-60)) {
|
||||
if (result.State == "Offline") {
|
||||
EquipmentAutomationFrameworkCellInstanceStart(record.Host, record.Port, cellInstanceName, verbBy);
|
||||
logger.LogInformation("Start invoked for {cellName}", cellInstanceName);
|
||||
} else if (result.State == "Warning") {
|
||||
EquipmentAutomationFrameworkCellInstanceRestart(record.Host, record.Port, cellInstanceName, verbBy);
|
||||
logger.LogInformation("Restart invoked for {cellName}", cellInstanceName);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Dictionary<string, Record> GetEquipmentAutomationFrameworkCellInstanceStatus(bool development, bool staging, bool production) {
|
||||
Dictionary<string, Record> results = [];
|
||||
string key;
|
||||
@ -160,41 +157,6 @@ internal static partial class Helper20250602 {
|
||||
return results;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetUrls(bool development, bool staging, bool production) {
|
||||
List<string> results = [];
|
||||
if (development) {
|
||||
results.Add("eaf-dev.mes.infineon.com:9003");
|
||||
}
|
||||
if (staging) {
|
||||
results.Add("eaf-staging.mes.infineon.com:9003");
|
||||
}
|
||||
if (production) {
|
||||
results.Add("eaf-prod.mes.infineon.com:9003");
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static List<UnicodeCategory> GetUnicodeCategory() {
|
||||
List<UnicodeCategory> unicodeCategories = [
|
||||
// UnicodeCategory.Control, // 33 - <20>
|
||||
UnicodeCategory.UppercaseLetter, // 25 - ABCDEFGHIJKLMNOPQRSTUVWXY
|
||||
UnicodeCategory.LowercaseLetter, // 25 - abcdefghiklmnopqrstuvwxyz
|
||||
UnicodeCategory.DecimalDigitNumber, // 10 - 0123456789
|
||||
UnicodeCategory.OtherPunctuation, // 10 - !"#%&,./:@
|
||||
UnicodeCategory.ClosePunctuation, // 2 - )]
|
||||
UnicodeCategory.MathSymbol, // 2 - |؈
|
||||
UnicodeCategory.OpenPunctuation, // 2 - ([
|
||||
// UnicodeCategory.OtherSymbol, // 1 - <20>
|
||||
UnicodeCategory.DashPunctuation, // 1 - -
|
||||
UnicodeCategory.ConnectorPunctuation, // 1 - _
|
||||
UnicodeCategory.ModifierSymbol, // 1 - `
|
||||
UnicodeCategory.NonSpacingMark, // 1 - ̵
|
||||
UnicodeCategory.SpaceSeparator, // 1 -
|
||||
UnicodeCategory.CurrencySymbol, // 1 - $
|
||||
];
|
||||
return unicodeCategories;
|
||||
}
|
||||
|
||||
private static void EquipmentAutomationFrameworkCellInstanceParseCheck() {
|
||||
Envelope? envelope;
|
||||
string xmlStart621 = "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\"><s:Header><a:Action s:mustUnderstand=\"1\">http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequenceResponse</a:Action><a:RelatesTo>urn:uuid:6eb7a538-0b2b-4d04-8f2a-ab50e1e5338a</a:RelatesTo></s:Header><s:Body><CreateSequenceResponse xmlns=\"http://schemas.xmlsoap.org/ws/2005/02/rm\"><Identifier>urn:uuid:31c290af-2312-4b00-a57c-d5e1ab51e02a</Identifier><Accept><AcksTo><a:Address>http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:Address></AcksTo></Accept></CreateSequenceResponse></s:Body></s:Envelope>";
|
||||
@ -215,33 +177,6 @@ internal static partial class Helper20250602 {
|
||||
}
|
||||
}
|
||||
|
||||
private static T? ParseXML<T>(string value, bool throwExceptions) where T : class {
|
||||
object? result = null;
|
||||
try {
|
||||
Stream stream = ToStream(value.Trim());
|
||||
XmlReader xmlReader = XmlReader.Create(stream, new XmlReaderSettings() { ConformanceLevel = ConformanceLevel.Document });
|
||||
#pragma warning disable IL2026, IL2090
|
||||
XmlSerializer xmlSerializer = new(typeof(T), typeof(T).GetNestedTypes());
|
||||
result = xmlSerializer.Deserialize(xmlReader);
|
||||
#pragma warning restore IL2026, IL2090
|
||||
stream.Dispose();
|
||||
} catch (Exception) {
|
||||
if (throwExceptions) {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return result as T;
|
||||
}
|
||||
|
||||
private static Stream ToStream(string value) {
|
||||
MemoryStream memoryStream = new();
|
||||
StreamWriter streamWriter = new(memoryStream);
|
||||
streamWriter.Write(value);
|
||||
streamWriter.Flush();
|
||||
memoryStream.Position = 0;
|
||||
return memoryStream;
|
||||
}
|
||||
|
||||
private static Dictionary<char, char> GetUnicodeReplaces() {
|
||||
Dictionary<char, char> results = new() {
|
||||
{ '\u0000', ' ' },
|
||||
@ -314,6 +249,60 @@ internal static partial class Helper20250602 {
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<UnicodeCategory> GetUnicodeCategory() {
|
||||
List<UnicodeCategory> unicodeCategories = [
|
||||
// UnicodeCategory.Control, // 33 - <20>
|
||||
UnicodeCategory.UppercaseLetter, // 25 - ABCDEFGHIJKLMNOPQRSTUVWXY
|
||||
UnicodeCategory.LowercaseLetter, // 25 - abcdefghiklmnopqrstuvwxyz
|
||||
UnicodeCategory.DecimalDigitNumber, // 10 - 0123456789
|
||||
UnicodeCategory.OtherPunctuation, // 10 - !"#%&,./:@
|
||||
UnicodeCategory.ClosePunctuation, // 2 - )]
|
||||
UnicodeCategory.MathSymbol, // 2 - |؈
|
||||
UnicodeCategory.OpenPunctuation, // 2 - ([
|
||||
// UnicodeCategory.OtherSymbol, // 1 - <20>
|
||||
UnicodeCategory.DashPunctuation, // 1 - -
|
||||
UnicodeCategory.ConnectorPunctuation, // 1 - _
|
||||
UnicodeCategory.ModifierSymbol, // 1 - `
|
||||
UnicodeCategory.NonSpacingMark, // 1 - ̵
|
||||
UnicodeCategory.SpaceSeparator, // 1 -
|
||||
UnicodeCategory.CurrencySymbol, // 1 - $
|
||||
];
|
||||
return unicodeCategories;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetUrls(bool development, bool staging, bool production) {
|
||||
List<string> results = [];
|
||||
if (development) {
|
||||
results.Add("eaf-dev.mes.infineon.com:9003");
|
||||
}
|
||||
if (staging) {
|
||||
results.Add("eaf-staging.mes.infineon.com:9003");
|
||||
}
|
||||
if (production) {
|
||||
results.Add("eaf-prod.mes.infineon.com:9003");
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static Status GetEquipmentAutomationFrameworkCellInstanceStateImageVerbIf(ILogger<Worker> logger, string verbBy, string cellInstanceName, Record record) {
|
||||
Status result;
|
||||
Dictionary<string, DateTime> equipmentAutomationFrameworkTriggers = [];
|
||||
if (!equipmentAutomationFrameworkTriggers.ContainsKey(cellInstanceName)) {
|
||||
equipmentAutomationFrameworkTriggers.Add(cellInstanceName, DateTime.MinValue);
|
||||
}
|
||||
result = EquipmentAutomationFrameworkCellInstanceStatus(cellInstanceName, record);
|
||||
if (equipmentAutomationFrameworkTriggers[cellInstanceName] < DateTime.Now.AddSeconds(-60)) {
|
||||
if (result.State == "Offline") {
|
||||
EquipmentAutomationFrameworkCellInstanceStart(record.Host, record.Port, cellInstanceName, verbBy);
|
||||
logger.LogInformation("Start invoked for {cellName}", cellInstanceName);
|
||||
} else if (result.State == "Warning") {
|
||||
EquipmentAutomationFrameworkCellInstanceRestart(record.Host, record.Port, cellInstanceName, verbBy);
|
||||
logger.LogInformation("Restart invoked for {cellName}", cellInstanceName);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Status EquipmentAutomationFrameworkCellInstanceStatus(string cellInstanceName, Record record) {
|
||||
Status result;
|
||||
bool stop = false;
|
||||
@ -409,27 +398,6 @@ internal static partial class Helper20250602 {
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void EquipmentAutomationFrameworkCellInstanceRestart(string host, int port, string cellName = "R71-HSMS", string verbBy = @"EC\EcMesEaf") {
|
||||
EquipmentAutomationFrameworkCellInstanceParseCheck();
|
||||
// Restart
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence</a:Action><a:MessageID>urn:uuid:09fd9303-dcfe-4563-803b-678441b12949</a:MessageID><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body><CreateSequence xmlns="http://schemas.xmlsoap.org/ws/2005/02/rm"><AcksTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></AcksTo><Offer><Identifier>urn:uuid:4f2050da-4287-411b-992f-3126a5b3b35b</Identifier></Offer></CreateSequence></s:Body></s:Envelope>
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><r:Sequence s:mustUnderstand="1"><r:Identifier>urn:uuid:fbf34c20-f381-4e82-b81f-b4c1809f14fa</r:Identifier><r:MessageNumber>1</r:MessageNumber></r:Sequence><a:Action s:mustUnderstand="1">http://tempuri.org/ICellControllerManager/RestartAllCellInstances</a:Action><a:MessageID>urn:uuid:c9f80db4-a2c2-4e53-9bed-8ba3a60b653c</a:MessageID><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body><RestartAllCellInstances xmlns="http://tempuri.org/"><cellInstances xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><b:string>SP101_FileArchiver</b:string></cellInstances><updateInfo>Restarted by EC\ecphares</updateInfo></RestartAllCellInstances></s:Body></s:Envelope>
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><r:SequenceAcknowledgement><r:Identifier>urn:uuid:4f2050da-4287-411b-992f-3126a5b3b35b</r:Identifier><r:AcknowledgementRange Lower="1" Upper="1"/></r:SequenceAcknowledgement><r:Sequence s:mustUnderstand="1"><r:Identifier>urn:uuid:fbf34c20-f381-4e82-b81f-b4c1809f14fa</r:Identifier><r:MessageNumber>2</r:MessageNumber><r:LastMessage/></r:Sequence><a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/rm/LastMessage</a:Action><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body/></s:Envelope>
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><r:SequenceAcknowledgement><r:Identifier>urn:uuid:4f2050da-4287-411b-992f-3126a5b3b35b</r:Identifier><r:AcknowledgementRange Lower="1" Upper="2"/></r:SequenceAcknowledgement><a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/rm/TerminateSequence</a:Action><a:MessageID>urn:uuid:3b063df5-e6df-47a5-b530-aa380a4c6a38</a:MessageID><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body><r:TerminateSequence><r:Identifier>urn:uuid:fbf34c20-f381-4e82-b81f-b4c1809f14fa</r:Identifier></r:TerminateSequence></s:Body></s:Envelope>
|
||||
EquipmentAutomationFrameworkCellInstanceVerb(host, port, cellName, verbBy, restart: true, stop: false, start: false);
|
||||
}
|
||||
|
||||
private static void EquipmentAutomationFrameworkCellInstanceStart(string host, int port, string cellName = "R71-HSMS", string verbBy = @"EC\EcMesEaf") {
|
||||
EquipmentAutomationFrameworkCellInstanceParseCheck();
|
||||
// Start
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence</a:Action><a:MessageID>urn:uuid:a1188d61-df04-4955-b1e4-b90faff95d4d</a:MessageID><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body><CreateSequence xmlns="http://schemas.xmlsoap.org/ws/2005/02/rm"><AcksTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></AcksTo><Offer><Identifier>urn:uuid:35310d6d-3d17-419c-9b4f-cf20b705e5c9</Identifier></Offer></CreateSequence></s:Body></s:Envelope>
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><r:Sequence s:mustUnderstand="1"><r:Identifier>urn:uuid:739e01d3-5573-48a4-8bbb-53e2dfc344af</r:Identifier><r:MessageNumber>1</r:MessageNumber></r:Sequence><a:Action s:mustUnderstand="1">http://tempuri.org/ICellControllerManager/StartAllCellInstances</a:Action><a:MessageID>urn:uuid:8758eec2-b4dc-4338-ba3d-235aa15e634c</a:MessageID><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body><StartAllCellInstances xmlns="http://tempuri.org/"><cellInstances xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><b:string>SP101_FileArchiver</b:string></cellInstances><updateInfo>Started by EC\ecphares</updateInfo></StartAllCellInstances></s:Body></s:Envelope>
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><r:Sequence s:mustUnderstand="1"><r:Identifier>urn:uuid:739e01d3-5573-48a4-8bbb-53e2dfc344af</r:Identifier><r:MessageNumber>1</r:MessageNumber></r:Sequence><a:Action s:mustUnderstand="1">http://tempuri.org/ICellControllerManager/StartAllCellInstances</a:Action><a:MessageID>urn:uuid:8758eec2-b4dc-4338-ba3d-235aa15e634c</a:MessageID><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body><StartAllCellInstances xmlns="http://tempuri.org/"><cellInstances xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><b:string>SP101_FileArchiver</b:string></cellInstances><updateInfo>Started by EC\ecphares</updateInfo></StartAllCellInstances></s:Body></s:Envelope>
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><r:SequenceAcknowledgement><r:Identifier>urn:uuid:35310d6d-3d17-419c-9b4f-cf20b705e5c9</r:Identifier><r:AcknowledgementRange Lower="1" Upper="1"/></r:SequenceAcknowledgement><r:Sequence s:mustUnderstand="1"><r:Identifier>urn:uuid:739e01d3-5573-48a4-8bbb-53e2dfc344af</r:Identifier><r:MessageNumber>2</r:MessageNumber><r:LastMessage/></r:Sequence><a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/rm/LastMessage</a:Action><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body/></s:Envelope>
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><r:SequenceAcknowledgement><r:Identifier>urn:uuid:35310d6d-3d17-419c-9b4f-cf20b705e5c9</r:Identifier><r:AcknowledgementRange Lower="1" Upper="2"/></r:SequenceAcknowledgement><a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/rm/TerminateSequence</a:Action><a:MessageID>urn:uuid:b2bb5329-c846-4cd1-98a8-343136923702</a:MessageID><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body><r:TerminateSequence><r:Identifier>urn:uuid:739e01d3-5573-48a4-8bbb-53e2dfc344af</r:Identifier></r:TerminateSequence></s:Body></s:Envelope>
|
||||
EquipmentAutomationFrameworkCellInstanceVerb(host, port, cellName, verbBy, restart: false, stop: false, start: true);
|
||||
}
|
||||
|
||||
private static void EquipmentAutomationFrameworkCellInstanceVerb(string host, int port, string cellName, string verbBy, bool restart, bool stop, bool start) {
|
||||
#pragma warning disable SYSLIB0014
|
||||
WebClient webClient = new();
|
||||
@ -453,8 +421,9 @@ internal static partial class Helper20250602 {
|
||||
} else if (start) {
|
||||
updateInfoVerb = "Started";
|
||||
verb = "StartAllCellInstances";
|
||||
} else
|
||||
} else {
|
||||
throw new Exception();
|
||||
}
|
||||
string headerMessageID621 = Guid.NewGuid().ToString();
|
||||
string bodyIdentifier621 = Guid.NewGuid().ToString();
|
||||
_ = stringBuilder.Append("<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\">").
|
||||
@ -542,4 +511,34 @@ internal static partial class Helper20250602 {
|
||||
_ = ParseXML<Envelope>(xml, throwExceptions: true);
|
||||
}
|
||||
|
||||
private static Stream ToStream(string value) {
|
||||
MemoryStream memoryStream = new();
|
||||
StreamWriter streamWriter = new(memoryStream);
|
||||
streamWriter.Write(value);
|
||||
streamWriter.Flush();
|
||||
memoryStream.Position = 0;
|
||||
return memoryStream;
|
||||
}
|
||||
|
||||
private static void EquipmentAutomationFrameworkCellInstanceStart(string host, int port, string cellName = "R71-HSMS", string verbBy = @"EC\EcMesEaf") {
|
||||
EquipmentAutomationFrameworkCellInstanceParseCheck();
|
||||
// Start
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence</a:Action><a:MessageID>urn:uuid:a1188d61-df04-4955-b1e4-b90faff95d4d</a:MessageID><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body><CreateSequence xmlns="http://schemas.xmlsoap.org/ws/2005/02/rm"><AcksTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></AcksTo><Offer><Identifier>urn:uuid:35310d6d-3d17-419c-9b4f-cf20b705e5c9</Identifier></Offer></CreateSequence></s:Body></s:Envelope>
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><r:Sequence s:mustUnderstand="1"><r:Identifier>urn:uuid:739e01d3-5573-48a4-8bbb-53e2dfc344af</r:Identifier><r:MessageNumber>1</r:MessageNumber></r:Sequence><a:Action s:mustUnderstand="1">http://tempuri.org/ICellControllerManager/StartAllCellInstances</a:Action><a:MessageID>urn:uuid:8758eec2-b4dc-4338-ba3d-235aa15e634c</a:MessageID><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body><StartAllCellInstances xmlns="http://tempuri.org/"><cellInstances xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><b:string>SP101_FileArchiver</b:string></cellInstances><updateInfo>Started by EC\ecphares</updateInfo></StartAllCellInstances></s:Body></s:Envelope>
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><r:Sequence s:mustUnderstand="1"><r:Identifier>urn:uuid:739e01d3-5573-48a4-8bbb-53e2dfc344af</r:Identifier><r:MessageNumber>1</r:MessageNumber></r:Sequence><a:Action s:mustUnderstand="1">http://tempuri.org/ICellControllerManager/StartAllCellInstances</a:Action><a:MessageID>urn:uuid:8758eec2-b4dc-4338-ba3d-235aa15e634c</a:MessageID><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body><StartAllCellInstances xmlns="http://tempuri.org/"><cellInstances xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><b:string>SP101_FileArchiver</b:string></cellInstances><updateInfo>Started by EC\ecphares</updateInfo></StartAllCellInstances></s:Body></s:Envelope>
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><r:SequenceAcknowledgement><r:Identifier>urn:uuid:35310d6d-3d17-419c-9b4f-cf20b705e5c9</r:Identifier><r:AcknowledgementRange Lower="1" Upper="1"/></r:SequenceAcknowledgement><r:Sequence s:mustUnderstand="1"><r:Identifier>urn:uuid:739e01d3-5573-48a4-8bbb-53e2dfc344af</r:Identifier><r:MessageNumber>2</r:MessageNumber><r:LastMessage/></r:Sequence><a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/rm/LastMessage</a:Action><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body/></s:Envelope>
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><r:SequenceAcknowledgement><r:Identifier>urn:uuid:35310d6d-3d17-419c-9b4f-cf20b705e5c9</r:Identifier><r:AcknowledgementRange Lower="1" Upper="2"/></r:SequenceAcknowledgement><a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/rm/TerminateSequence</a:Action><a:MessageID>urn:uuid:b2bb5329-c846-4cd1-98a8-343136923702</a:MessageID><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body><r:TerminateSequence><r:Identifier>urn:uuid:739e01d3-5573-48a4-8bbb-53e2dfc344af</r:Identifier></r:TerminateSequence></s:Body></s:Envelope>
|
||||
EquipmentAutomationFrameworkCellInstanceVerb(host, port, cellName, verbBy, restart: false, stop: false, start: true);
|
||||
}
|
||||
|
||||
private static void EquipmentAutomationFrameworkCellInstanceRestart(string host, int port, string cellName = "R71-HSMS", string verbBy = @"EC\EcMesEaf") {
|
||||
EquipmentAutomationFrameworkCellInstanceParseCheck();
|
||||
// Restart
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence</a:Action><a:MessageID>urn:uuid:09fd9303-dcfe-4563-803b-678441b12949</a:MessageID><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body><CreateSequence xmlns="http://schemas.xmlsoap.org/ws/2005/02/rm"><AcksTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></AcksTo><Offer><Identifier>urn:uuid:4f2050da-4287-411b-992f-3126a5b3b35b</Identifier></Offer></CreateSequence></s:Body></s:Envelope>
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><r:Sequence s:mustUnderstand="1"><r:Identifier>urn:uuid:fbf34c20-f381-4e82-b81f-b4c1809f14fa</r:Identifier><r:MessageNumber>1</r:MessageNumber></r:Sequence><a:Action s:mustUnderstand="1">http://tempuri.org/ICellControllerManager/RestartAllCellInstances</a:Action><a:MessageID>urn:uuid:c9f80db4-a2c2-4e53-9bed-8ba3a60b653c</a:MessageID><a:ReplyTo><a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address></a:ReplyTo><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body><RestartAllCellInstances xmlns="http://tempuri.org/"><cellInstances xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><b:string>SP101_FileArchiver</b:string></cellInstances><updateInfo>Restarted by EC\ecphares</updateInfo></RestartAllCellInstances></s:Body></s:Envelope>
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><r:SequenceAcknowledgement><r:Identifier>urn:uuid:4f2050da-4287-411b-992f-3126a5b3b35b</r:Identifier><r:AcknowledgementRange Lower="1" Upper="1"/></r:SequenceAcknowledgement><r:Sequence s:mustUnderstand="1"><r:Identifier>urn:uuid:fbf34c20-f381-4e82-b81f-b4c1809f14fa</r:Identifier><r:MessageNumber>2</r:MessageNumber><r:LastMessage/></r:Sequence><a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/rm/LastMessage</a:Action><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body/></s:Envelope>
|
||||
// <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:r="http://schemas.xmlsoap.org/ws/2005/02/rm" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header><r:SequenceAcknowledgement><r:Identifier>urn:uuid:4f2050da-4287-411b-992f-3126a5b3b35b</r:Identifier><r:AcknowledgementRange Lower="1" Upper="2"/></r:SequenceAcknowledgement><a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/rm/TerminateSequence</a:Action><a:MessageID>urn:uuid:3b063df5-e6df-47a5-b530-aa380a4c6a38</a:MessageID><a:To s:mustUnderstand="1">http://eaf-prod.mes.infineon.com:9003/CellControllerManager</a:To></s:Header><s:Body><r:TerminateSequence><r:Identifier>urn:uuid:fbf34c20-f381-4e82-b81f-b4c1809f14fa</r:Identifier></r:TerminateSequence></s:Body></s:Envelope>
|
||||
EquipmentAutomationFrameworkCellInstanceVerb(host, port, cellName, verbBy, restart: true, stop: false, start: false);
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI6;
|
||||
|
||||
@ -77,10 +76,12 @@ internal static partial class Helper20250618 {
|
||||
file = keyValuePair.Value[i];
|
||||
checkFile = $"{destinationDirectory}{file[sourceDirectoryLength..]}";
|
||||
checkDirectory = Path.GetDirectoryName(checkFile) ?? throw new Exception();
|
||||
if (!Directory.Exists(checkDirectory))
|
||||
if (!Directory.Exists(checkDirectory)) {
|
||||
_ = Directory.CreateDirectory(checkDirectory);
|
||||
if (File.Exists(checkFile))
|
||||
}
|
||||
if (File.Exists(checkFile)) {
|
||||
continue;
|
||||
}
|
||||
File.Move(file, checkFile);
|
||||
logger.LogInformation("<{file}> moved", file);
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
using DiscUtils.Iso9660;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI6;
|
||||
|
||||
@ -35,22 +33,6 @@ internal static partial class Helper20250628 {
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static string GetSizeWithSuffix(long value) {
|
||||
string result;
|
||||
int i = 0;
|
||||
string[] SizeSuffixes = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||
if (value < 0) {
|
||||
result = "-" + GetSizeWithSuffix(-value);
|
||||
} else {
|
||||
while (Math.Round(value / 1024f) >= 1) {
|
||||
value /= 1024;
|
||||
i++;
|
||||
}
|
||||
result = string.Format("{0:n1} {1}", value, SizeSuffixes[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void LogIsoInformation(ILogger<Worker> logger, ReadOnlyCollection<Record> records, string letter) {
|
||||
string size;
|
||||
string[] files;
|
||||
@ -85,4 +67,20 @@ internal static partial class Helper20250628 {
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetSizeWithSuffix(long value) {
|
||||
string result;
|
||||
int i = 0;
|
||||
string[] SizeSuffixes = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
||||
if (value < 0) {
|
||||
result = "-" + GetSizeWithSuffix(-value);
|
||||
} else {
|
||||
while (Math.Round(value / 1024f) >= 1) {
|
||||
value /= 1024;
|
||||
i++;
|
||||
}
|
||||
result = string.Format("{0:n1} {1}", value, SizeSuffixes[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -144,51 +144,6 @@ internal static partial class Helper20250701 {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int? GetProcessDataStandardFormatColumnTitlesLine(string[] lines) {
|
||||
int? result = null;
|
||||
for (int i = 0; i < lines.Length; i++) {
|
||||
if (lines[i].StartsWith("END_OFFSET") && i + 3 < lines.Length) {
|
||||
result = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<string, ReadOnlyCollection<string>> GetKeyValuePairs(int columnTitlesLine, string[] lines) {
|
||||
Dictionary<string, ReadOnlyCollection<string>> results = [];
|
||||
string[] segments;
|
||||
List<List<string>> collections = [];
|
||||
string[] columns = lines[columnTitlesLine].Split('\t');
|
||||
foreach (string _ in columns) {
|
||||
collections.Add([]);
|
||||
}
|
||||
for (int i = columnTitlesLine + 1; i < lines.Length; i++) {
|
||||
if (lines[i].StartsWith("NUM_DATA_ROWS")) {
|
||||
break;
|
||||
}
|
||||
segments = lines[i].Split('\t');
|
||||
if (segments.Length > columns.Length) {
|
||||
continue;
|
||||
}
|
||||
for (int c = 0; c < segments.Length; c++) {
|
||||
collections[c].Add(segments[c]);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < collections.Count; i++) {
|
||||
if (collections[i].Count > 1) {
|
||||
if (string.IsNullOrEmpty(collections[i][0])) {
|
||||
collections[i][0] = collections[i][1];
|
||||
}
|
||||
if (string.IsNullOrEmpty(collections[i][^1])) {
|
||||
collections[i][^1] = collections[i][^2];
|
||||
}
|
||||
}
|
||||
results.Add(columns[i].Trim('"'), collections[i].AsReadOnly());
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static string? GetMarkdown(string timeColumn, ReadOnlyDictionary<string, string> columnMapping, string name, string[] lines, int columnTitlesLine) {
|
||||
string? result;
|
||||
List<string> charts = [];
|
||||
@ -244,6 +199,40 @@ internal static partial class Helper20250701 {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<string, ReadOnlyCollection<string>> GetKeyValuePairs(int columnTitlesLine, string[] lines) {
|
||||
Dictionary<string, ReadOnlyCollection<string>> results = [];
|
||||
string[] segments;
|
||||
List<List<string>> collections = [];
|
||||
string[] columns = lines[columnTitlesLine].Split('\t');
|
||||
foreach (string _ in columns) {
|
||||
collections.Add([]);
|
||||
}
|
||||
for (int i = columnTitlesLine + 1; i < lines.Length; i++) {
|
||||
if (lines[i].StartsWith("NUM_DATA_ROWS")) {
|
||||
break;
|
||||
}
|
||||
segments = lines[i].Split('\t');
|
||||
if (segments.Length > columns.Length) {
|
||||
continue;
|
||||
}
|
||||
for (int c = 0; c < segments.Length; c++) {
|
||||
collections[c].Add(segments[c]);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < collections.Count; i++) {
|
||||
if (collections[i].Count > 1) {
|
||||
if (string.IsNullOrEmpty(collections[i][0])) {
|
||||
collections[i][0] = collections[i][1];
|
||||
}
|
||||
if (string.IsNullOrEmpty(collections[i][^1])) {
|
||||
collections[i][^1] = collections[i][^2];
|
||||
}
|
||||
}
|
||||
results.Add(columns[i].Trim('"'), collections[i].AsReadOnly());
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static string? GetJavaScriptObjectNotation(ILogger<Worker> logger, string file) {
|
||||
string? result = null;
|
||||
string[] lines = File.ReadAllLines(file);
|
||||
@ -323,8 +312,9 @@ internal static partial class Helper20250701 {
|
||||
List<string> results = [];
|
||||
for (int j = i; j < lines.Length; j++) {
|
||||
results.Add(lines[j]);
|
||||
if (lines[j].StartsWith("END_HEADER"))
|
||||
if (lines[j].StartsWith("END_HEADER")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
@ -387,6 +377,17 @@ internal static partial class Helper20250701 {
|
||||
return results.AsReadOnly();
|
||||
}
|
||||
|
||||
private static int? GetProcessDataStandardFormatColumnTitlesLine(string[] lines) {
|
||||
int? result = null;
|
||||
for (int i = 0; i < lines.Length; i++) {
|
||||
if (lines[i].StartsWith("END_OFFSET") && i + 3 < lines.Length) {
|
||||
result = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string? GetPipeTable(string json) {
|
||||
string? result = null;
|
||||
string? value;
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Drawing;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Drawing;
|
||||
|
||||
namespace File_Folder_Helper.ADO2025.PI6;
|
||||
|
||||
|
@ -86,8 +86,9 @@ internal static partial class Helper20250710 {
|
||||
string result;
|
||||
List<string> results = [];
|
||||
for (int j = i + 1; j < lines.Length; j++) {
|
||||
if (lines[j].StartsWith(segments[0]))
|
||||
if (lines[j].StartsWith(segments[0])) {
|
||||
break;
|
||||
}
|
||||
results.Add(lines[j].Trim());
|
||||
}
|
||||
result = string.Join('_', results);
|
||||
|
@ -17,6 +17,67 @@ internal static partial class Helper20250720 {
|
||||
private partial class Helper20250720SettingsSourceGenerationContext : JsonSerializerContext {
|
||||
}
|
||||
|
||||
private static void WriteFaceData(ILogger<Worker> logger, string outputDirectoryName, string? originalFile, long? fileNameFirstSegment, ReadOnlyCollection<ExifDirectory> exifDirectories, ReadOnlyCollection<string> digiKamFiles) {
|
||||
ReadOnlyDictionary<string, FaceFile> keyValuePairs = GetKeyValuePairs(logger, exifDirectories);
|
||||
if (keyValuePairs.Count > 0) {
|
||||
WriteFaceData(logger, outputDirectoryName, originalFile, fileNameFirstSegment, digiKamFiles, keyValuePairs);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteFaceData(ILogger<Worker> logger, string outputDirectoryName, string? originalFile, long? fileNameFirstSegment, ReadOnlyCollection<string> digiKamFiles, ReadOnlyDictionary<string, FaceFile> keyValuePairs) {
|
||||
#if xmp
|
||||
IXmpMeta xmp;
|
||||
using FileStream stream = File.OpenRead(digiKamFile);
|
||||
xmp = XmpMetaFactory.Parse(stream);
|
||||
foreach (var property in xmp.Properties) {
|
||||
logger.LogDebug("Path={property.Path} Namespace={property.Namespace} Value={property.Value}", property.Path, property.Namespace, property.Value);
|
||||
}
|
||||
xmp.Sort();
|
||||
SerializeOptions serializeOptions = new(SerializeOptions.EncodeUtf8);
|
||||
string check = XmpMetaFactory.SerializeToString(xmp, serializeOptions);
|
||||
File.WriteAllText(".xmp", check);
|
||||
#endif
|
||||
string[] requiredLines = [
|
||||
"xmlns:digiKam=\"http://www.digikam.org/ns/1.0/\"",
|
||||
"xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\"",
|
||||
"xmlns:exif=\"http://ns.adobe.com/exif/1.0/\"",
|
||||
"xmlns:tiff=\"http://ns.adobe.com/tiff/1.0/\"",
|
||||
"xmlns:dc=\"http://purl.org/dc/elements/1.1/\"",
|
||||
"xmlns:acdsee=\"http://ns.acdsee.com/iptc/1.0/\"",
|
||||
"xmlns:lr=\"http://ns.adobe.com/lightroom/1.0/\"",
|
||||
"xmlns:MP=\"http://ns.microsoft.com/photo/1.2/\"",
|
||||
"xmlns:stArea=\"http://ns.adobe.com/xmp/sType/Area#\"",
|
||||
"xmlns:photoshop=\"http://ns.adobe.com/photoshop/1.0/\"",
|
||||
"xmlns:MicrosoftPhoto=\"http://ns.microsoft.com/photo/1.0/\"",
|
||||
"xmlns:MPReg=\"http://ns.microsoft.com/photo/1.2/t/Region#\"",
|
||||
"xmlns:stDim=\"http://ns.adobe.com/xap/1.0/sType/Dimensions#\"",
|
||||
"xmlns:MPRI=\"http://ns.microsoft.com/photo/1.2/t/RegionInfo#\"",
|
||||
"xmlns:mediapro=\"http://ns.iview-multimedia.com/mediapro/1.0/\"",
|
||||
"xmlns:mwg-rs=\"http://www.metadataworkinggroup.com/schemas/regions/\"",
|
||||
"</rdf:RDF>"
|
||||
];
|
||||
foreach (string digiKamFile in digiKamFiles) {
|
||||
string[] lines = File.ReadAllLines(digiKamFile);
|
||||
List<string> trimmed = lines.Select(l => l.Trim()).ToList();
|
||||
int? digiKamLine = GetMatchingLine(requiredLines[0], trimmed.AsReadOnly());
|
||||
if (digiKamLine is null) {
|
||||
logger.LogError("{fileNameFirstSegment}) Didn't fine digiKam line!", fileNameFirstSegment);
|
||||
} else {
|
||||
foreach (string requiredLine in requiredLines) {
|
||||
if (!trimmed.Contains(requiredLine)) {
|
||||
trimmed.Insert(digiKamLine.Value + 1, requiredLine);
|
||||
}
|
||||
}
|
||||
int? rdfLine = GetMatchingLine(requiredLines[^1], trimmed.AsReadOnly());
|
||||
if (rdfLine is null) {
|
||||
logger.LogError("{fileNameFirstSegment}) Didn't fine description line!", fileNameFirstSegment);
|
||||
} else {
|
||||
WriteFaceData(outputDirectoryName, originalFile, keyValuePairs, digiKamFile, trimmed, rdfLine.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void WriteFaceData(ILogger<Worker> logger, List<string> args) {
|
||||
logger.LogInformation(args[0]);
|
||||
logger.LogInformation(args[1]);
|
||||
@ -84,24 +145,6 @@ internal static partial class Helper20250720 {
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteFaceData(ILogger<Worker> logger, string outputDirectoryName, string? originalFile, long? fileNameFirstSegment, ReadOnlyCollection<ExifDirectory> exifDirectories, ReadOnlyCollection<string> digiKamFiles) {
|
||||
ReadOnlyDictionary<string, FaceFile> keyValuePairs = GetKeyValuePairs(logger, exifDirectories);
|
||||
if (keyValuePairs.Count > 0) {
|
||||
WriteFaceData(logger, outputDirectoryName, originalFile, fileNameFirstSegment, digiKamFiles, keyValuePairs);
|
||||
}
|
||||
}
|
||||
|
||||
private static int? GetMatchingLine(string digiKamLine, ReadOnlyCollection<string> lines) {
|
||||
int? result = null;
|
||||
for (int i = 0; i < lines.Count; i++) {
|
||||
if (lines[i] == digiKamLine) {
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void WriteFaceData(string outputDirectoryName, string? originalFile, ReadOnlyDictionary<string, FaceFile> keyValuePairs, string digiKamFile, List<string> trimmed, int rdfLine) {
|
||||
if (keyValuePairs.Count == 0) {
|
||||
throw new Exception();
|
||||
@ -118,8 +161,9 @@ internal static partial class Helper20250720 {
|
||||
FaceFile faceFile;
|
||||
string descriptionLine = "</rdf:Description>";
|
||||
faceFile = keyValuePairs.ElementAt(0).Value;
|
||||
if (faceFile.Location is null || faceFile.OutputResolution is null)
|
||||
if (faceFile.Location is null || faceFile.OutputResolution is null) {
|
||||
throw new Exception();
|
||||
}
|
||||
List<string> regionLines = [
|
||||
"<MP:RegionInfo rdf:parseType=\"Resource\">",
|
||||
"<MPRI:Regions>",
|
||||
@ -142,8 +186,9 @@ internal static partial class Helper20250720 {
|
||||
foreach (KeyValuePair<string, FaceFile> keyValuePair in keyValuePairs) {
|
||||
personKey = keyValuePair.Key;
|
||||
faceFile = keyValuePair.Value;
|
||||
if (faceFile.Location is null || faceFile.OutputResolution is null)
|
||||
if (faceFile.Location is null || faceFile.OutputResolution is null) {
|
||||
throw new Exception();
|
||||
}
|
||||
width = faceFile.Location.Right - faceFile.Location.Left;
|
||||
height = faceFile.Location.Bottom - faceFile.Location.Top;
|
||||
if (!string.IsNullOrEmpty(originalFile) && File.Exists(originalFile)) {
|
||||
@ -156,8 +201,9 @@ internal static partial class Helper20250720 {
|
||||
}
|
||||
w = width / faceFile.OutputResolution.Width;
|
||||
h = height / faceFile.OutputResolution.Height;
|
||||
if (w == 0 || h == 0)
|
||||
if (w == 0 || h == 0) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
mpLeft = (double)faceFile.Location.Left / faceFile.OutputResolution.Width;
|
||||
mpTop = (double)faceFile.Location.Top / faceFile.OutputResolution.Height;
|
||||
mwgLeft = (faceFile.Location.Left + (width * .5)) / faceFile.OutputResolution.Width;
|
||||
@ -338,12 +384,14 @@ internal static partial class Helper20250720 {
|
||||
continue;
|
||||
}
|
||||
exifDirectory = IMetadata.GetExifDirectory(resultSettings, metadataSettings, faceFileInfo);
|
||||
if (exifDirectory is null)
|
||||
if (exifDirectory is null) {
|
||||
continue;
|
||||
}
|
||||
if (!keyValuePairs.TryGetValue(fileNameFirstSegment, out collection)) {
|
||||
keyValuePairs.Add(fileNameFirstSegment, []);
|
||||
if (!keyValuePairs.TryGetValue(fileNameFirstSegment, out collection))
|
||||
if (!keyValuePairs.TryGetValue(fileNameFirstSegment, out collection)) {
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
collection.Add(exifDirectory);
|
||||
}
|
||||
@ -365,58 +413,15 @@ internal static partial class Helper20250720 {
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteFaceData(ILogger<Worker> logger, string outputDirectoryName, string? originalFile, long? fileNameFirstSegment, ReadOnlyCollection<string> digiKamFiles, ReadOnlyDictionary<string, FaceFile> keyValuePairs) {
|
||||
#if xmp
|
||||
IXmpMeta xmp;
|
||||
using FileStream stream = File.OpenRead(digiKamFile);
|
||||
xmp = XmpMetaFactory.Parse(stream);
|
||||
foreach (var property in xmp.Properties) {
|
||||
logger.LogDebug("Path={property.Path} Namespace={property.Namespace} Value={property.Value}", property.Path, property.Namespace, property.Value);
|
||||
}
|
||||
xmp.Sort();
|
||||
SerializeOptions serializeOptions = new(SerializeOptions.EncodeUtf8);
|
||||
string check = XmpMetaFactory.SerializeToString(xmp, serializeOptions);
|
||||
File.WriteAllText(".xmp", check);
|
||||
#endif
|
||||
string[] requiredLines = [
|
||||
"xmlns:digiKam=\"http://www.digikam.org/ns/1.0/\"",
|
||||
"xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\"",
|
||||
"xmlns:exif=\"http://ns.adobe.com/exif/1.0/\"",
|
||||
"xmlns:tiff=\"http://ns.adobe.com/tiff/1.0/\"",
|
||||
"xmlns:dc=\"http://purl.org/dc/elements/1.1/\"",
|
||||
"xmlns:acdsee=\"http://ns.acdsee.com/iptc/1.0/\"",
|
||||
"xmlns:lr=\"http://ns.adobe.com/lightroom/1.0/\"",
|
||||
"xmlns:MP=\"http://ns.microsoft.com/photo/1.2/\"",
|
||||
"xmlns:stArea=\"http://ns.adobe.com/xmp/sType/Area#\"",
|
||||
"xmlns:photoshop=\"http://ns.adobe.com/photoshop/1.0/\"",
|
||||
"xmlns:MicrosoftPhoto=\"http://ns.microsoft.com/photo/1.0/\"",
|
||||
"xmlns:MPReg=\"http://ns.microsoft.com/photo/1.2/t/Region#\"",
|
||||
"xmlns:stDim=\"http://ns.adobe.com/xap/1.0/sType/Dimensions#\"",
|
||||
"xmlns:MPRI=\"http://ns.microsoft.com/photo/1.2/t/RegionInfo#\"",
|
||||
"xmlns:mediapro=\"http://ns.iview-multimedia.com/mediapro/1.0/\"",
|
||||
"xmlns:mwg-rs=\"http://www.metadataworkinggroup.com/schemas/regions/\"",
|
||||
"</rdf:RDF>"
|
||||
];
|
||||
foreach (string digiKamFile in digiKamFiles) {
|
||||
string[] lines = File.ReadAllLines(digiKamFile);
|
||||
List<string> trimmed = lines.Select(l => l.Trim()).ToList();
|
||||
int? digiKamLine = GetMatchingLine(requiredLines[0], trimmed.AsReadOnly());
|
||||
if (digiKamLine is null) {
|
||||
logger.LogError("{fileNameFirstSegment}) Didn't fine digiKam line!", fileNameFirstSegment);
|
||||
} else {
|
||||
foreach (string requiredLine in requiredLines) {
|
||||
if (!trimmed.Contains(requiredLine)) {
|
||||
trimmed.Insert(digiKamLine.Value + 1, requiredLine);
|
||||
}
|
||||
}
|
||||
int? rdfLine = GetMatchingLine(requiredLines[^1], trimmed.AsReadOnly());
|
||||
if (rdfLine is null) {
|
||||
logger.LogError("{fileNameFirstSegment}) Didn't fine description line!", fileNameFirstSegment);
|
||||
} else {
|
||||
WriteFaceData(outputDirectoryName, originalFile, keyValuePairs, digiKamFile, trimmed, rdfLine.Value);
|
||||
}
|
||||
private static int? GetMatchingLine(string digiKamLine, ReadOnlyCollection<string> lines) {
|
||||
int? result = null;
|
||||
for (int i = 0; i < lines.Count; i++) {
|
||||
if (lines[i] == digiKamLine) {
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void Extract(string file, double width, double height, int left, int top, string suffix) {
|
||||
|
@ -64,8 +64,9 @@ internal static partial class Helper20250726 {
|
||||
ReadOnlyDictionary<int, ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>>> keyValuePairs = IPath.GetKeyValuePairs(resultSettings, destinationDirectory, [destinationDirectoryName]);
|
||||
foreach (KeyValuePair<int, ReadOnlyDictionary<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>>> keyValuePair in keyValuePairs) {
|
||||
foreach (KeyValuePair<string, ReadOnlyDictionary<byte, ReadOnlyCollection<string>>> keyValue in keyValuePair.Value) {
|
||||
if (keyValue.Key != destinationDirectoryName)
|
||||
if (keyValue.Key != destinationDirectoryName) {
|
||||
throw new Exception("Never should happen!");
|
||||
}
|
||||
results.Add(keyValuePair.Key, keyValue.Value);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user