From a473fd1af1f87c31335386b244ebeded2150ff3d Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Fri, 2 Aug 2024 13:29:22 -0700 Subject: [PATCH] VSCodeTask --- .vscode/launch.json | 15 ++----- .vscode/mklink.md | 6 +-- Day/2024-Q3/Helper-2024-07-24.cs | 11 ++--- Helpers/HelperMarkdown.cs | 74 +++++++++++++++++++++++++++++--- Models/NginxFileSystem.cs | 30 +++++++++++++ Models/VSCodeTasks.cs | 43 +++++++++++++++++++ 6 files changed, 152 insertions(+), 27 deletions(-) create mode 100644 Models/NginxFileSystem.cs create mode 100644 Models/VSCodeTasks.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index 4941fcd..8b098b2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,17 +12,10 @@ "program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll", "args": [ "s", - "X", - "D:/5-Other-Small/Proxmox/Day-Helper-2024-07-28", - "Day-Helper-2024-07-28", - "ddns.net", - "dashkiosk,gitea,ha,immich,music,odoo,pihole,phares,pgadmin,quartz,slideshow,umbrel,vaultwarden", - "C:/Program Files/Git/mingw64/bin/openssl.exe", - "12345", - "-----BEGIN CERTIFICATE", - "END CERTIFICATE-----", - "certutil -addstore", - "Root" + "M", + "D:/5-Other-Small/Kanban-mestsa003/Other/UWM @ LEO", + "-d", + "D:/5-Other-Small/Kanban-mestsa003/Other/UWM @ LEO/.vscode/helper" ], "cwd": "${workspaceFolder}", "console": "integratedTerminal", diff --git a/.vscode/mklink.md b/.vscode/mklink.md index 6c869e5..c912aaa 100644 --- a/.vscode/mklink.md +++ b/.vscode/mklink.md @@ -18,9 +18,9 @@ mklink /J "L:\DevOps\Mesa_FI\File-Folder-Helper\.kanbn" "D:\5-Other-Small\Kanban del "L:\DevOps\Mesa_FI\File-Folder-Helper\.extensions-vscode" del "L:\DevOps\Mesa_FI\File-Folder-Helper\.extensions-vscode-oss" del "L:\DevOps\Mesa_FI\File-Folder-Helper\.extensions-vscode-insiders" -mklink /J "L:\DevOps\Mesa_FI\File-Folder-Helper\.extensions-vscode" "C:\Users\phares\.vscode\extensions\ifx.type-script-helper-1.6.2" -mklink /J "L:\DevOps\Mesa_FI\File-Folder-Helper\.extensions-vscode-oss" "C:\Users\phares\.vscode-oss\extensions\ifx.type-script-helper-1.6.2" -mklink /J "L:\DevOps\Mesa_FI\File-Folder-Helper\.extensions-vscode-insiders" "C:\Users\phares\.vscode-insiders\extensions\ifx.type-script-helper-1.6.2" +mklink /J "L:\DevOps\Mesa_FI\File-Folder-Helper\.extensions-vscode" "C:\Users\phares\.vscode\extensions\ifx.type-script-helper-1.6.3" +mklink /J "L:\DevOps\Mesa_FI\File-Folder-Helper\.extensions-vscode-oss" "C:\Users\phares\.vscode-oss\extensions\ifx.type-script-helper-1.6.3" +mklink /J "L:\DevOps\Mesa_FI\File-Folder-Helper\.extensions-vscode-insiders" "C:\Users\phares\.vscode-insiders\extensions\ifx.type-script-helper-1.6.3" ``` ```bash Thu Jul 18 2024 13:47:40 GMT-0700 (Mountain Standard Time) diff --git a/Day/2024-Q3/Helper-2024-07-24.cs b/Day/2024-Q3/Helper-2024-07-24.cs index b3f5759..222800d 100644 --- a/Day/2024-Q3/Helper-2024-07-24.cs +++ b/Day/2024-Q3/Helper-2024-07-24.cs @@ -1,3 +1,4 @@ +using File_Folder_Helper.Models; using Microsoft.Extensions.Logging; using System.Collections.ObjectModel; using System.Diagnostics; @@ -9,11 +10,6 @@ namespace File_Folder_Helper.Day; internal static partial class Helper20240724 { - private record NginxFileSystem(string Name, - string Type, - string MTime, - float Size); - private record FileConnectorConfigurationSystem(string AlternateTargetFolder, string FileAgeThreshold, string[] SourceFileFilters, @@ -95,7 +91,6 @@ internal static partial class Helper20240724 NginxFileSystem[]? weekNginxFileSystemCollection; string[] days = GetValidDays(fileAgeThresholdDateTime); string[] weeks = GetValidWeeks(fileAgeThresholdDateTime); - JsonSerializerOptions propertyNameCaseInsensitiveJsonSerializerOptions = new() { PropertyNameCaseInsensitive = true }; foreach (string week in weeks) { checkWeek = string.Concat("http://", _StaticFileServer, '/', week); @@ -104,7 +99,7 @@ internal static partial class Helper20240724 if (!task.Result.IsSuccessStatusCode) continue; weekJson = _HttpClient.GetStringAsync(checkWeek).Result; - weekNginxFileSystemCollection = JsonSerializer.Deserialize(weekJson, propertyNameCaseInsensitiveJsonSerializerOptions); + weekNginxFileSystemCollection = JsonSerializer.Deserialize(weekJson, NginxFileSystemCollectionSourceGenerationContext.Default.NginxFileSystemArray); if (weekNginxFileSystemCollection is null) continue; foreach (NginxFileSystem weekNginxFileSystem in weekNginxFileSystemCollection) @@ -113,7 +108,7 @@ internal static partial class Helper20240724 continue; dayUrl = string.Concat(checkWeek, '/', weekNginxFileSystem.Name); dayJson = _HttpClient.GetStringAsync(dayUrl).Result; - dayNginxFileSystemCollection = JsonSerializer.Deserialize(dayJson, propertyNameCaseInsensitiveJsonSerializerOptions); + dayNginxFileSystemCollection = JsonSerializer.Deserialize(dayJson, NginxFileSystemCollectionSourceGenerationContext.Default.NginxFileSystemArray); if (dayNginxFileSystemCollection is null) continue; results.AddRange(GetDayNginxFileSystemCollection(fileAgeThresholdDateTime, week, weekNginxFileSystem.Name, dayUrl, dayNginxFileSystemCollection)); diff --git a/Helpers/HelperMarkdown.cs b/Helpers/HelperMarkdown.cs index bd00899..eb0bef1 100644 --- a/Helpers/HelperMarkdown.cs +++ b/Helpers/HelperMarkdown.cs @@ -366,6 +366,28 @@ internal static partial class HelperMarkdown return (lines.ToList(), lineNumber); } + private static Dictionary GetFromMatterYaml(ReadOnlyCollection frontMatterYamlLines) + { + Dictionary results = []; + string[] segments; + foreach (string line in frontMatterYamlLines.OrderBy(l => l)) + { + segments = line.Split(": "); + if (segments.Length != 2) + { + results.Clear(); + break; + } + if (segments[1] is "''" or "\"\"") + results.Add(segments[0], string.Empty); + else if (segments[1] == "[]") + results.Add(segments[0], Array.Empty()); + else + results.Add(segments[0], segments[1].Trim()); + } + return results; + } + private static ReadOnlyDictionary GetFromMatterYaml(List lines, LineNumber lineNumber) { Dictionary results = []; @@ -373,12 +395,19 @@ internal static partial class HelperMarkdown IDeserializer deserializer = new DeserializerBuilder().Build(); #pragma warning restore IL3050 ReadOnlyCollection frontMatterYamlLines = GetFromMatterYamlLines(lines, lineNumber); - string frontMatterYaml = string.Join(Environment.NewLine, frontMatterYamlLines); - Dictionary? keyValuePairs = deserializer.Deserialize>(frontMatterYaml); - if (keyValuePairs is not null) + if (!frontMatterYamlLines.Any(l => l.StartsWith(' '))) + results = GetFromMatterYaml(frontMatterYamlLines); + else { - foreach (string key in keyValuePairs.Keys.OrderBy(l => l)) - results.Add(key, keyValuePairs[key]); + string frontMatterYaml = string.Join(Environment.NewLine, frontMatterYamlLines); + Dictionary? keyValuePairs = deserializer.Deserialize>(frontMatterYaml); + if (keyValuePairs is null) + results = GetFromMatterYaml(frontMatterYamlLines); + else + { + foreach (string key in keyValuePairs.Keys.OrderBy(l => l)) + results.Add(key, keyValuePairs[key]); + } } return new(results); } @@ -1135,6 +1164,36 @@ internal static partial class HelperMarkdown return new(result?.MarkdownFile, result?.Lines, result?.MarkdownFile.H1, result is null ? null : Path.GetRelativePath(markdownFile.Directory, Path.GetFullPath(result.MarkdownFile.File))); } + private static List GetTaskArgumentsForDayHelper20240623(Input input) + { + if (string.IsNullOrEmpty(input.Destination)) + throw new NotSupportedException(); + List results = []; + string? vscodeDirectory = Path.GetDirectoryName(input.Destination); + string? taskFile = vscodeDirectory is null ? null : Path.Combine(vscodeDirectory, "tasks.json"); + if (!string.IsNullOrEmpty(taskFile) && File.Exists(taskFile)) + { + string json = File.ReadAllText(taskFile); + VSCodeTasks? vsCodeTasks = JsonSerializer.Deserialize(json, VSCodeTasksSourceGenerationContext.Default.VSCodeTasks); + if (vsCodeTasks is not null && vsCodeTasks.TaskCollection is not null) + { + foreach (VSCodeTask vsCodeTask in vsCodeTasks.TaskCollection) + { + if (vsCodeTask.Arguments is null || vsCodeTask.Arguments.Count < 4 || vsCodeTask.Arguments[3] != "Day-Helper-2024-06-23") + continue; + if (results.Count > 0) + { + results.Clear(); + break; + } + results.AddRange(vsCodeTask.Arguments.Skip(2)); + break; + } + } + } + return results; + } + internal static void MarkdownWikiLinkVerification(AppSettings appSettings, ILogger logger, List args, CancellationToken cancellationToken) { int updated; @@ -1179,7 +1238,12 @@ internal static partial class HelperMarkdown logger.LogInformation("{updated} Markdown file(s) were updated", updated); } if (!string.IsNullOrEmpty(input.Destination)) + { SaveColumnToCards(input, relativeToCollection); + List taskArgumentsForDayHelper20240623 = GetTaskArgumentsForDayHelper20240623(input); + if (taskArgumentsForDayHelper20240623.Count > 0) + HelperDay.Select(appSettings, logger, taskArgumentsForDayHelper20240623, cancellationToken: CancellationToken.None); + } } } \ No newline at end of file diff --git a/Models/NginxFileSystem.cs b/Models/NginxFileSystem.cs new file mode 100644 index 0000000..9682266 --- /dev/null +++ b/Models/NginxFileSystem.cs @@ -0,0 +1,30 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace File_Folder_Helper.Models; + +public record NginxFileSystem(string Name, + string Type, + string MTime, + float Size) +{ + + public override string ToString() + { + string result = JsonSerializer.Serialize(this, NginxFileSystemSourceGenerationContext.Default.NginxFileSystem); + return result; + } + +} + +[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] +[JsonSerializable(typeof(NginxFileSystem))] +internal partial class NginxFileSystemSourceGenerationContext : JsonSerializerContext +{ +} + +[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] +[JsonSerializable(typeof(NginxFileSystem[]))] +internal partial class NginxFileSystemCollectionSourceGenerationContext : JsonSerializerContext +{ +} \ No newline at end of file diff --git a/Models/VSCodeTasks.cs b/Models/VSCodeTasks.cs new file mode 100644 index 0000000..94bc40b --- /dev/null +++ b/Models/VSCodeTasks.cs @@ -0,0 +1,43 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace File_Folder_Helper.Models; + +public record VSCodeTask([property: JsonPropertyName("label")] string? Label, + [property: JsonPropertyName("command")] string? Command, + [property: JsonPropertyName("type")] string? Type, + [property: JsonPropertyName("args")] IReadOnlyList? Arguments, + [property: JsonPropertyName("script")] string? Script) +{ + + public override string ToString() + { + string result = JsonSerializer.Serialize(this, VSCodeTaskSourceGenerationContext.Default.VSCodeTask); + return result; + } + +} + +[JsonSourceGenerationOptions(WriteIndented = true, PropertyNameCaseInsensitive = true)] +[JsonSerializable(typeof(VSCodeTask))] +internal partial class VSCodeTaskSourceGenerationContext : JsonSerializerContext +{ +} + +public record VSCodeTasks([property: JsonPropertyName("version")] string? Version, + [property: JsonPropertyName("tasks")] VSCodeTask[]? TaskCollection) +{ + + public override string ToString() + { + string result = JsonSerializer.Serialize(this, VSCodeTasksSourceGenerationContext.Default.VSCodeTasks); + return result; + } + +} + +[JsonSourceGenerationOptions(WriteIndented = true, PropertyNameCaseInsensitive = true)] +[JsonSerializable(typeof(VSCodeTasks))] +internal partial class VSCodeTasksSourceGenerationContext : JsonSerializerContext +{ +} \ No newline at end of file