From 03ada95fbb5f217c5fe3ae107f11580262da68c0 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Wed, 25 Sep 2024 14:03:27 -0700 Subject: [PATCH] InfinityQS --- .vscode/launch.json | 16 +++++--- Day/HelperDay.cs | 2 + Day/Q32024/Helper-2024-09-25.cs | 65 +++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 Day/Q32024/Helper-2024-09-25.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index 0536e3c..e2fa32f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,12 +13,16 @@ "args": [ "s", "X", - "D:/5-Other-Small/Kanban-messa010ec/Kanban/Work-Items", - "Day-Helper-2024-09-11", - "*.json", - ".kanbn", - "Epic|Feature|User Story", - "L:/DevOps/Mesa_FI/File-Folder-Helper/.vscode/helper/tfs" + "\\\\messa04ec.infineon.com\\EC_SPC_Si\\SPC\\Projects\\Active", + "Day-Helper-2024-09-25", + "*.ipj", + "=TEST,", + "L:/DevOps/Mesa_FI/File-Folder-Helper/.vscode/helper/iqs", + "555", + "666", + "777", + "888", + "999" ], "cwd": "${workspaceFolder}", "console": "integratedTerminal", diff --git a/Day/HelperDay.cs b/Day/HelperDay.cs index 2b49a85..75db6f0 100644 --- a/Day/HelperDay.cs +++ b/Day/HelperDay.cs @@ -109,6 +109,8 @@ internal static class HelperDay Day.Q32024.Helper20240911.WriteMarkdown(logger, args); else if (args[1] == "Day-Helper-2024-09-16") Day.Q32024.Helper20240916.DebugProxyPass(logger, args); + else if (args[1] == "Day-Helper-2024-09-25") + Day.Q32024.Helper20240925.DistinctTests(logger, args); else throw new Exception(appSettings.Company); } diff --git a/Day/Q32024/Helper-2024-09-25.cs b/Day/Q32024/Helper-2024-09-25.cs new file mode 100644 index 0000000..70e63e4 --- /dev/null +++ b/Day/Q32024/Helper-2024-09-25.cs @@ -0,0 +1,65 @@ +using Microsoft.Extensions.Logging; +using System.Collections.ObjectModel; +using System.Text.Json; +using System.Text.Json.Serialization; +namespace File_Folder_Helper.Day.Q32024; + +internal static partial class Helper20240925 +{ + + public record Test(string Name, + long Value); + + [JsonSourceGenerationOptions(WriteIndented = true)] + [JsonSerializable(typeof(ReadOnlyCollection))] + internal partial class TestCollectionSourceGenerationContext : JsonSerializerContext + { + } + + private static ReadOnlyCollection GetTests(string sourceDirectory, string searchPattern, string searchPatternB) + { + List results = []; + long test; + string[] lines; + string[] segments; + string[] segmentsB; + List distinct = []; + string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories); + foreach (string file in files) + { + lines = File.ReadAllLines(file); + foreach (string line in lines) + { + segments = line.Split(searchPatternB); + if (segments.Length < 2) + continue; + segmentsB = segments[1].Split(','); + if (segmentsB.Length < 2) + continue; + if (!long.TryParse(segmentsB[0], out test)) + continue; + if (distinct.Contains(test)) + continue; + distinct.Add(test); + results.Add(new(segmentsB[1].Trim('"'), test)); + } + } + return (from l in results orderby l.Name.Length, l.Name select l).ToArray().AsReadOnly(); + } + + internal static void DistinctTests(ILogger logger, List args) + { + string searchPattern = args[2]; + string searchPatternB = args[3]; + string destinationDirectory = args[4]; + string sourceDirectory = Path.GetFullPath(args[0]); + if (!Directory.Exists(destinationDirectory)) + _ = Directory.CreateDirectory(destinationDirectory); + ReadOnlyCollection tests = GetTests(sourceDirectory, searchPattern, searchPatternB); + logger.LogInformation("Found {files} file(s)", tests.Count); + string json = JsonSerializer.Serialize(tests, TestCollectionSourceGenerationContext.Default.ReadOnlyCollectionTest); + string fileName = Path.Combine(destinationDirectory, ".json"); + File.WriteAllText(fileName, json); + } + +} \ No newline at end of file