From e89e11dcf6d70105eb486afe4a5c4fda94aee88c Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Sat, 1 Mar 2025 11:11:50 -0700 Subject: [PATCH] PocketBaseImportWithDeno --- .vscode/launch.json | 17 ++++++--- ADO2025/PI5/Helper-2025-03-01.cs | 62 ++++++++++++++++++++++++++++++++ Day/HelperDay.cs | 2 ++ 3 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 ADO2025/PI5/Helper-2025-03-01.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index 94ecec5..6112f26 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,18 @@ "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll", "args": [ + "s", + "X", + "L:/Git/pocketbase_0.25.8_windows_amd64", + "Day-Helper-2025-03-01", + "*.json", + "-", + "L:/Git/pocketbase-import", + "json.ts", + "input", + "777", + "888", + "999", "s", "X", "L:/Git/pocketbase_0.25.8_windows_amd64", @@ -18,11 +30,6 @@ "immich-db-backup-1739350800014.sql", "COPY_public.", "FROM_stdin", - "555", - "666", - "777", - "888", - "999", "s", "X", "\\\\mesfs.infineon.com\\EC_Characterization_Si\\Archive\\BIORAD4\\2025_Week_09\\2025-02-28\\-660626-_2025-02-28_04;49_PM_395577460", diff --git a/ADO2025/PI5/Helper-2025-03-01.cs b/ADO2025/PI5/Helper-2025-03-01.cs new file mode 100644 index 0000000..2638f3b --- /dev/null +++ b/ADO2025/PI5/Helper-2025-03-01.cs @@ -0,0 +1,62 @@ +using Microsoft.Extensions.Logging; +using System.Collections.ObjectModel; + +namespace File_Folder_Helper.ADO2025.PI5; + +internal static partial class Helper20250301 +{ + + private static ReadOnlyCollection CopyFiles(char split, string workingDirectory, string directory, string[] files) + { + List results = []; + string fileName; + string checkFile; + string checkDirectory = Path.Combine(workingDirectory, directory); + 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)) + File.Delete(checkFile); + File.Copy(file, checkFile); + results.Add(fileName); + } + return results.AsReadOnly(); + } + + private static void PocketBaseImportWithDeno(ILogger logger, char split, string workingDirectory, string scriptName, string directory, string[] files) + { + string checkFile = Path.Combine(workingDirectory, scriptName); + if (!File.Exists(checkFile)) + logger.LogWarning("<{checkFile}> doesn't exist!", checkFile); + else + { + ReadOnlyCollection fileNames = CopyFiles(split, workingDirectory, directory, files); + if (fileNames.Count == 0) + logger.LogWarning("<{fileNames}>(s)", fileNames.Count); + else + { + foreach (string fileName in fileNames) + logger.LogInformation("deno run --unstable --allow-read --allow-env --allow-net {scriptName} --id=true --input={fileName}", scriptName, fileName); + } + } + } + + internal static void PocketBaseImportWithDeno(ILogger logger, List args) + { + char split = args[3][0]; + string directory = args[6]; + string scriptName = args[5]; + string searchPattern = args[2]; + string sourceDirectory = Path.GetFullPath(args[0]); + string workingDirectory = Path.GetFullPath(args[4]); + string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories); + if (files.Length == 0) + logger.LogWarning("<{files}>(s)", files.Length); + else + PocketBaseImportWithDeno(logger, split, workingDirectory, scriptName, directory, files); + } + +} \ No newline at end of file diff --git a/Day/HelperDay.cs b/Day/HelperDay.cs index 1aa66ad..fe56367 100644 --- a/Day/HelperDay.cs +++ b/Day/HelperDay.cs @@ -139,6 +139,8 @@ internal static class HelperDay ADO2025.PI5.Helper20250219.Compare(logger, args); else if (args[1] == "Day-Helper-2025-02-28") ADO2025.PI5.Helper20250228.PostgresDumpToJson(logger, args); + else if (args[1] == "Day-Helper-2025-03-01") + ADO2025.PI5.Helper20250301.PocketBaseImportWithDeno(logger, args); else throw new Exception(appSettings.Company); }