GetRecursiveLines only when

StartAt and Destination are supplied
nuget-lower
HelperGenealogicalDataCommunication
This commit is contained in:
Mike Phares 2023-08-31 08:31:10 -07:00
parent 096262b2eb
commit 84cda2e57f
7 changed files with 98 additions and 73 deletions

6
.vscode/tasks.json vendored
View File

@ -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'",
"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",
"type": "npm",

View File

@ -9,7 +9,7 @@
<UserSecretsId>eb9e8f58-fcb5-45bb-9d4d-54f064c485b1</UserSecretsId>
</PropertyGroup>
<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.Logging.Console" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.3" />

View File

@ -63,6 +63,9 @@ internal static partial class HelperGenealogicalDataCommunication
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();
private static string GetKey(Family family) =>
$"{family.Id}-{family.Index}".Trim('-');
private static ReadOnlyDictionary<long, ReadOnlyCollection<string>> Convert(Dictionary<long, List<string>> keyValuePairs)
{
Dictionary<long, ReadOnlyCollection<string>> results = new();
@ -110,29 +113,24 @@ internal static partial class HelperGenealogicalDataCommunication
return new(results);
}
private static string GetKey(Family family) =>
$"{family.Id}-{family.Index}".Trim('-');
private static ReadOnlyCollection<string> GetHeaderLines(string startsWith, string[] sourceLines)
private static ReadOnlyCollection<string> GetDistinctSortedKeys(List<Family> familyCollection, char personTitleFilter)
{
List<string> results = new();
for (int i = 0; i < sourceLines.Length; i++)
string[] results;
string key;
List<(string? Index, string Key)> collection = new();
foreach (Family family in familyCollection)
{
if (sourceLines[i].StartsWith(startsWith))
break;
results.Add(sourceLines[i]);
if (family.Id is null)
continue;
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);
}
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)
{
Dictionary<string, List<ReadOnlyCollection<string>>> results = new();
@ -154,6 +152,26 @@ internal static partial class HelperGenealogicalDataCommunication
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)
{
Dictionary<string, List<string>> results = new();
@ -455,21 +473,30 @@ internal static partial class HelperGenealogicalDataCommunication
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;
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)
{
if (family.Id is null)
continue;
if (string.IsNullOrEmpty(family.Title) || family.Title[0] != personTitleFilter)
continue;
id = family.Person.Id.ToString();
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);
}
@ -799,33 +826,6 @@ internal static partial class HelperGenealogicalDataCommunication
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)
{
string json;

View File

@ -14,6 +14,18 @@ internal static partial class HelperKanbanMetadata
[GeneratedRegex("[\\s!?.,@:;|\\\\/\"'`£$%\\^&*{}[\\]()<>~#+\\-=_¬]+")]
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()
{
if (GetParamCase("PascalCase") != "pascal-case")
@ -84,18 +96,6 @@ internal static partial class HelperKanbanMetadata
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)
{
bool? match;

View File

@ -1155,12 +1155,11 @@ internal static partial class HelperMarkdown
relativeToCollection = GetRelativeToCollection(appSettings, input);
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);
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");
if (!Directory.Exists(directory))

View File

@ -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);
}
}

View File

@ -34,6 +34,7 @@ public class Worker : BackgroundService
ConsoleKey.F,
ConsoleKey.G,
ConsoleKey.H,
ConsoleKey.I,
ConsoleKey.J,
ConsoleKey.K,
ConsoleKey.L,
@ -95,20 +96,20 @@ public class Worker : BackgroundService
_Logger.LogInformation("F) Clipboard (All Directories and File Name Without Extension),");
_Logger.LogInformation("G) Genealogical Data Communication");
_Logger.LogInformation("H) Hardcoded file search and sort,");
// I
_Logger.LogInformation("J) Set Date from Json Entry");
_Logger.LogInformation("K) Kanban support");
_Logger.LogInformation("I) Ignore case and rename files to lowercase,");
_Logger.LogInformation("J) Set Date from Json Entry,");
_Logger.LogInformation("K) Kanban support,");
_Logger.LogInformation("L) Log Merge (APC Log [0-9(8)]_*.log),");
_Logger.LogInformation("N) Create Note Files,");
_Logger.LogInformation("M) Markdown Wiki Link Verification,");
// O
// P
// Q
_Logger.LogInformation("R) Rename to old, copy, delete old");
_Logger.LogInformation("S) Set Date from Zip Entry");
_Logger.LogInformation("T) Too long rename");
_Logger.LogInformation("U) Links for Hugo");
_Logger.LogInformation("V) VSCode Hope Sort");
_Logger.LogInformation("R) Rename to old, copy, delete old,");
_Logger.LogInformation("S) Set Date from Zip Entry,");
_Logger.LogInformation("T) Too long rename,");
_Logger.LogInformation("U) Links for Hugo,");
_Logger.LogInformation("V) VSCode Hope Sort,");
// W
// X
// Y
@ -132,6 +133,9 @@ public class Worker : BackgroundService
case ConsoleKey.H:
Helpers.HelperHardcodedFileSearchAndSort.HardcodedFileSearchAndSort(_Logger, _Args[0]);
break;
case ConsoleKey.I:
Helpers.HelperSaveOrCopyContents.IgnoreCaseAndRenameFilesToLowercase(_Logger, _Args[0]);
break;
case ConsoleKey.J:
Helpers.HelperPackageFilesByDate.SetDateFromJsonEntry(_Logger, _Args[0]);
break;