From 5fe51ef645dfa55f1994c9943ac13b396ed1076d Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Tue, 14 Nov 2023 07:54:34 -0700 Subject: [PATCH] nuget bump 2023-11-02 2023-11-08 net8.0 editorconfig NuGet NuSpec Kanban --- .editorconfig | 30 ++++- .gitignore | 2 +- .vscode/launch.json | 2 +- .vscode/mklink.md | 15 +++ .vscode/tasks.json | 30 ++--- Day/Helper-2023-10-24.cs | 125 ++++++++++++++++++ Day/Helper-2023-11-02.cs | 35 +++++ Day/Helper-2023-11-08.cs | 37 ++++++ Day/HelperDay.cs | 6 + File-Folder-Helper.csproj | 9 +- Helpers/HelperCreateNoteFiles.cs | 10 +- Helpers/HelperDeleteEmptyDirectories.cs | 6 +- Helpers/HelperFindReplace.cs | 2 +- .../HelperGenealogicalDataCommunication.cs | 80 +++++------ Helpers/HelperHardcodedFileSearchAndSort.cs | 6 +- Helpers/HelperILMerge.cs | 4 +- Helpers/HelperKanbanMetadata.cs | 2 +- Helpers/HelperLogMerge.cs | 8 +- Helpers/HelperMarkdown.cs | 70 +++++----- Helpers/HelperPackageFilesByDate.cs | 2 +- Helpers/HelperPdfStripperWrapper.cs | 2 +- Helpers/HelperRenameToOldMoveDeleteOld.cs | 2 +- Helpers/HelperStart.cs | 2 +- Helpers/HelperVSCodePossibleExtension.cs | 6 +- Helpers/HelperZipFilesBy.cs | 97 ++++++++------ Models/Binder/AppSettings.cs | 1 + Worker.cs | 8 +- 27 files changed, 429 insertions(+), 170 deletions(-) create mode 100644 .vscode/mklink.md create mode 100644 Day/Helper-2023-10-24.cs create mode 100644 Day/Helper-2023-11-02.cs create mode 100644 Day/Helper-2023-11-08.cs diff --git a/.editorconfig b/.editorconfig index 046ef9f..e394f93 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,3 +1,19 @@ +[*.md] +end_of_line = crlf +file_header_template = unset +indent_size = 2 +indent_style = space +insert_final_newline = false +root = true +tab_width = 2 +[*.csproj] +end_of_line = crlf +file_header_template = unset +indent_size = 2 +indent_style = space +insert_final_newline = false +root = true +tab_width = 2 [*.cs] csharp_indent_block_contents = true csharp_indent_braces = false @@ -13,6 +29,7 @@ csharp_new_line_before_members_in_object_initializers = true csharp_new_line_before_open_brace = all csharp_new_line_between_query_expression_clauses = true csharp_prefer_braces = false +csharp_prefer_qualified_reference = true:error csharp_prefer_simple_default_expression = true:warning csharp_prefer_simple_using_statement = true:warning csharp_prefer_static_local_function = true:warning @@ -79,11 +96,22 @@ dotnet_code_quality.CAXXXX.api_surface = private, internal dotnet_diagnostic.CA1825.severity = warning # CA1823: Avoid zero-length array allocations dotnet_diagnostic.CA1829.severity = warning # CA1829: Use Length/Count property instead of Count() when available dotnet_diagnostic.CA1834.severity = warning # CA1834: Consider using 'StringBuilder.Append(char)' when applicable +dotnet_diagnostic.CA1860.severity = error # CA1860: Prefer comparing 'Count' to 0 rather than using 'Any()', both for clarity and for performance +dotnet_diagnostic.CA1869.severity = none # CA1869: Avoid creating a new 'JsonSerializerOptions' instance for every serialization operation. Cache and reuse instances instead. +dotnet_diagnostic.CA2254.severity = none # CA2254: The logging message template should not vary between calls to 'LoggerExtensions.LogInformation(ILogger, string?, params object?[])' dotnet_diagnostic.IDE0001.severity = warning # IDE0001: Simplify name dotnet_diagnostic.IDE0002.severity = warning # Simplify (member access) - System.Version.Equals("1", "2"); Version.Equals("1", "2"); +dotnet_diagnostic.IDE0004.severity = warning # IDE0004: Cast is redundant. dotnet_diagnostic.IDE0005.severity = warning # Using directive is unnecessary +dotnet_diagnostic.IDE0028.severity = error # IDE0028: Collection initialization can be simplified +dotnet_diagnostic.IDE0031.severity = warning # Use null propagation (IDE0031) dotnet_diagnostic.IDE0047.severity = warning # IDE0047: Parentheses can be removed +dotnet_diagnostic.IDE0049.severity = warning # Use language keywords instead of framework type names for type references (IDE0049) dotnet_diagnostic.IDE0060.severity = warning # IDE0060: Remove unused parameter +dotnet_diagnostic.IDE0290.severity = none # Use primary constructor [Distance]csharp(IDE0290) +dotnet_diagnostic.IDE0300.severity = error # IDE0300: Collection initialization can be simplified +dotnet_diagnostic.IDE0301.severity = error #IDE0301: Collection initialization can be simplified +dotnet_diagnostic.IDE0305.severity = none # IDE0305: Collection initialization can be simplified dotnet_naming_rule.abstract_method_should_be_pascal_case.severity = warning dotnet_naming_rule.abstract_method_should_be_pascal_case.style = pascal_case dotnet_naming_rule.abstract_method_should_be_pascal_case.symbols = abstract_method @@ -215,7 +243,7 @@ dotnet_style_parentheses_in_other_binary_operators = always_for_clarity dotnet_style_parentheses_in_other_operators = never_if_unnecessary dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity dotnet_style_predefined_type_for_locals_parameters_members = true -dotnet_style_predefined_type_for_member_access = true +dotnet_style_predefined_type_for_member_access = true:warning dotnet_style_prefer_auto_properties = true:warning dotnet_style_prefer_compound_assignment = true:warning dotnet_style_prefer_conditional_expression_over_assignment = false diff --git a/.gitignore b/.gitignore index 3fa5e0a..8ac8f51 100644 --- a/.gitignore +++ b/.gitignore @@ -330,4 +330,4 @@ ASALocalRun/ .vscode/Helper/** -.kanbn/board* \ No newline at end of file +.kanbn \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index db9b413..d7ba071 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "type": "coreclr", "request": "launch", "preLaunchTask": "build", - "program": "${workspaceFolder}/bin/Debug/net7.0/win-x64/File-Folder-Helper.dll", + "program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll", "args": [ "s", "\\\\messv02ecc1.ec.local\\EC_EDA\\Staging\\Traces\\HTR-PLC\\R72-PLC\\PollPath" diff --git a/.vscode/mklink.md b/.vscode/mklink.md new file mode 100644 index 0000000..49aea77 --- /dev/null +++ b/.vscode/mklink.md @@ -0,0 +1,15 @@ +--- +type: "note" +created: "2023-10-20T03:53:13.742Z" +updated: "2023-10-20T04:00:37.259Z" +--- + +# mklink + +```bash +mklink /J "L:\DevOps\Mesa_FI\File-Folder-Helper\.kanbn" "D:\Documents\Kanban\File-Folder-Helper" +``` + +```bash +mklink /J "L:\DevOps\Mesa_FI\File-Folder-Helper\.kanbn" "D:\5-Other-Small\Kanban\File-Folder-Helper" +``` diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 7390a31..702b664 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -100,91 +100,91 @@ { "label": "File-Folder-Helper AOT s H Run Data Repository", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.ec.local\\apps\\Metrology\\Run Data Repository'", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.infineon.com\\apps\\Metrology\\Run Data Repository'", "problemMatcher": [] }, { "label": "File-Folder-Helper AOT s J Verdaccio", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s J 'L:/Verdaccio/storage'", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s J 'L:/Verdaccio/storage'", "problemMatcher": [] }, { "label": "File-Folder-Helper AOT s M Self .Kanbn Tasks", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s M '.kanbn/tasks'", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s M '.kanbn/tasks'", "problemMatcher": [] }, { "label": "File-Folder-Helper AOT s S BaGet", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s S 'L:/BaGet/packages'", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s S 'L:/BaGet/packages'", "problemMatcher": [] }, { "label": "File-Folder-Helper AOT s V Helpers", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s V Helpers", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s V Helpers", "problemMatcher": [] }, { "label": "File-Folder-Helper AOT s H MET08ANLYSDIFAAST230", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.ec.local\\apps\\Metrology\\Run Data Repository\\MET08ANLYSDIFAAST230\\Source\\MET08ANLYSDIFAAST230'", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.infineon.com\\apps\\Metrology\\Run Data Repository\\MET08ANLYSDIFAAST230\\Source\\MET08ANLYSDIFAAST230'", "problemMatcher": [] }, { "label": "File-Folder-Helper AOT s H MET08DDUPSFS6420", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.ec.local\\apps\\Metrology\\Run Data Repository\\MET08DDUPSFS6420\\Source\\MET08DDUPSFS6420'", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.infineon.com\\apps\\Metrology\\Run Data Repository\\MET08DDUPSFS6420\\Source\\MET08DDUPSFS6420'", "problemMatcher": [] }, { "label": "File-Folder-Helper AOT s H MET08DDUPSP1TBI", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.ec.local\\apps\\Metrology\\Run Data Repository\\MET08DDUPSP1TBI\\Source\\MET08DDUPSP1TBI'", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.infineon.com\\apps\\Metrology\\Run Data Repository\\MET08DDUPSP1TBI\\Source\\MET08DDUPSP1TBI'", "problemMatcher": [] }, { "label": "File-Folder-Helper AOT s H MET08RESIHGCV", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.ec.local\\apps\\Metrology\\Run Data Repository\\MET08RESIHGCV\\Source\\MET08RESIHGCV'", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.infineon.com\\apps\\Metrology\\Run Data Repository\\MET08RESIHGCV\\Source\\MET08RESIHGCV'", "problemMatcher": [] }, { "label": "File-Folder-Helper AOT s H MET08RESIMAPCDE", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.ec.local\\apps\\Metrology\\Run Data Repository\\MET08RESIMAPCDE\\Source\\MET08RESIMAPCDE'", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.infineon.com\\apps\\Metrology\\Run Data Repository\\MET08RESIMAPCDE\\Source\\MET08RESIMAPCDE'", "problemMatcher": [] }, { "label": "File-Folder-Helper AOT s H MET08RESISRP2100", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.ec.local\\apps\\Metrology\\Run Data Repository\\MET08RESISRP2100\\Source\\MET08RESISRP2100'", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.infineon.com\\apps\\Metrology\\Run Data Repository\\MET08RESISRP2100\\Source\\MET08RESISRP2100'", "problemMatcher": [] }, { "label": "File-Folder-Helper AOT s H MET08THFTIRQS408M", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.ec.local\\apps\\Metrology\\Run Data Repository\\MET08THFTIRQS408M\\Source\\MET08THFTIRQS408M'", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.infineon.com\\apps\\Metrology\\Run Data Repository\\MET08THFTIRQS408M\\Source\\MET08THFTIRQS408M'", "problemMatcher": [] }, { "label": "File-Folder-Helper AOT s H MET08THFTIRSTRATUS", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.ec.local\\apps\\Metrology\\Run Data Repository\\MET08THFTIRSTRATUS\\Source\\MET08THFTIRSTRATUS'", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.infineon.com\\apps\\Metrology\\Run Data Repository\\MET08THFTIRSTRATUS\\Source\\MET08THFTIRSTRATUS'", "problemMatcher": [] }, { "label": "File-Folder-Helper AOT s H WaferCounter", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.ec.local\\apps\\WaferCounter\\BackupFiles'", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s H '\\\\messa01ec.infineon.com\\apps\\WaferCounter\\BackupFiles'", "problemMatcher": [] }, { "label": "File-Folder-Helper AOT s F Staging _Logs", "type": "shell", - "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net7.0/win-x64/publish/File-Folder-Helper.exe s F '\\\\messv02ecc1.ec.local\\EC_EAFLog\\Staging\\_ Logs'", + "command": "& L:/DevOps/Mesa_FI/File-Folder-Helper/bin/Release/net8.0/win-x64/publish/File-Folder-Helper.exe s F '\\\\messv02ecc1.ec.local\\EC_EAFLog\\Staging\\_ Logs'", "problemMatcher": [] }, { diff --git a/Day/Helper-2023-10-24.cs b/Day/Helper-2023-10-24.cs new file mode 100644 index 0000000..c2a0cca --- /dev/null +++ b/Day/Helper-2023-10-24.cs @@ -0,0 +1,125 @@ +using Microsoft.Extensions.Logging; +using System.Diagnostics; +using System.Text; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace File_Folder_Helper.Day; + +internal record Drive(string Share, + bool Use, + string User); + +internal static class Helper20231024 +{ + + internal static void NetUse(ILogger logger, string argsZero) + { + Process? process; + string arguments; + string[] segments; + string standardError; + string standardOutput; + string fileName = "net"; + StringBuilder stringBuilder = new(); + string json = File.ReadAllText(Path.Combine(argsZero, ".json")); + string decrypted = File.ReadAllText(Path.Combine(argsZero, ".password")); + List drives = JsonSerializer.Deserialize(json, DrivesSourceGenerationContext.Default.ListDrive) ?? throw new NullReferenceException(); + foreach (Drive drive in drives) + { + if (!drive.Use) + continue; + arguments = $"use * \"{drive.Share}\" /p:yes /user:{drive.User} {decrypted}"; + _ = stringBuilder.Clear(); + segments = arguments.Split(' '); + for (int j = 0; j < segments.Length - 1; j++) + _ = stringBuilder.Append(segments[j]).Append(' '); + logger.LogInformation("// {stringBuilder}", stringBuilder); + ProcessStartInfo processStartInfo = new(fileName, arguments) + { + RedirectStandardError = true, + RedirectStandardOutput = true, + UseShellExecute = false + }; + try + { + process = Process.Start(processStartInfo); + if (process is null) + continue; + for (int j = 1; j < 45; j++) + { + _ = process.WaitForExit(1000); + if (process.HasExited) + break; + } + if (!process.HasExited) + logger.LogError("// Never exited!"); + else + { + standardError = process.StandardError.ReadToEnd(); + standardOutput = process.StandardOutput.ReadToEnd(); + logger.LogInformation("// {standardError}{Environment.NewLine}{Environment.NewLine}// {standardOutput}", standardError, Environment.NewLine, Environment.NewLine, standardOutput); + try + { + _ = Directory.CreateDirectory($"{drive.Share}\\Tmp\\Phares"); + string reg = """ + Windows Registry Editor Version 5.00 + + [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ODBC\ODBC.INI\SPCEPIWORLD] + "Driver"="C:\\WINDOWS\\system32\\SQLSRV32.dll" + "Description"="InfinityQS SPC (Si)" + "Server"="messqlec1.infineon.com\\PROD1,53959" + "Database"="SPCEPIWORLD" + "LastUser"="" + "Trusted_Connection"="Yes" + + [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ODBC\ODBC.INI\ODBC Data Sources] + "SPCEPIWORLD"="SQL Server" + """; + string bat = """ + @ECHO OFF + NET USE G: /delete + NET USE H: /delete + NET USE M: /delete + NET USE P: /delete + NET USE R: /delete + NET USE T: /delete + NET USE V: /delete + NET USE Y: /delete + NET USE G: \\mesfs.infineon.com\EC_Engineering /PERSISTENT:YES + NET USE H: \\mesfs.infineon.com\EC_TempHumidity_Controls /PERSISTENT:YES + NET USE M: \\mesfs.infineon.com\EC_Maintenance /PERSISTENT:YES + NET USE P: \\mesfs.infineon.com\EC_Production /PERSISTENT:YES + NET USE R: \\mesfs.infineon.com\EC_Customer_Service /PERSISTENT:YES + NET USE T: \\mesfs.infineon.com\EC_Materials /PERSISTENT:YES + NET USE V: \\mesfs.infineon.com\EC_Engineering /PERSISTENT:YES + NET USE Y: \\mesfs.infineon.com\EC_EpiReactorRecipes /PERSISTENT:YES + """; + File.WriteAllText($"{drive.Share}\\Tmp\\Phares\\SPCEPIWORLD_hklm.reg", reg); + File.WriteAllText($"{drive.Share}\\Tmp\\Phares\\MESA-Users-Drives.bat", bat); + File.WriteAllText($"{drive.Share}\\Tmp\\Phares\\lnk.txt", """"\\messa04ec.infineon.com\EC_SPC_Si\SPC\Projects\Active\ir epi services database.ipj""""); + } + catch (Exception) + { } + } + } + catch (Exception ex) + { + logger.LogError(ex, "Error:"); + } + } + } + +} + +[JsonSourceGenerationOptions(WriteIndented = true)] +[JsonSerializable(typeof(Drive))] +internal partial class DriveSourceGenerationContext : JsonSerializerContext +{ +} + +[JsonSourceGenerationOptions(WriteIndented = true)] +[JsonSerializable(typeof(List))] +internal partial class DrivesSourceGenerationContext : JsonSerializerContext +{ +} \ No newline at end of file diff --git a/Day/Helper-2023-11-02.cs b/Day/Helper-2023-11-02.cs new file mode 100644 index 0000000..b9521b7 --- /dev/null +++ b/Day/Helper-2023-11-02.cs @@ -0,0 +1,35 @@ +using Microsoft.Extensions.Logging; + +namespace File_Folder_Helper.Day; + +internal static class Helper20231102 +{ + + internal static void NuSpec(ILogger logger, string argsZero) + { + string[] lines; + string? idLine; + string? versionLine; + string[] files = Directory.GetFiles(argsZero); + logger.LogInformation("{fileCount}", files.Length.ToString()); + foreach (string file in files) + { + idLine = null; + versionLine = null; + lines = File.ReadAllLines(file); + foreach (string line in lines) + { + if (!line.EndsWith("") && !line.EndsWith("")) + continue; + if (line.EndsWith("")) + idLine = line.TrimEnd(); + if (line.EndsWith("")) + versionLine = line.TrimEnd(); + if (idLine is not null && versionLine is not null) + break; + } + File.AppendAllText(".txt", $"{idLine}{versionLine}{Environment.NewLine}"); + } + } + +} \ No newline at end of file diff --git a/Day/Helper-2023-11-08.cs b/Day/Helper-2023-11-08.cs new file mode 100644 index 0000000..6f50d7f --- /dev/null +++ b/Day/Helper-2023-11-08.cs @@ -0,0 +1,37 @@ +using Microsoft.Extensions.Logging; + +namespace File_Folder_Helper.Day; + +internal static class Helper20231108 +{ + + internal static void MasterImage(ILogger logger, List args) + { + string fileName; + string checkFile; + string[] aSegments; + string[] bSegments; + if (!Directory.Exists(args[0])) + throw new Exception(args[0]); + if (!Directory.Exists(args[2])) + throw new Exception(args[2]); + string directoryName = Path.GetFileName(args[0]) ?? throw new Exception(); + string[] files = Directory.GetFiles(args[0]); + logger.LogInformation("{fileCount}", files.Length.ToString()); + foreach (string file in files) + { + aSegments = Path.GetFileNameWithoutExtension(file).Split('-'); + if (aSegments.Length != 2) + continue; + bSegments = aSegments[1].Split('_'); + if (bSegments.Length != 3) + continue; + fileName = $"{directoryName}-{bSegments[1]}-{bSegments[0]}{Path.GetExtension(file)}"; + checkFile = Path.Combine(args[2], fileName); + if (File.Exists(checkFile)) + continue; + File.Copy(file, checkFile); + } + } + +} \ No newline at end of file diff --git a/Day/HelperDay.cs b/Day/HelperDay.cs index 216a1ea..473c357 100644 --- a/Day/HelperDay.cs +++ b/Day/HelperDay.cs @@ -14,6 +14,12 @@ internal static class HelperDay Day.Helper20231010.HgCV(logger, args[0]); else if (args[1] == "Day-Helper-2023-10-16") Day.Helper20231016.MoveDirectory(logger, args[0]); + else if (args[1] == "Day-Helper-2023-10-24") + Day.Helper20231024.NetUse(logger, args[0]); + else if (args[1] == "Day-Helper-2023-11-02") + Day.Helper20231102.NuSpec(logger, args[0]); + else if (args[1] == "Day-Helper-2023-11-08") + Day.Helper20231108.MasterImage(logger, args); else throw new Exception(appSettings.Company); } diff --git a/File-Folder-Helper.csproj b/File-Folder-Helper.csproj index 20bfe5e..81b1d4b 100644 --- a/File-Folder-Helper.csproj +++ b/File-Folder-Helper.csproj @@ -1,7 +1,6 @@ enable - 11.0 enable Exe win-x64 @@ -9,10 +8,10 @@ eb9e8f58-fcb5-45bb-9d4d-54f064c485b1 - - - - + + + + \ No newline at end of file diff --git a/Helpers/HelperCreateNoteFiles.cs b/Helpers/HelperCreateNoteFiles.cs index bb41301..edd9f56 100644 --- a/Helpers/HelperCreateNoteFiles.cs +++ b/Helpers/HelperCreateNoteFiles.cs @@ -146,8 +146,8 @@ internal static partial class HelperCreateNoteFiles file = string.Concat(Path.Combine(directory, $"{dateTime:yyyy-MM-dd}.md")); if (File.Exists(file)) continue; - File.WriteAllLines(file, new string[] - { + File.WriteAllLines(file, + [ "---", "type: daily-note", $"created: {dateTime:yyyy-MM-dd}", @@ -158,7 +158,7 @@ internal static partial class HelperCreateNoteFiles "```bash", string.Empty, "```", - }); + ]); if (directory != lastDirectory) { Directory.SetCreationTime(directory, dateTime); @@ -192,8 +192,8 @@ internal static partial class HelperCreateNoteFiles string? attributes; int descriptionKey = 2; string[]? headerColumns; + List allLines = []; string destinationDirectory; - List allLines = new(); DateTime dateTime = new(ticks); string csvHeader = "type,title,description,tags,links,body"; string tsvHeader = "type\ttitle\tdescription\ttags\tlinks\tbody"; @@ -275,8 +275,8 @@ internal static partial class HelperCreateNoteFiles internal static void CreateNoteFiles(ILogger logger, string argsZero) { + List importFiles = []; long ticks = DateTime.Now.Ticks; - List importFiles = new(); CleanExistingFiles(logger, argsZero, ticks); importFiles.AddRange(Directory.GetFiles(argsZero, "*.csv", SearchOption.TopDirectoryOnly)); importFiles.AddRange(Directory.GetFiles(argsZero, "*.tsv", SearchOption.TopDirectoryOnly)); diff --git a/Helpers/HelperDeleteEmptyDirectories.cs b/Helpers/HelperDeleteEmptyDirectories.cs index 880c0ce..31ec2ca 100644 --- a/Helpers/HelperDeleteEmptyDirectories.cs +++ b/Helpers/HelperDeleteEmptyDirectories.cs @@ -24,7 +24,7 @@ internal static class HelperDeleteEmptyDirectories } } if (directories.Length > 0) - files = Array.Empty(); + files = []; else files = Directory.GetFiles(checkDirectory, "*", SearchOption.TopDirectoryOnly); if (directories.Length == 0 && files.Length == 0) @@ -40,7 +40,7 @@ internal static class HelperDeleteEmptyDirectories } else { - List check = new(); + List check = []; foreach (string directory in directories) { DeleteOldLogFilesAndDeleteEmptyDirectories(ticks, searchPattern, directory, check); @@ -53,7 +53,7 @@ internal static class HelperDeleteEmptyDirectories private static void DeleteOldLogFilesAndDeleteEmptyDirectories(ILogger logger, long? ticks, string? searchPattern, string rootDirectory) { - List check = new(); + List check = []; List directories = Directory.GetDirectories(rootDirectory, "*", SearchOption.TopDirectoryOnly).ToList(); directories.Add(rootDirectory); foreach (string directory in directories) diff --git a/Helpers/HelperFindReplace.cs b/Helpers/HelperFindReplace.cs index 1d3bb9f..1c2aad9 100644 --- a/Helpers/HelperFindReplace.cs +++ b/Helpers/HelperFindReplace.cs @@ -23,7 +23,7 @@ internal static class HelperFindReplace private static ReadOnlyCollection<(string, string)> GetFindReplace(string tnsNamesOraFile) { - List<(string, string)> results = new(); + List<(string, string)> results = []; string[] segments; string[] lines = File.ReadAllLines(tnsNamesOraFile); foreach (string line in lines) diff --git a/Helpers/HelperGenealogicalDataCommunication.cs b/Helpers/HelperGenealogicalDataCommunication.cs index cb97c5e..8285792 100644 --- a/Helpers/HelperGenealogicalDataCommunication.cs +++ b/Helpers/HelperGenealogicalDataCommunication.cs @@ -73,7 +73,7 @@ internal static partial class HelperGenealogicalDataCommunication private static ReadOnlyDictionary> Convert(Dictionary> keyValuePairs) { - Dictionary> results = new(); + Dictionary> results = []; foreach (KeyValuePair> keyValuePair in keyValuePairs) results.Add(keyValuePair.Key, new(keyValuePair.Value)); return new(results); @@ -81,7 +81,7 @@ internal static partial class HelperGenealogicalDataCommunication private static Dictionary>> Convert(Dictionary>> keyValuePairs) { - Dictionary>> results = new(); + Dictionary>> results = []; foreach (KeyValuePair>> keyValuePair in keyValuePairs) results.Add(keyValuePair.Key, new(keyValuePair.Value)); return new(results); @@ -91,13 +91,13 @@ internal static partial class HelperGenealogicalDataCommunication { List results; if (person is null) - results = new() { "Id", "First-Name", "Last-Name", "Birth-Date", "Sex", "Address", "City", "State", "Zip", "Phone", "E-mail", "Facebook", "Facebook-Id", "Comment", "U-Id" }; + results = ["Id", "First-Name", "Last-Name", "Birth-Date", "Sex", "Address", "City", "State", "Zip", "Phone", "E-mail", "Facebook", "Facebook-Id", "Comment", "U-Id"]; else { string? facebook = GetFaceBook(person); string? facebookId = GetFaceBookId(person); - results = new() - { + results = + [ person.Id.ToString(), string.Concat(person.Name?.Given), string.Concat(person.Name?.Sur), @@ -113,7 +113,7 @@ internal static partial class HelperGenealogicalDataCommunication string.Concat(facebookId), string.Empty, string.Concat(person.UId) - }; + ]; } return new(results); } @@ -122,7 +122,7 @@ internal static partial class HelperGenealogicalDataCommunication { string[] results; string key; - List<(string? Index, string Key)> collection = new(); + List<(string? Index, string Key)> collection = []; foreach (Family family in familyCollection) { if (family.Id is null) @@ -138,7 +138,7 @@ internal static partial class HelperGenealogicalDataCommunication private static Dictionary>> Convert(ReadOnlyCollection distinctSortedKKeys) { - Dictionary>> results = new(); + Dictionary>> results = []; ReadOnlyCollection collection; List>? objectCollection; foreach (string key in distinctSortedKKeys) @@ -147,7 +147,7 @@ internal static partial class HelperGenealogicalDataCommunication continue; if (!results.TryGetValue(key, out objectCollection)) { - results.Add(key, new()); + results.Add(key, []); if (!results.TryGetValue(key, out objectCollection)) throw new NotSupportedException(); } @@ -159,7 +159,7 @@ internal static partial class HelperGenealogicalDataCommunication private static ReadOnlyCollection GetHeaderLines(string startsWith, string[] sourceLines) { - List results = new(); + List results = []; for (int i = 0; i < sourceLines.Length; i++) { if (sourceLines[i].StartsWith(startsWith)) @@ -179,7 +179,7 @@ internal static partial class HelperGenealogicalDataCommunication private static Dictionary> GetTxtFileCollection(Input input) { - Dictionary> results = new(); + Dictionary> results = []; string[] lines; string[] directories; string directoryName; @@ -188,7 +188,7 @@ internal static partial class HelperGenealogicalDataCommunication List? collectionA; List? collectionB; string siblingDirectoryName; - string[] files = input.SingletonDirectory is null || !Directory.Exists(input.SingletonDirectory) ? Array.Empty() : Directory.GetFiles(input.SingletonDirectory, "*.txt", SearchOption.AllDirectories); + string[] files = input.SingletonDirectory is null || !Directory.Exists(input.SingletonDirectory) ? [] : Directory.GetFiles(input.SingletonDirectory, "*.txt", SearchOption.AllDirectories); foreach (string file in files) { sourceDirectory = Path.GetDirectoryName(file); @@ -203,7 +203,7 @@ internal static partial class HelperGenealogicalDataCommunication directoryName = Path.GetFileName(sourceDirectory); if (!results.TryGetValue(directoryName, out collectionA)) { - results.Add(directoryName, new()); + results.Add(directoryName, []); if (!results.TryGetValue(directoryName, out collectionA)) throw new Exception(); } @@ -219,7 +219,7 @@ internal static partial class HelperGenealogicalDataCommunication siblingDirectoryName = Path.GetFileName(directory); if (!results.TryGetValue(siblingDirectoryName, out collectionB)) { - results.Add(siblingDirectoryName, new()); + results.Add(siblingDirectoryName, []); if (!results.TryGetValue(siblingDirectoryName, out collectionB)) throw new Exception(); } @@ -270,8 +270,8 @@ internal static partial class HelperGenealogicalDataCommunication bool moreAdded = false; List? collection; DateOnly? dateOnly = null; - List distinct = new(); - List @continue = new(); + List distinct = []; + List @continue = []; for (int j = i + 1; j < lines.Count; j++) { if (lines[j][0] == '1') @@ -324,7 +324,7 @@ internal static partial class HelperGenealogicalDataCommunication string seven; string? note = null; DateOnly? dateOnly = null; - List @continue = new(); + List @continue = []; bool? isDead = lines[i].Length == 8 && lines[i][..8] == "1 DEAT Y" ? true : lines[i].Length == 8 && lines[i][..8] == "1 DEAT N" ? false : null; for (int j = i + 1; j < lines.Count; j++) { @@ -364,7 +364,7 @@ internal static partial class HelperGenealogicalDataCommunication string seven; string? note = null; DateOnly? dateOnly = null; - List @continue = new(); + List @continue = []; for (int j = i + 1; j < lines.Count; j++) { if (lines[j][0] == '1') @@ -399,11 +399,11 @@ internal static partial class HelperGenealogicalDataCommunication private static string[] GetNewLines(ReadOnlyCollection lines, Birth? birth) { - List results = new(); + List results = []; string six; string text; string seven; - List @continue = birth is null ? new() : birth.Continue.ToList(); + List @continue = birth is null ? [] : birth.Continue.ToList(); for (int i = 0; i < lines.Count; i++) { if (birth is null) @@ -447,7 +447,7 @@ internal static partial class HelperGenealogicalDataCommunication private static List GetIdsWhenPersonHasTitle(ReadOnlyDictionary people) { - List results = new(); + List results = []; foreach (KeyValuePair keyValuePair in people) { if (keyValuePair.Value.Title is null) @@ -459,7 +459,7 @@ internal static partial class HelperGenealogicalDataCommunication private static ReadOnlyCollection GetRelations(ReadOnlyCollection> familyGroupLines) { - List results = new(); + List results = []; int id; string relation; string[] segments; @@ -585,12 +585,12 @@ internal static partial class HelperGenealogicalDataCommunication { GenealogicalDataCommunicationCollections result; long? id; - List lines = new(); + List lines = []; + List footerLines = []; const string startsWith = "0 @"; - List footerLines = new(); - Dictionary> keyValuePairs = new(); - List> familyGroupLines = new(); - string[] sourceLines = string.IsNullOrEmpty(input.GenealogicalDataCommunicationFile) || !File.Exists(input.GenealogicalDataCommunicationFile) ? Array.Empty() : File.ReadAllLines(input.GenealogicalDataCommunicationFile); + Dictionary> keyValuePairs = []; + List> familyGroupLines = []; + string[] sourceLines = string.IsNullOrEmpty(input.GenealogicalDataCommunicationFile) || !File.Exists(input.GenealogicalDataCommunicationFile) ? [] : File.ReadAllLines(input.GenealogicalDataCommunicationFile); ReadOnlyCollection headerLines = GetHeaderLines(startsWith, sourceLines); for (int i = headerLines.Count; i < sourceLines.Length; i++) { @@ -632,7 +632,7 @@ internal static partial class HelperGenealogicalDataCommunication } if (id is null) throw new Exception(string.Join(Environment.NewLine, lines)); - keyValuePairs.Add(id.Value, new()); + keyValuePairs.Add(id.Value, []); if (lines.Count == 0) continue; keyValuePairs[id.Value].AddRange(lines); @@ -648,7 +648,7 @@ internal static partial class HelperGenealogicalDataCommunication private static ReadOnlyDictionary GetPeople(Input input, GenealogicalDataCommunicationCollections genealogicalDataCommunicationCollections) { - Dictionary results = new(); + Dictionary results = []; long? id; char? sex; Name? name; @@ -724,11 +724,11 @@ internal static partial class HelperGenealogicalDataCommunication Collections result; long personKey; char[] ageCollection; - Dictionary idToName = new(); - Dictionary idToPersonKey = new(); - Dictionary idToGivenName = new(); + List collection = []; + Dictionary idToName = []; + Dictionary idToPersonKey = []; + Dictionary idToGivenName = []; int length = appSettings.PersonBirthdayFormat.Length; - List collection = new(); foreach (KeyValuePair keyValuePair in people) { if (keyValuePair.Value.Birth?.Note is null) @@ -742,7 +742,7 @@ internal static partial class HelperGenealogicalDataCommunication personKey = dateTime.Ticks; idToPersonKey.Add(keyValuePair.Key, personKey); idToName.Add(keyValuePair.Key, WindowsFileSystem().Replace(keyValuePair.Value.Name.ForwardSlashFull, "_")); - ageCollection = keyValuePair.Value.Birth.Continue.Count == 0 ? Array.Empty() : keyValuePair.Value.Birth.Continue[0].ToArray(); + ageCollection = keyValuePair.Value.Birth.Continue.Count == 0 ? [] : keyValuePair.Value.Birth.Continue[0].ToArray(); idToGivenName.Add(keyValuePair.Key, string.IsNullOrEmpty(keyValuePair.Value.Name.Given) ? WindowsFileSystem().Replace(keyValuePair.Value.Name.ForwardSlashFull, "_") : WindowsFileSystem().Replace(keyValuePair.Value.Name.Given, "_")); collection.Add(new(keyValuePair.Key, new(keyValuePair.Value.Lines), keyValuePair.Value.Birth.Note, ageCollection, dateTime, personKey)); } @@ -752,7 +752,7 @@ internal static partial class HelperGenealogicalDataCommunication private static List GetFamilyCollection(ReadOnlyCollection> familyGroupLines, ReadOnlyDictionary people, ReadOnlyDictionary idToPersonKey, ReadOnlyDictionary idToName, ReadOnlyDictionary idToGivenName) { - List results = new(); + List results = []; string? name; long personKey; Person? person; @@ -862,8 +862,8 @@ internal static partial class HelperGenealogicalDataCommunication private static void WriteGenealogicalDataCommunicationCollections(ILogger logger, Input input, GenealogicalDataCommunicationCollections genealogicalDataCommunicationCollections, ReadOnlyDictionary people) { - List lines = new(); - List allLines = new(); + List lines = []; + List allLines = []; if (genealogicalDataCommunicationCollections.HeaderLines.Count > 0) { allLines.AddRange(genealogicalDataCommunicationCollections.HeaderLines); @@ -931,8 +931,8 @@ internal static partial class HelperGenealogicalDataCommunication long count = ticks; string rootDirectory; string approximateYears; - List distinct = new(); - List duplicates = new(); + List distinct = []; + List duplicates = []; string personDisplayDirectoryName; foreach (PersonExport personExport in personExportCollection) { @@ -1010,7 +1010,7 @@ internal static partial class HelperGenealogicalDataCommunication [Obsolete] private static string[] GetNewLines(ReadOnlyCollection lines, Name? name, string[] kFiles, string[] mFiles, string[] k2Files, string[] m2Files) { - List results = new(); + List results = []; string six; int? birthLastLine = null; string slugName = WindowsFileSystem().Replace(string.Concat(name?.ForwardSlashFull), "_"); diff --git a/Helpers/HelperHardcodedFileSearchAndSort.cs b/Helpers/HelperHardcodedFileSearchAndSort.cs index ae61dff..d11ebca 100644 --- a/Helpers/HelperHardcodedFileSearchAndSort.cs +++ b/Helpers/HelperHardcodedFileSearchAndSort.cs @@ -17,8 +17,8 @@ internal static class HelperHardcodedFileSearchAndSort string checkDirectory; CultureInfo cultureInfo = new("en-US"); Calendar calendar = cultureInfo.Calendar; - string[] hardcodedValues = new string[] - { + string[] hardcodedValues = + [ "BIORAD2", "BIORAD3", "BIORAD4", @@ -40,7 +40,7 @@ internal static class HelperHardcodedFileSearchAndSort "WC6Inch", "WC8Inch", "Bio-Rad" - }; + ]; string[] files = Directory.GetFiles(sourceDirectory, "*", searchOption); foreach (string file in files) { diff --git a/Helpers/HelperILMerge.cs b/Helpers/HelperILMerge.cs index 2f1933b..5aefda6 100644 --- a/Helpers/HelperILMerge.cs +++ b/Helpers/HelperILMerge.cs @@ -11,8 +11,8 @@ internal static class HelperILMerge bool result; ProcessStartInfo processStartInfo; StringBuilder stringBuilder = new(); - string[] successChecks = new string[] { "success" }; - string[] errorChecks = new string[] { "Error", "Conflict", "error:" }; + string[] successChecks = ["success"]; + string[] errorChecks = ["Error", "Conflict", "error:"]; FileInfo ilMerge = new("C:/Users/phares/AppData/Local/IFXApps/ILMerge/ILMerge.exe"); string[] dllFiles = Directory.GetFiles(workingDirectory, "*.dll", SearchOption.TopDirectoryOnly); string errorFile = Path.Combine(workingDirectory, string.Concat(Path.GetFileName(workingDirectory), ".err")); diff --git a/Helpers/HelperKanbanMetadata.cs b/Helpers/HelperKanbanMetadata.cs index 98e5eba..c68b54d 100644 --- a/Helpers/HelperKanbanMetadata.cs +++ b/Helpers/HelperKanbanMetadata.cs @@ -66,7 +66,7 @@ internal static partial class HelperKanbanMetadata private static List<(int, int, string, FileInfo)> GetCollectionFromIndex(string sourceDirectory, string[] lines) { - List<(int, int, string, FileInfo)> results = new(); + List<(int, int, string, FileInfo)> results = []; string line; FileInfo fileInfo; string[] segments; diff --git a/Helpers/HelperLogMerge.cs b/Helpers/HelperLogMerge.cs index 7c6e2b2..e242db3 100644 --- a/Helpers/HelperLogMerge.cs +++ b/Helpers/HelperLogMerge.cs @@ -13,14 +13,14 @@ internal static class HelperLogMerge FileInfo fileInfo; string[] segments; string checkDirectory; + List lines = []; string format = "yyyyMMdd"; + List moveFiles = []; string segment1 = string.Empty; string sourceFileNameWithoutExtension; - List lines = new(); - List moveFiles = new(); DateTime dateTime = DateTime.Now.AddMinutes(2); string[] sourceFiles = Directory.GetFiles(argsZero, "*.log", SearchOption.TopDirectoryOnly); - Dictionary> keyValuePairs = new(); + Dictionary> keyValuePairs = []; foreach (string sourceFile in sourceFiles) { sourceFileNameWithoutExtension = Path.GetFileNameWithoutExtension(sourceFile); @@ -33,7 +33,7 @@ internal static class HelperLogMerge moveFiles.Add(sourceFile); day = sourceFileNameWithoutExtension[..8]; if (!keyValuePairs.ContainsKey(day)) - keyValuePairs.Add(day, new Dictionary()); + keyValuePairs.Add(day, []); if (sourceFileNameWithoutExtension.Substring(8, 1) == "_") continue; segments = sourceFileNameWithoutExtension.Split('_'); diff --git a/Helpers/HelperMarkdown.cs b/Helpers/HelperMarkdown.cs index 5cd87f8..74ce318 100644 --- a/Helpers/HelperMarkdown.cs +++ b/Helpers/HelperMarkdown.cs @@ -71,7 +71,7 @@ internal static partial class HelperMarkdown private static List GetFrontMatterLines(string[] parsedLines) { - List results = new(); + List results = []; string afterTrim; string[] segments; StringBuilder stringBuilder = new(); @@ -153,8 +153,8 @@ internal static partial class HelperMarkdown private static List GetMarkdownFileAndLines(string file, List markdownFiles) { - List results = new(); - List distinct = new(); + List results = []; + List distinct = []; string? directory = Path.GetDirectoryName(file); foreach (MarkdownFileAndLines markdownFileAndLines in markdownFiles) { @@ -259,12 +259,12 @@ internal static partial class HelperMarkdown int notCompleted; List lines; string? effort = null; - List assignees = new(); + List assignees = []; string? requestedDateTime = null; ReadOnlyCollection groups; - List h2HexColors = new(); - List h2NoCheckboxes = new(); - List h2WithCheckboxes = new(); + List h2HexColors = []; + List h2NoCheckboxes = []; + List h2WithCheckboxes = []; if (markdownFileAndLines.MarkdownFile.LineNumber.FrontMatterYamlEnd is not null) { for (int i = 1; i < markdownFileAndLines.Lines.Length; i++) @@ -300,7 +300,7 @@ internal static partial class HelperMarkdown h2HexColors.Add(new(line[skip..], $"#{groups.First(l => l.Value.Length == 6)}")); continue; } - lines = new(); + lines = []; if (i + 1 == markdownFileAndLines.Lines.Length) continue; for (int j = i + 1; j < markdownFileAndLines.Lines.Length; j++) @@ -335,10 +335,10 @@ internal static partial class HelperMarkdown private static List Distinct(IEnumerable? markdownFileAndLinesCollection) { - List results = new(); + List results = []; if (markdownFileAndLinesCollection is not null) { - List distinct = new(); + List distinct = []; foreach (MarkdownFileAndLines markdownFileAndLines in markdownFileAndLinesCollection) { if (distinct.Contains(markdownFileAndLines.MarkdownFile.File)) @@ -352,7 +352,7 @@ internal static partial class HelperMarkdown private static List GetMarkdownFileAndLines(ReadOnlyDictionary> keyValuePairs) { - List results = new(); + List results = []; foreach (KeyValuePair> keyValuePair in keyValuePairs) { foreach (MarkdownFileAndLines markdownFileAndLines in keyValuePair.Value) @@ -370,7 +370,7 @@ internal static partial class HelperMarkdown string[] segmentsB; string segmentsLast; string segmentsFirst; - List jsonLines = new(); + List jsonLines = []; for (int i = 0; i < frontMatterYamlEnd; i++) { if (lines[i] == "---") @@ -430,13 +430,13 @@ internal static partial class HelperMarkdown if (jsonLines.Count > 0) (result, keyValuePairs, results) = Get(jsonLines); else - (result, keyValuePairs, results) = (null, null, new()); + (result, keyValuePairs, results) = (null, null, []); return (result, keyValuePairs, results.ToArray()); } private static ReadOnlyDictionary> GetKeyValuePairs(ReadOnlyDictionary relativeToCollection) { - Dictionary> results = new(); + Dictionary> results = []; MarkdownFile markdownFile; string fileNameWithoutExtension; string fileNameWithoutExtensionB; @@ -446,7 +446,7 @@ internal static partial class HelperMarkdown markdownFile = relativeTo.Value.MarkdownFile; if (!results.TryGetValue(relativeTo.Key, out markdownFiles)) { - results.Add(relativeTo.Key, new()); + results.Add(relativeTo.Key, []); if (!results.TryGetValue(relativeTo.Key, out markdownFiles)) throw new NotSupportedException(); } @@ -459,7 +459,7 @@ internal static partial class HelperMarkdown fileNameWithoutExtensionB = fileNameWithoutExtension.Replace("%20", "-").Replace(' ', '-'); if (!results.TryGetValue(markdownFile.FileNameWithoutExtension, out markdownFiles)) { - results.Add(markdownFile.FileNameWithoutExtension, new()); + results.Add(markdownFile.FileNameWithoutExtension, []); if (!results.TryGetValue(markdownFile.FileNameWithoutExtension, out markdownFiles)) throw new NotSupportedException(); } @@ -468,7 +468,7 @@ internal static partial class HelperMarkdown continue; if (!results.TryGetValue(fileNameWithoutExtension, out markdownFiles)) { - results.Add(fileNameWithoutExtension, new()); + results.Add(fileNameWithoutExtension, []); if (!results.TryGetValue(fileNameWithoutExtension, out markdownFiles)) throw new NotSupportedException(); } @@ -476,7 +476,7 @@ internal static partial class HelperMarkdown continue; if (!results.TryGetValue(fileNameWithoutExtensionB, out markdownFiles)) { - results.Add(fileNameWithoutExtensionB, new()); + results.Add(fileNameWithoutExtensionB, []); if (!results.TryGetValue(fileNameWithoutExtensionB, out markdownFiles)) throw new NotSupportedException(); } @@ -487,7 +487,7 @@ internal static partial class HelperMarkdown markdownFile = relativeTo.Value.MarkdownFile; if (!results.TryGetValue(markdownFile.H1, out markdownFiles)) { - results.Add(markdownFile.H1, new()); + results.Add(markdownFile.H1, []); if (!results.TryGetValue(markdownFile.H1, out markdownFiles)) throw new NotSupportedException(); } @@ -548,7 +548,7 @@ internal static partial class HelperMarkdown private static ReadOnlyDictionary GetRelativeToCollection(AppSettings appSettings, Input input, string[] files, bool force) { - Dictionary results = new(); + Dictionary results = []; string h1; string key; string type; @@ -571,7 +571,7 @@ internal static partial class HelperMarkdown else { type = appSettings.DefaultNoteType; - File.WriteAllLines(file, new string[] { "---", $"type: \"{type}\"", "---", string.Empty, $"# {h1}" }); + File.WriteAllLines(file, ["---", $"type: \"{type}\"", "---", string.Empty, $"# {h1}"]); lines = File.ReadAllLines(file).ToList(); } markdownFile = new(fileInfo.CreationTime, @@ -587,23 +587,23 @@ internal static partial class HelperMarkdown if (force || input.StartAt is null || file.StartsWith(input.StartAt)) results.Add(key, new(markdownFile, lines.ToArray())); else - results.Add(key, new(markdownFile, Array.Empty())); + results.Add(key, new(markdownFile, [])); } return new(results); } private static ReadOnlyDictionary> GetColumnsToCards(Input input, ReadOnlyDictionary relativeToCollection) { - Dictionary> results = new(); + Dictionary> results = []; Card card; string key; string[] lines; string[] segmentsA; string? column = null; - List cards = new(); + List cards = []; + List allKeys = []; MarkdownFile markdownFile; MarkdownExtra markdownExtra; - List allKeys = new(); MarkdownFileAndLines? markdownFileAndLines; foreach (KeyValuePair relativeTo in relativeToCollection) allKeys.Add(relativeTo.Key); @@ -626,7 +626,7 @@ internal static partial class HelperMarkdown if (column is null) throw new NullReferenceException(nameof(column)); results.Add(column, cards); - cards = new(); + cards = []; } column = lines[i][3..].TrimEnd(); if (lines.Length == i + 1) @@ -695,7 +695,7 @@ internal static partial class HelperMarkdown { column = "Not Linked"; results.Add(column, cards); - cards = new(); + cards = []; } } return new(results); @@ -714,7 +714,7 @@ internal static partial class HelperMarkdown else { List matches; - matches = markdownFileAndLinesCollection is null ? new() : GetMarkdownFileAndLines(file, markdownFileAndLinesCollection); + matches = markdownFileAndLinesCollection is null ? [] : GetMarkdownFileAndLines(file, markdownFileAndLinesCollection); if (matches.Count == 1) result = matches[0]; else @@ -793,7 +793,7 @@ internal static partial class HelperMarkdown private static int ConvertFrontMatterToJsonFriendly(ReadOnlyDictionary relativeToCollection) { int result = 0; - List results = new(); + List results = []; bool write; string[] lines; MarkdownFile markdownFile; @@ -1101,7 +1101,7 @@ internal static partial class HelperMarkdown private static List GetRecursiveLines(AppSettings appSettings, Input input, ILogger logger, ReadOnlyDictionary relativeToCollection) { - List results = new(); + List results = []; string[] lines; List indentations; MarkdownFile markdownFile; @@ -1113,8 +1113,8 @@ internal static partial class HelperMarkdown continue; if (input.StartAt is null || !relativeTo.Value.MarkdownFile.File.StartsWith(input.StartAt) || Path.GetFileName(relativeTo.Value.MarkdownFile.Directory) != Path.GetFileName(input.StartAt)) continue; - indentations = new(); - recursiveLines = new(); + indentations = []; + recursiveLines = []; lines = relativeTo.Value.Lines; markdownFile = relativeTo.Value.MarkdownFile; SetRecursiveLines(appSettings, logger, keyValuePairs, markdownFile.FileNameWithoutExtension, markdownFile, lines, indentations, recursiveLines); @@ -1153,7 +1153,7 @@ internal static partial class HelperMarkdown private static List GetWithLinksForHugo(AppSettings appSettings, Input input) { - List results = new(); + List results = []; string file; string line; string[] lines; @@ -1212,7 +1212,7 @@ internal static partial class HelperMarkdown private static List GetDistinct(List collection) { - List results = new(); + List results = []; foreach (Record record in collection) { if (results.Contains(record.Directory)) @@ -1278,7 +1278,7 @@ internal static partial class HelperMarkdown private static int SetFrontMatterAndH1(AppSettings appSettings, ReadOnlyDictionary relativeToCollection) { int result = 0; - List results = new(); + List results = []; string h1Line; string[] lines; string typeLine; diff --git a/Helpers/HelperPackageFilesByDate.cs b/Helpers/HelperPackageFilesByDate.cs index 55c4094..7229af4 100644 --- a/Helpers/HelperPackageFilesByDate.cs +++ b/Helpers/HelperPackageFilesByDate.cs @@ -17,9 +17,9 @@ internal static class HelperPackageFilesByDate PackageJson? packageJson; string[] packageJsonFiles; string? packageJsonDirectory; + List dateTimes = []; string fileNameWithoutExtension; string packageJsonDirectoryName; - List dateTimes = new(); if (log is null) throw new NullReferenceException(); if (!Directory.Exists(sourceDirectory)) diff --git a/Helpers/HelperPdfStripperWrapper.cs b/Helpers/HelperPdfStripperWrapper.cs index df6c352..127f379 100644 --- a/Helpers/HelperPdfStripperWrapper.cs +++ b/Helpers/HelperPdfStripperWrapper.cs @@ -113,7 +113,7 @@ internal static class HelperPdfStripperWrapper string[] lines; string fileName; string[] segments; - List collection = new(); + List collection = []; foreach (string file in files) { lines = File.ReadAllLines(file); diff --git a/Helpers/HelperRenameToOldMoveDeleteOld.cs b/Helpers/HelperRenameToOldMoveDeleteOld.cs index 7797a72..ea2b429 100644 --- a/Helpers/HelperRenameToOldMoveDeleteOld.cs +++ b/Helpers/HelperRenameToOldMoveDeleteOld.cs @@ -14,7 +14,7 @@ internal static class HelperRenameToOldMoveDeleteOldMerge { string renameFile; string destinationFile; - List deleteFiles = new(); + List deleteFiles = []; string[] moveFiles = Directory.GetFiles(argsZero, "*", SearchOption.TopDirectoryOnly); log.LogInformation("<{moveFiles.Length}> to move", moveFiles.Length); foreach (string moveFile in moveFiles) diff --git a/Helpers/HelperStart.cs b/Helpers/HelperStart.cs index 3cdb44e..6d6dcd7 100644 --- a/Helpers/HelperStart.cs +++ b/Helpers/HelperStart.cs @@ -48,7 +48,7 @@ internal static class HelperStart if (!result) result = standardOutput == string.Empty && standardError == string.Empty; if (!result) - File.WriteAllLines(errorFile, new string[] { standardOutput, Environment.NewLine, Environment.NewLine, standardError }); + File.WriteAllLines(errorFile, [standardOutput, Environment.NewLine, Environment.NewLine, standardError]); return result; } diff --git a/Helpers/HelperVSCodePossibleExtension.cs b/Helpers/HelperVSCodePossibleExtension.cs index 0b35f7c..da1b156 100644 --- a/Helpers/HelperVSCodePossibleExtension.cs +++ b/Helpers/HelperVSCodePossibleExtension.cs @@ -122,7 +122,7 @@ internal static partial class HelperVSCodePossibleExtension private static ReadOnlyCollection GetMethodLines(ReadOnlyCollection methods) { - List results = new(); + List results = []; foreach (Method method in methods) { for (int i = method.StartLine; i < method.EndLine + 1; i++) @@ -133,7 +133,7 @@ internal static partial class HelperVSCodePossibleExtension private static ReadOnlyCollection GetMethods(string cSharpFile, ILogger logger, string[] lines) { - List results = new(); + List results = []; int blocks; bool isLinq; int endLine; @@ -210,7 +210,7 @@ internal static partial class HelperVSCodePossibleExtension private static bool WriteAllLines(string cSharpFile, string[] lines, ReadOnlyCollection methods) { bool result; - List results = new(); + List results = []; ReadOnlyCollection methodLines = GetMethodLines(methods); int minMethodLines = methodLines.Min(); for (int i = 0; i < minMethodLines; i++) diff --git a/Helpers/HelperZipFilesBy.cs b/Helpers/HelperZipFilesBy.cs index e7053ab..d00dd70 100644 --- a/Helpers/HelperZipFilesBy.cs +++ b/Helpers/HelperZipFilesBy.cs @@ -11,29 +11,50 @@ internal static partial class HelperZipFilesBy [GeneratedRegex("[a-zA-Z0-9]{1,}")] private static partial Regex LowerAlphaAlphaAndNumber(); - private static bool SetDateFromZipEntry(ILogger logger, string[] zipFiles, string keyFile, string keyFileB, string keyFileC) + private static DateTimeOffset? GetDateTimeOffset(string keyFileExtension, FileInfo fileInfo, FileInfo extractKeyFileInfo) + { + DateTimeOffset? dateTimeOffset = null; + using ZipArchive zip = ZipFile.Open(fileInfo.FullName, ZipArchiveMode.Read); + foreach (ZipArchiveEntry zipArchiveEntry in zip.Entries) + { + if (!zipArchiveEntry.Name.EndsWith(keyFileExtension)) + continue; + dateTimeOffset = zipArchiveEntry.LastWriteTime; + if (fileInfo.FullName[0] != '\\') + { + zipArchiveEntry.ExtractToFile(extractKeyFileInfo.FullName); + File.SetCreationTime(extractKeyFileInfo.FullName, fileInfo.CreationTime); + File.SetLastWriteTime(extractKeyFileInfo.FullName, dateTimeOffset.Value.LocalDateTime); + } + break; + } + return dateTimeOffset; + } + + private static bool ExtractKeyFileAndSetDateFromZipEntry(ILogger logger, string[] zipFiles, string keyFileExtension, string keyFileExtensionB, string keyFileExtensionC) { bool result = false; string[] files; string checkFile; FileInfo fileInfo; - string? zipDirectory; + FileInfo extractKeyFileInfo; DateTimeOffset? dateTimeOffset; foreach (string zipFile in zipFiles) + { + fileInfo = new(zipFile); + if (fileInfo.DirectoryName is null) + throw new NullReferenceException(nameof(fileInfo.DirectoryName)); + extractKeyFileInfo = new(Path.Combine(fileInfo.DirectoryName, $"{Path.GetFileNameWithoutExtension(fileInfo.Name)}{keyFileExtension}")); + if (extractKeyFileInfo.Exists) + { + if (extractKeyFileInfo.CreationTime.ToString("yyyy-MM-dd") == fileInfo.CreationTime.ToString("yyyy-MM-dd") && extractKeyFileInfo.LastWriteTime.ToString("yyyy-MM-dd") == fileInfo.LastWriteTime.ToString("yyyy-MM-dd")) + continue; + File.Delete(extractKeyFileInfo.FullName); + } try { - dateTimeOffset = null; - fileInfo = new(zipFile); - using ZipArchive zip = ZipFile.Open(zipFile, ZipArchiveMode.Read); - foreach (ZipArchiveEntry zipArchiveEntry in zip.Entries) - { - if (!zipArchiveEntry.Name.EndsWith(keyFile)) - continue; - dateTimeOffset = zipArchiveEntry.LastWriteTime; - break; - } - zipDirectory = Path.GetDirectoryName(zipFile); - if (dateTimeOffset is null || zipDirectory is null) + dateTimeOffset = GetDateTimeOffset(keyFileExtension, fileInfo, extractKeyFileInfo); + if (dateTimeOffset is null) continue; if (fileInfo.LastWriteTime != dateTimeOffset.Value.LocalDateTime) { @@ -41,7 +62,9 @@ internal static partial class HelperZipFilesBy if (!result) result = true; } - files = Directory.GetFiles(zipDirectory, $"*{keyFile}", SearchOption.TopDirectoryOnly); + if (string.IsNullOrEmpty(keyFileExtensionB)) + continue; + files = Directory.GetFiles(fileInfo.DirectoryName, keyFileExtensionB, SearchOption.TopDirectoryOnly); foreach (string file in files) { fileInfo = new(file); @@ -52,22 +75,11 @@ internal static partial class HelperZipFilesBy result = true; } } - if (string.IsNullOrEmpty(keyFileB)) + if (string.IsNullOrEmpty(keyFileExtensionC)) continue; - files = Directory.GetFiles(zipDirectory, keyFileB, SearchOption.TopDirectoryOnly); - foreach (string file in files) - { - fileInfo = new(file); - if (fileInfo.LastWriteTime != dateTimeOffset.Value.LocalDateTime) - { - File.SetLastWriteTime(fileInfo.FullName, dateTimeOffset.Value.LocalDateTime); - if (!result) - result = true; - } - } - if (string.IsNullOrEmpty(keyFileC)) - continue; - files = Directory.GetFiles(zipDirectory, keyFileC, SearchOption.TopDirectoryOnly); + if (fileInfo.DirectoryName is null) + throw new NullReferenceException(nameof(fileInfo.DirectoryName)); + files = Directory.GetFiles(fileInfo.DirectoryName, keyFileExtensionC, SearchOption.TopDirectoryOnly); foreach (string file in files) { fileInfo = new(file); @@ -93,6 +105,7 @@ internal static partial class HelperZipFilesBy { File.Move(zipFile, checkFile); } catch (Exception) { logger.LogInformation("<{zipFile}> couldn't be moved!", zipFile); } } + } return result; } @@ -115,9 +128,9 @@ internal static partial class HelperZipFilesBy DateTime dateTime = DateTime.MinValue; DateTime firstEmail = new(2019, 3, 8); CultureInfo cultureInfo = new("en-US"); + Dictionary weeks = []; Calendar calendar = cultureInfo.Calendar; Regex regex = LowerAlphaAlphaAndNumber(); - Dictionary weeks = new(); int ticksLength = nowDateTime.AddDays(-6).Ticks.ToString().Length; for (int i = 0; i < int.MaxValue; i++) { @@ -131,10 +144,10 @@ internal static partial class HelperZipFilesBy } weekOfYear = calendar.GetWeekOfYear(nowDateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00"); string skipKey = string.Concat(nowDateTime.ToString("yyyy"), "_Week_", weekOfYear); - Dictionary> keyValuePairs = new(); + Dictionary> keyValuePairs = []; string[] topDirectories = Directory.GetDirectories(sourceDirectory, "*", SearchOption.TopDirectoryOnly); if (topDirectories.Length == 0) - topDirectories = new string[] { sourceDirectory }; + topDirectories = [sourceDirectory]; foreach (string topDirectory in topDirectories) { keyValuePairs.Clear(); @@ -187,7 +200,7 @@ internal static partial class HelperZipFilesBy if (key == skipKey) continue; if (!keyValuePairs.ContainsKey(key)) - keyValuePairs.Add(key, new List()); + keyValuePairs.Add(key, []); keyValuePairs[key].Add(subFile); } } @@ -237,30 +250,30 @@ internal static partial class HelperZipFilesBy return result; } - internal static bool SetDateFromZipEntryForNuspec(ILogger logger, string[] files) => - SetDateFromZipEntry(logger, files, ".nuspec", "icon", "readme"); + internal static bool ExportNuspecAndSetDateFromZipEntry(ILogger logger, string[] files) => + ExtractKeyFileAndSetDateFromZipEntry(logger, files, ".nuspec", "icon", "readme"); - internal static bool SetDateFromZipEntry(ILogger logger, string sourceDirectory, SearchOption searchOption = SearchOption.AllDirectories) + internal static bool ExtractKeyFileAndSetDateFromZipEntry(ILogger logger, string sourceDirectory, SearchOption searchOption = SearchOption.AllDirectories) { bool result = false; bool loop; - string keyFile; - string keyFileB; - string keyFileC; string[] zipFiles; string searchPattern; + string keyFileExtension; + string keyFileExtensionB; + string keyFileExtensionC; if (!Directory.Exists(sourceDirectory)) _ = Directory.CreateDirectory(sourceDirectory); for (int i = 1; i < 3; i++) { - (searchPattern, keyFile, keyFileB, keyFileC) = i switch + (searchPattern, keyFileExtension, keyFileExtensionB, keyFileExtensionC) = i switch { 1 => ("*.nupkg", ".nuspec", "icon", "readme"), 2 => ("*.vsix", ".vsixmanifest", string.Empty, string.Empty), _ => throw new NotSupportedException() }; zipFiles = Directory.GetFiles(sourceDirectory, searchPattern, searchOption); - loop = SetDateFromZipEntry(logger, zipFiles, keyFile, keyFileB, keyFileC); + loop = ExtractKeyFileAndSetDateFromZipEntry(logger, zipFiles, keyFileExtension, keyFileExtensionB, keyFileExtensionC); if (loop && !result) result = true; } diff --git a/Models/Binder/AppSettings.cs b/Models/Binder/AppSettings.cs index e4b9901..f03cb89 100644 --- a/Models/Binder/AppSettings.cs +++ b/Models/Binder/AppSettings.cs @@ -64,6 +64,7 @@ public class AppSettings continue; throw new NotSupportedException(physicalFileProvider.Root); } + throw new NotSupportedException("Not found!"); } result = Get(appSettings); return result; diff --git a/Worker.cs b/Worker.cs index f5eb006..33e8f13 100644 --- a/Worker.cs +++ b/Worker.cs @@ -24,8 +24,8 @@ public class Worker : BackgroundService _IsSilent = silentIndex > -1; if (_IsSilent) args.RemoveAt(silentIndex); - _ConsoleKeys = new ConsoleKey[] - { + _ConsoleKeys = + [ ConsoleKey.A, ConsoleKey.B, ConsoleKey.C, @@ -52,7 +52,7 @@ public class Worker : BackgroundService ConsoleKey.Y, ConsoleKey.Z, ConsoleKey.Delete - }; + ]; } public override Task StartAsync(CancellationToken cancellationToken) => @@ -174,7 +174,7 @@ public class Worker : BackgroundService Helpers.HelperRenameToOldMoveDeleteOldMerge.RenameToOldMoveDeleteOld(_Logger, _Args[0]); break; case ConsoleKey.S: - _ = Helpers.HelperZipFilesBy.SetDateFromZipEntry(_Logger, _Args[0]); + _ = Helpers.HelperZipFilesBy.ExtractKeyFileAndSetDateFromZipEntry(_Logger, _Args[0]); break; case ConsoleKey.T: Helpers.HelperTooLong.UpdateDateVerifyAndGetTicksDirectories(_Logger, _AppSettings, _Args[0]);