GetRecursiveLines only when
StartAt and Destination are supplied nuget-lower HelperGenealogicalDataCommunication
This commit is contained in:
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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))
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user