GetRecursiveLines only when
StartAt and Destination are supplied nuget-lower HelperGenealogicalDataCommunication
This commit is contained in:
parent
096262b2eb
commit
84cda2e57f
6
.vscode/tasks.json
vendored
6
.vscode/tasks.json
vendored
@ -121,6 +121,12 @@
|
|||||||
"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/net7.0/win-x64/publish/File-Folder-Helper.exe s S 'L:/BaGet/packages'",
|
||||||
"problemMatcher": []
|
"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",
|
||||||
|
"problemMatcher": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": "Kanbn Console",
|
"label": "Kanbn Console",
|
||||||
"type": "npm",
|
"type": "npm",
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<UserSecretsId>eb9e8f58-fcb5-45bb-9d4d-54f064c485b1</UserSecretsId>
|
<UserSecretsId>eb9e8f58-fcb5-45bb-9d4d-54f064c485b1</UserSecretsId>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="7.0.9" />
|
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler" Version="7.0.10" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.3" />
|
<PackageReference Include="System.Text.Json" Version="7.0.3" />
|
||||||
|
@ -63,6 +63,9 @@ internal static partial class HelperGenealogicalDataCommunication
|
|||||||
private static string? GetFaceBookId(Person person) =>
|
private static string? GetFaceBookId(Person person) =>
|
||||||
person.Birth?.Continue.Where(l => l.StartsWith("https://www.facebook.com/profile.php?id=")).Select(l => l[40..].Split('&')[0]).FirstOrDefault();
|
person.Birth?.Continue.Where(l => l.StartsWith("https://www.facebook.com/profile.php?id=")).Select(l => l[40..].Split('&')[0]).FirstOrDefault();
|
||||||
|
|
||||||
|
private static string GetKey(Family family) =>
|
||||||
|
$"{family.Id}-{family.Index}".Trim('-');
|
||||||
|
|
||||||
private static ReadOnlyDictionary<long, ReadOnlyCollection<string>> Convert(Dictionary<long, List<string>> keyValuePairs)
|
private static ReadOnlyDictionary<long, ReadOnlyCollection<string>> Convert(Dictionary<long, List<string>> keyValuePairs)
|
||||||
{
|
{
|
||||||
Dictionary<long, ReadOnlyCollection<string>> results = new();
|
Dictionary<long, ReadOnlyCollection<string>> results = new();
|
||||||
@ -110,29 +113,24 @@ internal static partial class HelperGenealogicalDataCommunication
|
|||||||
return new(results);
|
return new(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetKey(Family family) =>
|
private static ReadOnlyCollection<string> GetDistinctSortedKeys(List<Family> familyCollection, char personTitleFilter)
|
||||||
$"{family.Id}-{family.Index}".Trim('-');
|
|
||||||
|
|
||||||
private static ReadOnlyCollection<string> GetHeaderLines(string startsWith, string[] sourceLines)
|
|
||||||
{
|
{
|
||||||
List<string> results = new();
|
string[] results;
|
||||||
for (int i = 0; i < sourceLines.Length; i++)
|
string key;
|
||||||
|
List<(string? Index, string Key)> collection = new();
|
||||||
|
foreach (Family family in familyCollection)
|
||||||
{
|
{
|
||||||
if (sourceLines[i].StartsWith(startsWith))
|
if (family.Id is null)
|
||||||
break;
|
continue;
|
||||||
results.Add(sourceLines[i]);
|
if (string.IsNullOrEmpty(family.Title) || family.Title[0] != personTitleFilter)
|
||||||
|
continue;
|
||||||
|
key = GetKey(family);
|
||||||
|
collection.Add((family.Index, key));
|
||||||
}
|
}
|
||||||
|
results = (from l in collection orderby l.Key, l.Index?.Length descending select l.Key).Distinct().ToArray();
|
||||||
return new(results);
|
return new(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long? GetId(string line)
|
|
||||||
{
|
|
||||||
long? result;
|
|
||||||
string[] segments = line.Split('@');
|
|
||||||
result = segments[1].Length < 2 || !long.TryParse(segments[1][1..], out long idValue) ? null : idValue;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Dictionary<string, List<ReadOnlyCollection<string>>> Convert(ReadOnlyCollection<string> distinctSortedKKeys)
|
private static Dictionary<string, List<ReadOnlyCollection<string>>> Convert(ReadOnlyCollection<string> distinctSortedKKeys)
|
||||||
{
|
{
|
||||||
Dictionary<string, List<ReadOnlyCollection<string>>> results = new();
|
Dictionary<string, List<ReadOnlyCollection<string>>> results = new();
|
||||||
@ -154,6 +152,26 @@ internal static partial class HelperGenealogicalDataCommunication
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ReadOnlyCollection<string> GetHeaderLines(string startsWith, string[] sourceLines)
|
||||||
|
{
|
||||||
|
List<string> results = new();
|
||||||
|
for (int i = 0; i < sourceLines.Length; i++)
|
||||||
|
{
|
||||||
|
if (sourceLines[i].StartsWith(startsWith))
|
||||||
|
break;
|
||||||
|
results.Add(sourceLines[i]);
|
||||||
|
}
|
||||||
|
return new(results);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long? GetId(string line)
|
||||||
|
{
|
||||||
|
long? result;
|
||||||
|
string[] segments = line.Split('@');
|
||||||
|
result = segments[1].Length < 2 || !long.TryParse(segments[1][1..], out long idValue) ? null : idValue;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private static Dictionary<string, List<string>> GetTxtFileCollection(Input input)
|
private static Dictionary<string, List<string>> GetTxtFileCollection(Input input)
|
||||||
{
|
{
|
||||||
Dictionary<string, List<string>> results = new();
|
Dictionary<string, List<string>> results = new();
|
||||||
@ -455,21 +473,30 @@ internal static partial class HelperGenealogicalDataCommunication
|
|||||||
return new(results.OrderBy(l => l.FamilyIndex).ToArray());
|
return new(results.OrderBy(l => l.FamilyIndex).ToArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ReadOnlyCollection<string> GetDistinctSortedKeys(List<Family> familyCollection, char personTitleFilter)
|
private static ReadOnlyDictionary<string, ReadOnlyCollection<ReadOnlyCollection<string>>> GetKeyValuePairs(List<Family> familyCollection, char personTitleFilter)
|
||||||
{
|
{
|
||||||
string[] results;
|
Dictionary<string, ReadOnlyCollection<ReadOnlyCollection<string>>> results;
|
||||||
|
Dictionary<string, List<ReadOnlyCollection<string>>> keyValuePairs;
|
||||||
|
string id;
|
||||||
string key;
|
string key;
|
||||||
List<(string? Index, string Key)> collection = new();
|
ReadOnlyCollection<string> collection;
|
||||||
|
List<ReadOnlyCollection<string>>? objectCollection;
|
||||||
|
ReadOnlyCollection<string> distinctSortedKeys = GetDistinctSortedKeys(familyCollection, personTitleFilter);
|
||||||
|
keyValuePairs = Convert(distinctSortedKeys);
|
||||||
foreach (Family family in familyCollection)
|
foreach (Family family in familyCollection)
|
||||||
{
|
{
|
||||||
if (family.Id is null)
|
if (family.Id is null)
|
||||||
continue;
|
continue;
|
||||||
if (string.IsNullOrEmpty(family.Title) || family.Title[0] != personTitleFilter)
|
if (string.IsNullOrEmpty(family.Title) || family.Title[0] != personTitleFilter)
|
||||||
continue;
|
continue;
|
||||||
|
id = family.Person.Id.ToString();
|
||||||
key = GetKey(family);
|
key = GetKey(family);
|
||||||
collection.Add((family.Index, key));
|
if (!keyValuePairs.TryGetValue(key, out objectCollection))
|
||||||
|
throw new NotSupportedException();
|
||||||
|
collection = GetObjectCollection(family.Person);
|
||||||
|
objectCollection.Add(collection);
|
||||||
}
|
}
|
||||||
results = (from l in collection orderby l.Key, l.Index?.Length descending select l.Key).Distinct().ToArray();
|
results = Convert(keyValuePairs);
|
||||||
return new(results);
|
return new(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -799,33 +826,6 @@ internal static partial class HelperGenealogicalDataCommunication
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ReadOnlyDictionary<string, ReadOnlyCollection<ReadOnlyCollection<string>>> GetKeyValuePairs(List<Family> familyCollection, char personTitleFilter)
|
|
||||||
{
|
|
||||||
Dictionary<string, ReadOnlyCollection<ReadOnlyCollection<string>>> results;
|
|
||||||
Dictionary<string, List<ReadOnlyCollection<string>>> keyValuePairs;
|
|
||||||
string id;
|
|
||||||
string key;
|
|
||||||
ReadOnlyCollection<string> collection;
|
|
||||||
List<ReadOnlyCollection<string>>? objectCollection;
|
|
||||||
ReadOnlyCollection<string> distinctSortedKeys = GetDistinctSortedKeys(familyCollection, personTitleFilter);
|
|
||||||
keyValuePairs = Convert(distinctSortedKeys);
|
|
||||||
foreach (Family family in familyCollection)
|
|
||||||
{
|
|
||||||
if (family.Id is null)
|
|
||||||
continue;
|
|
||||||
if (string.IsNullOrEmpty(family.Title) || family.Title[0] != personTitleFilter)
|
|
||||||
continue;
|
|
||||||
id = family.Person.Id.ToString();
|
|
||||||
key = GetKey(family);
|
|
||||||
if (!keyValuePairs.TryGetValue(key, out objectCollection))
|
|
||||||
throw new NotSupportedException();
|
|
||||||
collection = GetObjectCollection(family.Person);
|
|
||||||
objectCollection.Add(collection);
|
|
||||||
}
|
|
||||||
results = Convert(keyValuePairs);
|
|
||||||
return new(results);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void WriteJsonFiles(AppSettings appSettings, Input input, GenealogicalDataCommunicationCollections genealogicalDataCommunicationCollections, ReadOnlyDictionary<long, Person> people, List<Family> familyCollection)
|
private static void WriteJsonFiles(AppSettings appSettings, Input input, GenealogicalDataCommunicationCollections genealogicalDataCommunicationCollections, ReadOnlyDictionary<long, Person> people, List<Family> familyCollection)
|
||||||
{
|
{
|
||||||
string json;
|
string json;
|
||||||
|
@ -14,6 +14,18 @@ internal static partial class HelperKanbanMetadata
|
|||||||
[GeneratedRegex("[\\s!?.,@:;|\\\\/\"'`£$%\\^&*{}[\\]()<>~#+\\-=_¬]+")]
|
[GeneratedRegex("[\\s!?.,@:;|\\\\/\"'`£$%\\^&*{}[\\]()<>~#+\\-=_¬]+")]
|
||||||
private static partial Regex InvalidCharacter();
|
private static partial Regex InvalidCharacter();
|
||||||
|
|
||||||
|
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 void TestParamCases()
|
private static void TestParamCases()
|
||||||
{
|
{
|
||||||
if (GetParamCase("PascalCase") != "pascal-case")
|
if (GetParamCase("PascalCase") != "pascal-case")
|
||||||
@ -84,18 +96,6 @@ internal static partial class HelperKanbanMetadata
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static void SetMetadata(ILogger log, AppSettings appSettings, string sourceDirectory)
|
internal static void SetMetadata(ILogger log, AppSettings appSettings, string sourceDirectory)
|
||||||
{
|
{
|
||||||
bool? match;
|
bool? match;
|
||||||
|
@ -1155,11 +1155,10 @@ internal static partial class HelperMarkdown
|
|||||||
relativeToCollection = GetRelativeToCollection(appSettings, input);
|
relativeToCollection = GetRelativeToCollection(appSettings, input);
|
||||||
logger.LogInformation("{updated} Markdown file(s) were updated", updated);
|
logger.LogInformation("{updated} Markdown file(s) were updated", updated);
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(input.StartAt))
|
if (!string.IsNullOrEmpty(input.StartAt) && !string.IsNullOrEmpty(input.Destination))
|
||||||
{
|
{
|
||||||
relativeToCollection = GetRelativeToCollection(appSettings, input, force: true);
|
relativeToCollection = GetRelativeToCollection(appSettings, input, force: true);
|
||||||
List<MarkdownFileAndLines> markdownFileAndLinesCollection = GetRecursiveLines(appSettings, input, logger, relativeToCollection);
|
List<MarkdownFileAndLines> markdownFileAndLinesCollection = GetRecursiveLines(appSettings, input, logger, relativeToCollection);
|
||||||
if (!string.IsNullOrEmpty(input.Destination))
|
|
||||||
Write(input, markdownFileAndLinesCollection);
|
Write(input, markdownFileAndLinesCollection);
|
||||||
}
|
}
|
||||||
string directory = Path.Combine(Environment.CurrentDirectory, ".vscode");
|
string directory = Path.Combine(Environment.CurrentDirectory, ".vscode");
|
||||||
|
@ -223,4 +223,20 @@ internal static class HelperSaveOrCopyContents
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void IgnoreCaseAndRenameFilesToLowercase(ILogger log, string argsZero)
|
||||||
|
{
|
||||||
|
string fileName;
|
||||||
|
int filesRenamed = 0;
|
||||||
|
string[] files = Directory.GetFiles(argsZero, "*", SearchOption.TopDirectoryOnly);
|
||||||
|
foreach (string file in files)
|
||||||
|
{
|
||||||
|
fileName = Path.GetFileName(file);
|
||||||
|
if (fileName == fileName.ToLower())
|
||||||
|
continue;
|
||||||
|
File.Move(file, file.ToLower());
|
||||||
|
filesRenamed++;
|
||||||
|
}
|
||||||
|
log.LogInformation("{filesRenamed}(s) renamed", filesRenamed);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
20
Worker.cs
20
Worker.cs
@ -34,6 +34,7 @@ public class Worker : BackgroundService
|
|||||||
ConsoleKey.F,
|
ConsoleKey.F,
|
||||||
ConsoleKey.G,
|
ConsoleKey.G,
|
||||||
ConsoleKey.H,
|
ConsoleKey.H,
|
||||||
|
ConsoleKey.I,
|
||||||
ConsoleKey.J,
|
ConsoleKey.J,
|
||||||
ConsoleKey.K,
|
ConsoleKey.K,
|
||||||
ConsoleKey.L,
|
ConsoleKey.L,
|
||||||
@ -95,20 +96,20 @@ public class Worker : BackgroundService
|
|||||||
_Logger.LogInformation("F) Clipboard (All Directories and File Name Without Extension),");
|
_Logger.LogInformation("F) Clipboard (All Directories and File Name Without Extension),");
|
||||||
_Logger.LogInformation("G) Genealogical Data Communication");
|
_Logger.LogInformation("G) Genealogical Data Communication");
|
||||||
_Logger.LogInformation("H) Hardcoded file search and sort,");
|
_Logger.LogInformation("H) Hardcoded file search and sort,");
|
||||||
// I
|
_Logger.LogInformation("I) Ignore case and rename files to lowercase,");
|
||||||
_Logger.LogInformation("J) Set Date from Json Entry");
|
_Logger.LogInformation("J) Set Date from Json Entry,");
|
||||||
_Logger.LogInformation("K) Kanban support");
|
_Logger.LogInformation("K) Kanban support,");
|
||||||
_Logger.LogInformation("L) Log Merge (APC Log [0-9(8)]_*.log),");
|
_Logger.LogInformation("L) Log Merge (APC Log [0-9(8)]_*.log),");
|
||||||
_Logger.LogInformation("N) Create Note Files,");
|
_Logger.LogInformation("N) Create Note Files,");
|
||||||
_Logger.LogInformation("M) Markdown Wiki Link Verification,");
|
_Logger.LogInformation("M) Markdown Wiki Link Verification,");
|
||||||
// O
|
// O
|
||||||
// P
|
// P
|
||||||
// Q
|
// Q
|
||||||
_Logger.LogInformation("R) Rename to old, copy, delete old");
|
_Logger.LogInformation("R) Rename to old, copy, delete old,");
|
||||||
_Logger.LogInformation("S) Set Date from Zip Entry");
|
_Logger.LogInformation("S) Set Date from Zip Entry,");
|
||||||
_Logger.LogInformation("T) Too long rename");
|
_Logger.LogInformation("T) Too long rename,");
|
||||||
_Logger.LogInformation("U) Links for Hugo");
|
_Logger.LogInformation("U) Links for Hugo,");
|
||||||
_Logger.LogInformation("V) VSCode Hope Sort");
|
_Logger.LogInformation("V) VSCode Hope Sort,");
|
||||||
// W
|
// W
|
||||||
// X
|
// X
|
||||||
// Y
|
// Y
|
||||||
@ -132,6 +133,9 @@ public class Worker : BackgroundService
|
|||||||
case ConsoleKey.H:
|
case ConsoleKey.H:
|
||||||
Helpers.HelperHardcodedFileSearchAndSort.HardcodedFileSearchAndSort(_Logger, _Args[0]);
|
Helpers.HelperHardcodedFileSearchAndSort.HardcodedFileSearchAndSort(_Logger, _Args[0]);
|
||||||
break;
|
break;
|
||||||
|
case ConsoleKey.I:
|
||||||
|
Helpers.HelperSaveOrCopyContents.IgnoreCaseAndRenameFilesToLowercase(_Logger, _Args[0]);
|
||||||
|
break;
|
||||||
case ConsoleKey.J:
|
case ConsoleKey.J:
|
||||||
Helpers.HelperPackageFilesByDate.SetDateFromJsonEntry(_Logger, _Args[0]);
|
Helpers.HelperPackageFilesByDate.SetDateFromJsonEntry(_Logger, _Args[0]);
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user