SaveParents
Removed GetFilteredOutMapped Removed GetNonSpecificPeopleCollection
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
@ -20,13 +23,16 @@ internal abstract class GenealogicalDataCommunication
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
private static List<GenealogicalDataCommunicationRelation> GetRelations(Dictionary<string, string> idToNick, List<string[]> familyGroupLines)
|
||||
private static List<GenealogicalDataCommunicationRelation> GetRelations(string personBirthdayFormat, ReadOnlyDictionary<string, string> personKeyFormattedToPersonFullName, Dictionary<string, string> idToNick, List<string[]> familyGroupLines)
|
||||
{
|
||||
List<GenealogicalDataCommunicationRelation> results = new();
|
||||
string? nick;
|
||||
long? personKey;
|
||||
string relation;
|
||||
string? fullName;
|
||||
string[] segments;
|
||||
string[] familyLines;
|
||||
Models.PersonBirthday? personBirthday;
|
||||
for (int i = 0; i < familyGroupLines.Count; i++)
|
||||
{
|
||||
familyLines = familyGroupLines[i];
|
||||
@ -38,10 +44,13 @@ internal abstract class GenealogicalDataCommunication
|
||||
if (!idToNick.TryGetValue(segments[1], out nick))
|
||||
continue;
|
||||
relation = segments.First()[2..].Trim();
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(personBirthdayFormat, nick);
|
||||
personKey = personBirthday?.Value.Ticks;
|
||||
fullName = personKeyFormattedToPersonFullName.GetValueOrDefault(nick);
|
||||
if (j + 1 >= familyLines.Length || familyLines[j + 1].Length < 3 || familyLines[j + 1][..3] != "2 _")
|
||||
results.Add(new(i, relation, segments[1], nick, null));
|
||||
results.Add(new(i, relation, segments[1], nick, personKey, fullName, null));
|
||||
else
|
||||
results.Add(new(i, relation, segments[1], nick, familyLines[j + 1][2..]));
|
||||
results.Add(new(i, relation, segments[1], nick, personKey, fullName, familyLines[j + 1][2..]));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
@ -55,7 +64,7 @@ internal abstract class GenealogicalDataCommunication
|
||||
return new(results);
|
||||
}
|
||||
|
||||
internal static (string[], ReadOnlyDictionary<string, string[]>, List<string[]>, string[], List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations) GetIndividuals(string genealogicalDataCommunicationFile, bool requireNickName)
|
||||
internal static (string[], ReadOnlyDictionary<string, string[]>, List<string[]>, string[], List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations) GetIndividuals(string personBirthdayFormat, string genealogicalDataCommunicationFile, ReadOnlyCollection<Models.PersonContainer> personContainers, bool requireNickName)
|
||||
{
|
||||
ReadOnlyDictionary<string, string[]> results;
|
||||
string? nick;
|
||||
@ -66,6 +75,7 @@ internal abstract class GenealogicalDataCommunication
|
||||
List<string[]> familyGroupLines = new();
|
||||
Dictionary<string, string> idToNick = new();
|
||||
Dictionary<string, List<string>> keyValuePairs = new();
|
||||
ReadOnlyDictionary<string, string> personKeyFormattedToPersonFullName = IPersonContainer.GetPersonKeyFormattedToPersonFullName(personBirthdayFormat, personContainers);
|
||||
string[] sourceLines = string.IsNullOrEmpty(genealogicalDataCommunicationFile) || !File.Exists(genealogicalDataCommunicationFile) ? Array.Empty<string>() : File.ReadAllLines(genealogicalDataCommunicationFile);
|
||||
string[] headerLines = GetHeaderLines(startsWith, sourceLines);
|
||||
for (int i = headerLines.Length; i < sourceLines.Length; i++)
|
||||
@ -125,60 +135,16 @@ internal abstract class GenealogicalDataCommunication
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
results = Convert(keyValuePairs);
|
||||
List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations = GetRelations(idToNick, familyGroupLines);
|
||||
List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations = GetRelations(personBirthdayFormat, personKeyFormattedToPersonFullName, idToNick, familyGroupLines);
|
||||
return (headerLines, results, familyGroupLines, footerLines.ToArray(), genealogicalDataCommunicationRelations);
|
||||
}
|
||||
|
||||
private static string[] GetFilteredOutMapped(string[] individualsLines)
|
||||
{
|
||||
List<string> results = new();
|
||||
for (int i = 0; i < individualsLines.Length; i++)
|
||||
{
|
||||
if (individualsLines[i].StartsWith("0 @I"))
|
||||
continue;
|
||||
else if (individualsLines[i].StartsWith("1 _UID"))
|
||||
continue;
|
||||
else if (individualsLines[i].StartsWith("1 NAME"))
|
||||
continue;
|
||||
else if (individualsLines[i].StartsWith("2 GIVN"))
|
||||
continue;
|
||||
else if (individualsLines[i].StartsWith("2 SURN"))
|
||||
continue;
|
||||
else if (individualsLines[i].StartsWith("2 NSFX"))
|
||||
continue;
|
||||
else if (individualsLines[i].StartsWith("2 NICK"))
|
||||
continue;
|
||||
else if (individualsLines[i].StartsWith("1 SEX"))
|
||||
continue;
|
||||
else if (individualsLines[i] == "1 BIRT")
|
||||
{
|
||||
if (individualsLines.Length > i + 1 && individualsLines[i + 1].StartsWith("2 DATE"))
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
else if (individualsLines[i].StartsWith("1 DEAT"))
|
||||
{
|
||||
if (individualsLines.Length > i + 1 && individualsLines[i + 1].StartsWith("2 DATE"))
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
else if (individualsLines[i] == "1 CHAN")
|
||||
{
|
||||
if (individualsLines.Length > i + 1 && individualsLines[i + 1].StartsWith("2 DATE"))
|
||||
i += 1;
|
||||
continue;
|
||||
}
|
||||
results.Add(individualsLines[i]);
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
internal static List<string> GetMappedLines(string genealogicalDataCommunicationFile, bool requireNickName)
|
||||
internal static List<string> GetMappedLines(string personBirthdayFormat, string genealogicalDataCommunicationFile, ReadOnlyCollection<Models.PersonContainer> personContainers, bool requireNickName)
|
||||
{
|
||||
List<string> results = new();
|
||||
Models.PersonBirthday personBirthday = new(DateTime.Now);
|
||||
GenealogicalDataCommunicationLines genealogicalDataCommunicationLines;
|
||||
(string[] headerLines, ReadOnlyDictionary<string, string[]> individuals, List<string[]> familyGroupLines, string[] footerLines, _) = GetIndividuals(genealogicalDataCommunicationFile, requireNickName);
|
||||
(string[] headerLines, ReadOnlyDictionary<string, string[]> individuals, List<string[]> familyGroupLines, string[] footerLines, _) = GetIndividuals(personBirthdayFormat, genealogicalDataCommunicationFile, personContainers, requireNickName);
|
||||
results.AddRange(headerLines);
|
||||
foreach (KeyValuePair<string, string[]> keyValuePair in individuals)
|
||||
{
|
||||
@ -335,9 +301,10 @@ internal abstract class GenealogicalDataCommunication
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static bool CleanDisplayDirectoryAllFilesAndWriteTicksGed(string mappingDefaultName, string personBirthdayFormat, List<Models.PersonContainer> personContainers, string[] headerLines, List<string[]> familyGroupLines, string[] footerLines, long ticks, string a2PeopleContentDirectory)
|
||||
internal static bool CleanDisplayDirectoryAllFilesAndWriteTicksGed(string mappingDefaultName, string personBirthdayFormat, ReadOnlyCollection<Models.PersonContainer> personContainers, string[] headerLines, List<string[]> familyGroupLines, string[] footerLines, long ticks, string a2PeopleContentDirectory)
|
||||
{
|
||||
bool result = false;
|
||||
string directory;
|
||||
string[] mdFiles;
|
||||
string[] txtFiles;
|
||||
const int zero = 0;
|
||||
@ -411,8 +378,218 @@ internal abstract class GenealogicalDataCommunication
|
||||
for (int i = 0; i < familyGroupLines.Count; i++)
|
||||
lines.AddRange(familyGroupLines[i]);
|
||||
lines.AddRange(footerLines);
|
||||
File.WriteAllLines(Path.Combine(a2PeopleContentDirectory, $"{dateTime.Year}-GenealogicalDataCommunication", $"{dateTime.Year}-Week-{weekOfYear}", $"{ticks}.ged"), lines);
|
||||
directory = Path.Combine(a2PeopleContentDirectory, $"{dateTime.Year}-GenealogicalDataCommunication", $"{dateTime.Year}-Week-{weekOfYear}");
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
File.WriteAllLines(Path.Combine(directory, $"{ticks}.ged"), lines);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> GetFamilyIndexToCollection(List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations)
|
||||
{
|
||||
Dictionary<int, List<GenealogicalDataCommunicationRelation>> results = new();
|
||||
List<GenealogicalDataCommunicationRelation>? relations;
|
||||
foreach (GenealogicalDataCommunicationRelation genealogicalDataCommunicationRelation in genealogicalDataCommunicationRelations)
|
||||
{
|
||||
if (!results.TryGetValue(genealogicalDataCommunicationRelation.FamilyIndex, out relations))
|
||||
{
|
||||
results.Add(genealogicalDataCommunicationRelation.FamilyIndex, new());
|
||||
if (!results.TryGetValue(genealogicalDataCommunicationRelation.FamilyIndex, out relations))
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
relations.Add(genealogicalDataCommunicationRelation);
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
internal static ReadOnlyDictionary<long, List<GenealogicalDataCommunicationRelation>> GetCollection(string personBirthdayFormat, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations)
|
||||
{
|
||||
Dictionary<long, List<GenealogicalDataCommunicationRelation>> results = new();
|
||||
long personKey;
|
||||
string personKeyFormatted;
|
||||
Models.PersonBirthday? personBirthday;
|
||||
List<GenealogicalDataCommunicationRelation>? collection;
|
||||
foreach (GenealogicalDataCommunicationRelation genealogicalDataCommunicationRelation in genealogicalDataCommunicationRelations)
|
||||
{
|
||||
personKeyFormatted = genealogicalDataCommunicationRelation.NickName;
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(personBirthdayFormat, personKeyFormatted);
|
||||
if (personBirthday is null)
|
||||
continue;
|
||||
personKey = personBirthday.Value.Ticks;
|
||||
if (!results.TryGetValue(personKey, out collection))
|
||||
{
|
||||
results.Add(personKey, new());
|
||||
if (!results.TryGetValue(personKey, out collection))
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
collection.Add(genealogicalDataCommunicationRelation);
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
internal static ReadOnlyDictionary<long, List<GenealogicalDataCommunicationRelation>> GetCollection(string personBirthdayFormat, ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection)
|
||||
{
|
||||
Dictionary<long, List<GenealogicalDataCommunicationRelation>> results = new();
|
||||
long personKey;
|
||||
string personKeyFormatted;
|
||||
Models.PersonBirthday? personBirthday;
|
||||
List<GenealogicalDataCommunicationRelation>? collection;
|
||||
foreach (KeyValuePair<int, List<GenealogicalDataCommunicationRelation>> keyValuePair in familyIndexToCollection)
|
||||
{
|
||||
foreach (GenealogicalDataCommunicationRelation genealogicalDataCommunicationRelation in keyValuePair.Value)
|
||||
{
|
||||
personKeyFormatted = genealogicalDataCommunicationRelation.NickName;
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(personBirthdayFormat, personKeyFormatted);
|
||||
if (personBirthday is null)
|
||||
continue;
|
||||
personKey = personBirthday.Value.Ticks;
|
||||
if (!results.TryGetValue(personKey, out collection))
|
||||
{
|
||||
results.Add(personKey, new());
|
||||
if (!results.TryGetValue(personKey, out collection))
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
collection.Add(genealogicalDataCommunicationRelation);
|
||||
}
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
internal static string GetMergeWithLineTwo(GenealogicalDataCommunicationRelation genealogicalDataCommunicationRelation, GenealogicalDataCommunicationRelation relation)
|
||||
{
|
||||
string result;
|
||||
const char father = 'F';
|
||||
const char mother = 'M';
|
||||
string wife = IGenealogicalDataCommunication.Wife;
|
||||
string husband = IGenealogicalDataCommunication.Husband;
|
||||
if (string.IsNullOrEmpty(genealogicalDataCommunicationRelation.LineTwo))
|
||||
{
|
||||
if (relation.Relation == wife)
|
||||
result = nameof(mother);
|
||||
else if (relation.Relation == husband)
|
||||
result = nameof(father);
|
||||
else
|
||||
result = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuilder stringBuilder = new();
|
||||
if (genealogicalDataCommunicationRelation.LineTwo[1] == father)
|
||||
{
|
||||
if (relation.Relation == wife)
|
||||
_ = stringBuilder.Append(nameof(mother));
|
||||
else if (relation.Relation == husband)
|
||||
_ = stringBuilder.Append(genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()).Append(' ').Append(nameof(father));
|
||||
}
|
||||
else if (genealogicalDataCommunicationRelation.LineTwo[1] == mother)
|
||||
{
|
||||
if (relation.Relation == husband)
|
||||
_ = stringBuilder.Append(nameof(father));
|
||||
else if (relation.Relation == wife)
|
||||
_ = stringBuilder.Append(genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()).Append(' ').Append(nameof(mother));
|
||||
}
|
||||
result = stringBuilder.ToString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void WriteAll(long ticks, string a2PeopleContentDirectory, List<string[]> frontMatterLinesCollections, string weekOfYear)
|
||||
{
|
||||
string json;
|
||||
string[] segments;
|
||||
string? directory;
|
||||
string frontMatterLastLine;
|
||||
DateTime dateTime = new(ticks);
|
||||
List<string> allFrontMatterLines = new();
|
||||
foreach (string[] frontMatterLines in frontMatterLinesCollections)
|
||||
{
|
||||
allFrontMatterLines.Add("{");
|
||||
frontMatterLastLine = frontMatterLines.Last();
|
||||
foreach (string frontMatterLine in frontMatterLines)
|
||||
{
|
||||
segments = frontMatterLine.Split(": ");
|
||||
if (segments.Length != 2)
|
||||
continue;
|
||||
if (frontMatterLine == frontMatterLastLine)
|
||||
allFrontMatterLines.Add($"\"{string.Join("\": ", segments)}");
|
||||
else
|
||||
allFrontMatterLines.Add($"\"{string.Join("\": ", segments)},");
|
||||
}
|
||||
allFrontMatterLines.Add("},");
|
||||
}
|
||||
directory = Path.Combine(a2PeopleContentDirectory, $"{dateTime.Year}-Markdown", $"{dateTime.Year}-Week-{weekOfYear}", ticks.ToString());
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
json = $"[{string.Join(Environment.NewLine, allFrontMatterLines.ToArray(), 0, allFrontMatterLines.Count - 1)}{allFrontMatterLines.Last()[..^1]}]";
|
||||
Models.GenealogicalDataCommunication[]? genealogicalDataCommunications = JsonSerializer.Deserialize(json, GenealogicalDataCommunicationSourceCollectionGenerationContext.Default.GenealogicalDataCommunicationArray);
|
||||
if (genealogicalDataCommunications is null)
|
||||
throw new NullReferenceException(nameof(genealogicalDataCommunications));
|
||||
json = JsonSerializer.Serialize(genealogicalDataCommunications, GenealogicalDataCommunicationSourceCollectionGenerationContext.Default.GenealogicalDataCommunicationArray);
|
||||
_ = IPath.WriteAllText(Path.Combine(directory, $"{ticks}.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
}
|
||||
|
||||
internal static void MaybeWriteMarkDownFiles(string mappingDefaultName, string personBirthdayFormat, long ticks, ReadOnlyCollection<Models.PersonContainer> personContainers, ReadOnlyDictionary<string, string[]> individuals, ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection, string a2PeopleContentDirectory)
|
||||
{
|
||||
bool? male;
|
||||
bool? first;
|
||||
string fullName;
|
||||
string[]? lines;
|
||||
string[] matches;
|
||||
string? directory;
|
||||
bool isDefaultName;
|
||||
const int zero = 0;
|
||||
string personKeyFormatted;
|
||||
string lowerHyphenFullName;
|
||||
List<string> frontMatterLines;
|
||||
string pattern = "[^a-z0-9-]";
|
||||
DateTime dateTime = new(ticks);
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
List<(string? Id, string[] FrontMatterLines)> collection = new();
|
||||
Models.GenealogicalDataCommunication genealogicalDataCommunication;
|
||||
GenealogicalDataCommunicationLines? genealogicalDataCommunicationLines;
|
||||
string weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
ReadOnlyDictionary<string, string> personKeyFormattedToPersonFullName = IPersonContainer.GetPersonKeyFormattedToPersonFullName(personBirthdayFormat, personContainers);
|
||||
foreach (Models.PersonContainer personContainer in personContainers.OrderByDescending(l => l.Key))
|
||||
{
|
||||
if (personContainer.Key is null || personContainer.Birthdays is null || personContainer.Person is null || personContainer.PersonDirectory is null || !personContainer.Birthdays.Any())
|
||||
continue;
|
||||
male = personContainer.PersonDirectory.Sex == 'U' ? null : personContainer.PersonDirectory.Sex == 'M' || (personContainer.PersonDirectory.Sex == 'F' ? false : throw new Exception());
|
||||
first = personContainer.PersonDirectory.First == 'U' ? null : personContainer.PersonDirectory.First == 'Y' || (personContainer.PersonDirectory.First == 'N' ? false : throw new Exception());
|
||||
if (first is null)
|
||||
continue;
|
||||
isDefaultName = IPerson.IsDefaultName(mappingDefaultName, personContainer.DisplayDirectoryName);
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(personBirthdayFormat, personContainer.Key.Value);
|
||||
matches = (from l in personContainer.DisplayDirectoryAllFiles where l.Contains(personKeyFormatted) select l).ToArray();
|
||||
if (!matches.Any())
|
||||
continue;
|
||||
directory = Path.GetDirectoryName(matches[zero]);
|
||||
if (directory is null)
|
||||
continue;
|
||||
if (!individuals.TryGetValue(personKeyFormatted, out lines))
|
||||
continue;
|
||||
genealogicalDataCommunicationLines = lines is null ? null : GetGenealogicalDataCommunicationLines(personContainer.Birthdays[zero], lines);
|
||||
if (genealogicalDataCommunicationLines is null)
|
||||
continue;
|
||||
genealogicalDataCommunication = GetGenealogicalDataCommunication(first.Value, genealogicalDataCommunicationLines);
|
||||
if (genealogicalDataCommunication.Sex != personContainer.PersonDirectory.Sex)
|
||||
continue;
|
||||
if (genealogicalDataCommunication.Birth is not null && !directory.EndsWith(genealogicalDataCommunication.Birth.Value.Hour.ToString()))
|
||||
continue;
|
||||
if (genealogicalDataCommunication.Death is null && personContainer.PersonDirectory.Status == 'D' || genealogicalDataCommunication.Death is not null && personContainer.PersonDirectory.Status == 'A')
|
||||
continue;
|
||||
fullName = PersonName.GetFullName(personContainer.Person.Name);
|
||||
lowerHyphenFullName = $"{Regex.Replace(fullName.ToLower(), pattern, "-")}";
|
||||
frontMatterLines = MarkDown.GetFrontMatterLines(ticks, fullName, lowerHyphenFullName, genealogicalDataCommunication);
|
||||
if (!frontMatterLines.Any())
|
||||
continue;
|
||||
collection.Add((genealogicalDataCommunication.Id, frontMatterLines.ToArray()));
|
||||
MarkDown.WriteFile(personKeyFormatted, ticks, a2PeopleContentDirectory, calendar, pattern, personKeyFormattedToPersonFullName, familyIndexToCollection, genealogicalDataCommunication, fullName, lowerHyphenFullName, frontMatterLines);
|
||||
}
|
||||
if (collection.Any())
|
||||
{
|
||||
List<string[]> frontMatterLinesCollections = (from l in collection orderby l.Id.Length, l.Id where l.Id is not null select l.FrontMatterLines).ToList();
|
||||
WriteAll(ticks, a2PeopleContentDirectory, frontMatterLinesCollections, weekOfYear);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -7,10 +7,14 @@ public interface IGenealogicalDataCommunication
|
||||
|
||||
// ...
|
||||
|
||||
List<string> TestStatic_GetMappedLines(string genealogicalDataCommunicationFile, bool requireNickName) =>
|
||||
GetMappedLines(genealogicalDataCommunicationFile, requireNickName);
|
||||
static List<string> GetMappedLines(string genealogicalDataCommunicationFile, bool requireNickName) =>
|
||||
GenealogicalDataCommunication.GetMappedLines(genealogicalDataCommunicationFile, requireNickName);
|
||||
const string Wife = "WIFE";
|
||||
const string Child = "CHIL";
|
||||
const string Husband = "HUSB";
|
||||
|
||||
List<string> TestStatic_GetMappedLines(string personBirthdayFormat, string genealogicalDataCommunicationFile, ReadOnlyCollection<Models.PersonContainer> personContainers, bool requireNickName) =>
|
||||
GetMappedLines(personBirthdayFormat, genealogicalDataCommunicationFile, personContainers, requireNickName);
|
||||
static List<string> GetMappedLines(string personBirthdayFormat, string genealogicalDataCommunicationFile, ReadOnlyCollection<Models.PersonContainer> personContainers, bool requireNickName) =>
|
||||
GenealogicalDataCommunication.GetMappedLines(personBirthdayFormat, genealogicalDataCommunicationFile, personContainers, requireNickName);
|
||||
|
||||
GenealogicalDataCommunicationLines TestStatic_GetGenealogicalDataCommunicationLines(Models.PersonBirthday personBirthday, string[] individualsLines) =>
|
||||
GetGenealogicalDataCommunicationLines(individualsLines);
|
||||
@ -22,14 +26,39 @@ public interface IGenealogicalDataCommunication
|
||||
static Models.GenealogicalDataCommunication GetGenealogicalDataCommunication(bool first, GenealogicalDataCommunicationLines genealogicalDataCommunicationLines) =>
|
||||
GenealogicalDataCommunication.GetGenealogicalDataCommunication(first, genealogicalDataCommunicationLines);
|
||||
|
||||
(string[], ReadOnlyDictionary<string, string[]>, List<string[]>, string[], List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations) TestStatic_GetIndividuals(string genealogicalDataCommunicationFile, bool requireNickName) =>
|
||||
GetIndividuals(genealogicalDataCommunicationFile, requireNickName);
|
||||
static (string[], ReadOnlyDictionary<string, string[]>, List<string[]>, string[], List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations) GetIndividuals(string genealogicalDataCommunicationFile, bool requireNickName) =>
|
||||
GenealogicalDataCommunication.GetIndividuals(genealogicalDataCommunicationFile, requireNickName);
|
||||
(string[], ReadOnlyDictionary<string, string[]>, List<string[]>, string[], List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations) TestStatic_GetIndividuals(string personBirthdayFormat, string genealogicalDataCommunicationFile, ReadOnlyCollection<Models.PersonContainer> personContainers, bool requireNickName) =>
|
||||
GetIndividuals(personBirthdayFormat, genealogicalDataCommunicationFile, personContainers, requireNickName);
|
||||
static (string[], ReadOnlyDictionary<string, string[]>, List<string[]>, string[], List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations) GetIndividuals(string personBirthdayFormat, string genealogicalDataCommunicationFile, ReadOnlyCollection<Models.PersonContainer> personContainers, bool requireNickName) =>
|
||||
GenealogicalDataCommunication.GetIndividuals(personBirthdayFormat, genealogicalDataCommunicationFile, personContainers, requireNickName);
|
||||
|
||||
bool TestStatic_CleanDisplayDirectoryAllFilesAndWriteTicksGed(string mappingDefaultName, string personBirthdayFormat, List<Models.PersonContainer> personContainers, string[] headerLines, List<string[]> familyGroupLines, string[] footerLines, long ticks, string a2PeopleContentDirectory) =>
|
||||
bool TestStatic_CleanDisplayDirectoryAllFilesAndWriteTicksGed(string mappingDefaultName, string personBirthdayFormat, ReadOnlyCollection<Models.PersonContainer> personContainers, string[] headerLines, List<string[]> familyGroupLines, string[] footerLines, long ticks, string a2PeopleContentDirectory) =>
|
||||
CleanDisplayDirectoryAllFilesAndWriteTicksGed(mappingDefaultName, personBirthdayFormat, personContainers, headerLines, familyGroupLines, footerLines, ticks, a2PeopleContentDirectory);
|
||||
static bool CleanDisplayDirectoryAllFilesAndWriteTicksGed(string mappingDefaultName, string personBirthdayFormat, List<Models.PersonContainer> personContainers, string[] headerLines, List<string[]> familyGroupLines, string[] footerLines, long ticks, string a2PeopleContentDirectory) =>
|
||||
static bool CleanDisplayDirectoryAllFilesAndWriteTicksGed(string mappingDefaultName, string personBirthdayFormat, ReadOnlyCollection<Models.PersonContainer> personContainers, string[] headerLines, List<string[]> familyGroupLines, string[] footerLines, long ticks, string a2PeopleContentDirectory) =>
|
||||
GenealogicalDataCommunication.CleanDisplayDirectoryAllFilesAndWriteTicksGed(mappingDefaultName, personBirthdayFormat, personContainers, headerLines, familyGroupLines, footerLines, ticks, a2PeopleContentDirectory);
|
||||
|
||||
ReadOnlyDictionary<long, List<GenealogicalDataCommunicationRelation>> TestStatic_GetCollection(string personBirthdayFormat, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations) =>
|
||||
GetCollection(personBirthdayFormat, genealogicalDataCommunicationRelations);
|
||||
static ReadOnlyDictionary<long, List<GenealogicalDataCommunicationRelation>> GetCollection(string personBirthdayFormat, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations) =>
|
||||
GenealogicalDataCommunication.GetCollection(personBirthdayFormat, genealogicalDataCommunicationRelations);
|
||||
|
||||
ReadOnlyDictionary<long, List<GenealogicalDataCommunicationRelation>> TestStatic_GetCollection(string personBirthdayFormat, ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection) =>
|
||||
GetCollection(personBirthdayFormat, familyIndexToCollection);
|
||||
static ReadOnlyDictionary<long, List<GenealogicalDataCommunicationRelation>> GetCollection(string personBirthdayFormat, ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection) =>
|
||||
GenealogicalDataCommunication.GetCollection(personBirthdayFormat, familyIndexToCollection);
|
||||
|
||||
ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> TestStatic_GetFamilyIndexToCollection(List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations) =>
|
||||
GetFamilyIndexToCollection(genealogicalDataCommunicationRelations);
|
||||
static ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> GetFamilyIndexToCollection(List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations) =>
|
||||
GenealogicalDataCommunication.GetFamilyIndexToCollection(genealogicalDataCommunicationRelations);
|
||||
|
||||
string? TestStatic_GetMergeWithLineTwo(GenealogicalDataCommunicationRelation genealogicalDataCommunicationRelation, GenealogicalDataCommunicationRelation relation) =>
|
||||
GetMergeWithLineTwo(genealogicalDataCommunicationRelation, relation);
|
||||
static string? GetMergeWithLineTwo(GenealogicalDataCommunicationRelation genealogicalDataCommunicationRelation, GenealogicalDataCommunicationRelation relation) =>
|
||||
GenealogicalDataCommunication.GetMergeWithLineTwo(genealogicalDataCommunicationRelation, relation);
|
||||
|
||||
void TestStatic_MaybeWriteMarkDownFiles(string mappingDefaultName, string personBirthdayFormat, long ticks, ReadOnlyCollection<Models.PersonContainer> personContainers, ReadOnlyDictionary<string, string[]> individuals, ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection, string a2PeopleContentDirectory) =>
|
||||
MaybeWriteMarkDownFiles(mappingDefaultName, personBirthdayFormat, ticks, personContainers, individuals, familyIndexToCollection, a2PeopleContentDirectory);
|
||||
static void MaybeWriteMarkDownFiles(string mappingDefaultName, string personBirthdayFormat, long ticks, ReadOnlyCollection<Models.PersonContainer> personContainers, ReadOnlyDictionary<string, string[]> individuals, ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection, string a2PeopleContentDirectory) =>
|
||||
GenealogicalDataCommunication.MaybeWriteMarkDownFiles(mappingDefaultName, personBirthdayFormat, ticks, personContainers, individuals, familyIndexToCollection, a2PeopleContentDirectory);
|
||||
|
||||
}
|
@ -12,20 +12,10 @@ public interface IPersonContainer
|
||||
static List<long> GetPersonKeys(IEnumerable<Models.PersonContainer> personContainers) =>
|
||||
PersonContainer.GetPersonKeys(personContainers);
|
||||
|
||||
List<Models.PersonContainer> TestStatic_GetNonSpecificPeopleCollection(string mappingDefaultName, int personBirthdayFirstYear, char[] personCharacters, List<Models.PersonContainer> personContainers, long ticks) =>
|
||||
GetNonSpecificPeopleCollection(mappingDefaultName, personBirthdayFirstYear, personCharacters, personContainers, ticks);
|
||||
static List<Models.PersonContainer> GetNonSpecificPeopleCollection(string mappingDefaultName, int personBirthdayFirstYear, char[] personCharacters, List<Models.PersonContainer> personContainers, long ticks) =>
|
||||
PersonContainer.GetNonSpecificPeopleCollection(mappingDefaultName, personBirthdayFirstYear, personCharacters, personContainers, ticks);
|
||||
|
||||
List<Models.PersonContainer> TestStatic_GetPersonContainers(Properties.IStorage storage, string mappingDefaultName, string personBirthdayFormat, char[] personCharacters, string facesFileNameExtension, ReadOnlyDictionary<string, string[]> individuals) =>
|
||||
GetPersonContainers(storage, mappingDefaultName, personBirthdayFormat, personCharacters, facesFileNameExtension, individuals);
|
||||
static List<Models.PersonContainer> GetPersonContainers(Properties.IStorage storage, string mappingDefaultName, string personBirthdayFormat, char[] personCharacters, string facesFileNameExtension, ReadOnlyDictionary<string, string[]> individuals) =>
|
||||
PersonContainer.GetPersonContainers(storage, mappingDefaultName, personBirthdayFormat, personCharacters, facesFileNameExtension, individuals);
|
||||
|
||||
void TestStatic_MaybeWriteMarkDownFiles(string mappingDefaultName, string personBirthdayFormat, long ticks, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, List<Models.PersonContainer> personContainers, string a2PeopleContentDirectory) =>
|
||||
MaybeWriteMarkDownFiles(mappingDefaultName, personBirthdayFormat, ticks, genealogicalDataCommunicationRelations, personContainers, a2PeopleContentDirectory);
|
||||
static void MaybeWriteMarkDownFiles(string mappingDefaultName, string personBirthdayFormat, long ticks, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, List<Models.PersonContainer> personContainers, string a2PeopleContentDirectory) =>
|
||||
PersonContainer.MaybeWriteMarkDownFiles(mappingDefaultName, personBirthdayFormat, ticks, genealogicalDataCommunicationRelations, personContainers, a2PeopleContentDirectory);
|
||||
List<Models.PersonContainer> TestStatic_GetPersonContainers(Properties.IStorage storage, string mappingDefaultName, string personBirthdayFormat, char[] personCharacters, string facesFileNameExtension) =>
|
||||
GetPersonContainers(storage, mappingDefaultName, personBirthdayFormat, personCharacters, facesFileNameExtension);
|
||||
static List<Models.PersonContainer> GetPersonContainers(Properties.IStorage storage, string mappingDefaultName, string personBirthdayFormat, char[] personCharacters, string facesFileNameExtension) =>
|
||||
PersonContainer.GetPersonContainers(storage, mappingDefaultName, personBirthdayFormat, personCharacters, facesFileNameExtension);
|
||||
|
||||
List<(long?, string)> TestStatic_GetDisplay(string personBirthdayFormat, Models.PersonContainer personContainer) =>
|
||||
GetDisplay(personBirthdayFormat, personContainer);
|
||||
@ -37,4 +27,9 @@ public interface IPersonContainer
|
||||
static string? VerifyAge(char numberSign, string personDisplayDirectory, string? minusOne, string personDisplayDirectoryName, int? approximateYears, List<(string PersonKeyFormatted, Models.PersonBirthday PersonBirthday)> collection) =>
|
||||
PersonContainer.VerifyAge(numberSign, personDisplayDirectory, minusOne, personDisplayDirectoryName, approximateYears, collection);
|
||||
|
||||
ReadOnlyDictionary<string, string> TestStatic_GetPersonKeyFormattedToPersonFullName(string personBirthdayFormat, ReadOnlyCollection<Models.PersonContainer> personContainers) =>
|
||||
GetPersonKeyFormattedToPersonFullName(personBirthdayFormat, personContainers);
|
||||
static ReadOnlyDictionary<string, string> GetPersonKeyFormattedToPersonFullName(string personBirthdayFormat, ReadOnlyCollection<Models.PersonContainer> personContainers) =>
|
||||
PersonContainer.GetPersonKeyFormattedToPersonFullName(personBirthdayFormat, personContainers);
|
||||
|
||||
}
|
@ -33,10 +33,12 @@ internal abstract class MarkDown
|
||||
{
|
||||
i = j;
|
||||
afterTrim = parsedLines[j].Trim();
|
||||
if (afterTrim != "],")
|
||||
_ = stringBuilder.Append(afterTrim);
|
||||
else
|
||||
if (afterTrim == "],")
|
||||
_ = stringBuilder.Append(afterTrim[..^1]);
|
||||
else if (afterTrim[^1] == ',')
|
||||
_ = stringBuilder.Append(afterTrim).Append(' ');
|
||||
else
|
||||
_ = stringBuilder.Append(afterTrim);
|
||||
if (afterTrim is "]" or "],")
|
||||
{
|
||||
results.Add(stringBuilder.ToString());
|
||||
@ -60,7 +62,7 @@ internal abstract class MarkDown
|
||||
{
|
||||
List<string> results;
|
||||
string[] parsedLines = genealogicalDataCommunication.ToString().Split(Environment.NewLine);
|
||||
results = GetFrontMatterLines(parsedLines);
|
||||
results = GetFrontMatterLines(parsedLines);
|
||||
if (results.Any())
|
||||
{
|
||||
DateTime dateTime = new DateTime(ticks).ToUniversalTime();
|
||||
@ -74,96 +76,80 @@ internal abstract class MarkDown
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static void WriteFile(string personKeyFormatted, long ticks, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, string a2PeopleContentDirectory, Calendar calendar, string pattern, ReadOnlyDictionary<string, string> personKeyFormattedToPersonFullName, ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection, Models.GenealogicalDataCommunication genealogicalDataCommunication, string fullName, string lowerHyphenFullName, List<string> frontMatterLines)
|
||||
internal static void WriteFile(string personKeyFormatted, long ticks, string a2PeopleContentDirectory, Calendar calendar, string pattern, ReadOnlyDictionary<string, string> personKeyFormattedToPersonFullName, ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection, Models.GenealogicalDataCommunication genealogicalDataCommunication, string fullName, string lowerHyphenFullName, List<string> frontMatterLines)
|
||||
{
|
||||
string text;
|
||||
string decade;
|
||||
string? personFullName;
|
||||
const char father = 'F';
|
||||
const char mother = 'M';
|
||||
bool hasRelation = false;
|
||||
const string wife = "WIFE";
|
||||
string? mergeWithLineTwo;
|
||||
List<string> lines = new();
|
||||
StringBuilder link = new();
|
||||
const string child = "CHIL";
|
||||
const string husband = "HUSB";
|
||||
const string person = "person";
|
||||
DateTime dateTime = new(ticks);
|
||||
List<GenealogicalDataCommunicationRelation>? relations;
|
||||
List<GenealogicalDataCommunicationRelation>? genealogicalDataCommunicationRelations;
|
||||
lines.Add("---");
|
||||
lines.AddRange(frontMatterLines);
|
||||
lines.Add("---");
|
||||
lines.Add(string.Empty);
|
||||
lines.Add($"# {fullName}");
|
||||
lines.Add(string.Empty);
|
||||
foreach (GenealogicalDataCommunicationRelation genealogicalDataCommunicationRelation in genealogicalDataCommunicationRelations)
|
||||
foreach (KeyValuePair<int, List<GenealogicalDataCommunicationRelation>> keyValuePair in familyIndexToCollection)
|
||||
{
|
||||
if (genealogicalDataCommunication?.NickName is null || genealogicalDataCommunication.NickName.Length < 4)
|
||||
continue;
|
||||
if (genealogicalDataCommunicationRelation.Relation != child)
|
||||
continue;
|
||||
if (genealogicalDataCommunicationRelation.NickName != personKeyFormatted)
|
||||
continue;
|
||||
if (!familyIndexToCollection.TryGetValue(genealogicalDataCommunicationRelation.FamilyIndex, out relations))
|
||||
continue;
|
||||
foreach (GenealogicalDataCommunicationRelation relation in relations)
|
||||
foreach (GenealogicalDataCommunicationRelation genealogicalDataCommunicationRelation in keyValuePair.Value)
|
||||
{
|
||||
if (relation.FamilyIndex != genealogicalDataCommunicationRelation.FamilyIndex)
|
||||
if (genealogicalDataCommunication?.NickName is null || genealogicalDataCommunication.NickName.Length < 4)
|
||||
continue;
|
||||
if (relation.Relation is husband or wife)
|
||||
if (genealogicalDataCommunicationRelation.Relation != IGenealogicalDataCommunication.Child)
|
||||
continue;
|
||||
if (genealogicalDataCommunicationRelation.NickName != personKeyFormatted)
|
||||
continue;
|
||||
if (!familyIndexToCollection.TryGetValue(genealogicalDataCommunicationRelation.FamilyIndex, out genealogicalDataCommunicationRelations))
|
||||
continue;
|
||||
foreach (GenealogicalDataCommunicationRelation relation in genealogicalDataCommunicationRelations)
|
||||
{
|
||||
if (!hasRelation)
|
||||
if (relation.FamilyIndex != genealogicalDataCommunicationRelation.FamilyIndex)
|
||||
continue;
|
||||
if (relation.Relation is IGenealogicalDataCommunication.Husband or IGenealogicalDataCommunication.Wife)
|
||||
{
|
||||
lines.Add("## Relations");
|
||||
lines.Add(string.Empty);
|
||||
hasRelation = true;
|
||||
}
|
||||
decade = relation.NickName[..3];
|
||||
_ = link.Clear();
|
||||
_ = link.Append("- [");
|
||||
if (!personKeyFormattedToPersonFullName.TryGetValue(relation.NickName, out personFullName))
|
||||
_ = link.Append(relation.NickName);
|
||||
else
|
||||
_ = link.Append(personFullName);
|
||||
if (genealogicalDataCommunication.NickName[..3] == decade)
|
||||
_ = link.Append("](");
|
||||
else
|
||||
_ = link.Append("](../").Append(decade).Append('/');
|
||||
if (personFullName is null)
|
||||
_ = link.Append(relation.NickName);
|
||||
else
|
||||
_ = link.Append(Regex.Replace(personFullName.ToLower(), pattern, "-").Replace("--", "-"));
|
||||
_ = link.Append(".md) ");
|
||||
if (string.IsNullOrEmpty(genealogicalDataCommunicationRelation.LineTwo))
|
||||
lines.Add(link.ToString());
|
||||
else
|
||||
{
|
||||
if (genealogicalDataCommunicationRelation.LineTwo[1] == father)
|
||||
if (!hasRelation)
|
||||
{
|
||||
if (relation.Relation == wife)
|
||||
_ = link.Append(nameof(mother));
|
||||
else if (relation.Relation == husband)
|
||||
_ = link.Append(genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()).Append(nameof(father));
|
||||
lines.Add("## Relations");
|
||||
lines.Add(string.Empty);
|
||||
hasRelation = true;
|
||||
}
|
||||
else if (genealogicalDataCommunicationRelation.LineTwo[1] == mother)
|
||||
{
|
||||
if (relation.Relation == husband)
|
||||
_ = link.Append(nameof(father));
|
||||
else if (relation.Relation == wife)
|
||||
_ = link.Append(genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()).Append(nameof(mother));
|
||||
}
|
||||
lines.Add(link.ToString());
|
||||
decade = relation.NickName[..3];
|
||||
_ = link.Clear();
|
||||
_ = link.Append("- [");
|
||||
if (!personKeyFormattedToPersonFullName.TryGetValue(relation.NickName, out personFullName))
|
||||
_ = link.Append(relation.NickName);
|
||||
else
|
||||
_ = link.Append(personFullName);
|
||||
if (genealogicalDataCommunication.NickName[..3] == decade)
|
||||
_ = link.Append("](");
|
||||
else
|
||||
_ = link.Append("](../").Append(decade).Append('/');
|
||||
if (personFullName is null)
|
||||
_ = link.Append(relation.NickName);
|
||||
else
|
||||
_ = link.Append(Regex.Replace(personFullName.ToLower(), pattern, "-").Replace("--", "-"));
|
||||
_ = link.Append(".md) ");
|
||||
mergeWithLineTwo = GenealogicalDataCommunication.GetMergeWithLineTwo(genealogicalDataCommunicationRelation, relation);
|
||||
lines.Add($"{link}{mergeWithLineTwo}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasRelation)
|
||||
lines.Add(string.Empty);
|
||||
string text = string.Join(Environment.NewLine, lines);
|
||||
// text = string.Join(Environment.NewLine, lines);
|
||||
// _ = IPath.WriteAllText(Path.Combine(directory, $"{personKeyFormatted}.md"), text, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
string weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
string directory = Path.Combine(a2PeopleContentDirectory, $"{dateTime.Year}-Markdown", $"{dateTime.Year}-Week-{weekOfYear}", ticks.ToString(), person, personKeyFormatted[..3]);
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
_ = IPath.WriteAllText(Path.Combine(directory, $"{lowerHyphenFullName}.md"), text, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
string markdownOnlyDirectory = Path.Combine(a2PeopleContentDirectory, $"{dateTime.Year}-Markdown", $"{dateTime.Year}-Week-{weekOfYear}", ticks.ToString(), person, personKeyFormatted[..3]);
|
||||
if (!Directory.Exists(markdownOnlyDirectory))
|
||||
_ = Directory.CreateDirectory(markdownOnlyDirectory);
|
||||
text = string.Join(Environment.NewLine, lines);
|
||||
_ = IPath.WriteAllText(Path.Combine(markdownOnlyDirectory, $"{lowerHyphenFullName}.md"), text, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
@ -95,19 +92,17 @@ internal abstract class PersonContainer
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<Models.PersonContainer> GetPersonContainersCollections(string mappingDefaultName, string facesFileNameExtension, char[] personCharacters, ReadOnlyDictionary<string, string[]> individuals, PersonDirectory personDirectory, char numberSign, string personDisplayDirectory, string personDisplayDirectoryName, bool isDefaultName, int? approximateYears, List<(string PersonKeyFormatted, Models.PersonBirthday PersonBirthday)> collection)
|
||||
private static List<Models.PersonContainer> GetPersonContainersCollections(string mappingDefaultName, string facesFileNameExtension, char[] personCharacters, PersonDirectory personDirectory, char numberSign, string personDisplayDirectory, string personDisplayDirectoryName, bool isDefaultName, int? approximateYears, List<(string PersonKeyFormatted, Models.PersonBirthday PersonBirthday)> collection)
|
||||
{
|
||||
List<Models.PersonContainer> results = new();
|
||||
long personKey;
|
||||
const int zero = 0;
|
||||
Models.Person person;
|
||||
string[]? individualsLines;
|
||||
Models.PersonContainer personContainer;
|
||||
Models.PersonBirthday[] orderedPersonBirthdays;
|
||||
string[] personDisplayDirectoryAllFiles = GetFiles(facesFileNameExtension, personDisplayDirectory, isDefaultName);
|
||||
foreach ((string personKeyFormatted, Models.PersonBirthday personBirthday) in collection)
|
||||
{
|
||||
_ = individuals.TryGetValue(personKeyFormatted, out individualsLines);
|
||||
orderedPersonBirthdays = (from l in collection where !l.PersonKeyFormatted.Contains(numberSign) orderby l.PersonBirthday.Value.Ticks descending select l.PersonBirthday).ToArray();
|
||||
if (!orderedPersonBirthdays.Any())
|
||||
personKey = collection[zero].PersonBirthday.Value.Ticks;
|
||||
@ -118,7 +113,7 @@ internal abstract class PersonContainer
|
||||
personKey = orderedPersonBirthdays[zero].Value.Ticks;
|
||||
}
|
||||
person = IPerson.GetPerson(mappingDefaultName, personCharacters, personDisplayDirectoryName, personDisplayDirectoryAllFiles, personKey);
|
||||
personContainer = new(approximateYears, orderedPersonBirthdays, personDisplayDirectoryAllFiles, personDisplayDirectoryName, individualsLines, personKey, person, personDirectory);
|
||||
personContainer = new(approximateYears, orderedPersonBirthdays, personDisplayDirectoryAllFiles, personDisplayDirectoryName, personKey, person, personDirectory);
|
||||
results.Add(personContainer);
|
||||
}
|
||||
return results;
|
||||
@ -155,7 +150,7 @@ internal abstract class PersonContainer
|
||||
return result;
|
||||
}
|
||||
|
||||
private static (List<string?>, List<Models.PersonContainer>) GetPersonContainersGroup(string mappingDefaultName, string personBirthdayFormat, string facesFileNameExtension, char[] personCharacters, ReadOnlyDictionary<string, string[]> individuals, PersonDirectory personDirectory, string[] personDisplayDirectories)
|
||||
private static (List<string?>, List<Models.PersonContainer>) GetPersonContainersGroup(string mappingDefaultName, string personBirthdayFormat, string facesFileNameExtension, char[] personCharacters, PersonDirectory personDirectory, string[] personDisplayDirectories)
|
||||
{
|
||||
List<Models.PersonContainer> results = new();
|
||||
string? minusOne;
|
||||
@ -189,7 +184,7 @@ internal abstract class PersonContainer
|
||||
continue;
|
||||
if (collection.Any())
|
||||
{
|
||||
personContainers = GetPersonContainersCollections(mappingDefaultName, facesFileNameExtension, personCharacters, individuals, personDirectory, numberSign, personDisplayDirectory, personDisplayDirectoryName, isDefaultName, approximateYears, collection);
|
||||
personContainers = GetPersonContainersCollections(mappingDefaultName, facesFileNameExtension, personCharacters, personDirectory, numberSign, personDisplayDirectory, personDisplayDirectoryName, isDefaultName, approximateYears, collection);
|
||||
results.AddRange(personContainers);
|
||||
}
|
||||
else
|
||||
@ -202,7 +197,7 @@ internal abstract class PersonContainer
|
||||
return new(changes, results);
|
||||
}
|
||||
|
||||
private static (List<string?>, List<Models.PersonContainer>) GetPersonContainersInnerGroups(string mappingDefaultName, string personBirthdayFormat, string facesFileNameExtension, char[] personCharacters, ReadOnlyDictionary<string, string[]> individuals, string groupDirectory, string groupDirectoryName)
|
||||
private static (List<string?>, List<Models.PersonContainer>) GetPersonContainersInnerGroups(string mappingDefaultName, string personBirthdayFormat, string facesFileNameExtension, char[] personCharacters, string groupDirectory, string groupDirectoryName)
|
||||
{
|
||||
List<Models.PersonContainer> results = new();
|
||||
string[] segments;
|
||||
@ -219,7 +214,7 @@ internal abstract class PersonContainer
|
||||
if (@char == exclamationPoint)
|
||||
{
|
||||
personDirectory = new(@char, "Ignore", 'U', 'U', 'U');
|
||||
(changes, collection) = GetPersonContainersGroup(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, individuals, personDirectory, innerGroupDirectories);
|
||||
(changes, collection) = GetPersonContainersGroup(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, personDirectory, innerGroupDirectories);
|
||||
allChanges.AddRange(changes);
|
||||
results.AddRange(collection);
|
||||
}
|
||||
@ -241,7 +236,7 @@ internal abstract class PersonContainer
|
||||
continue;
|
||||
personDirectory = new(@char, innerGroupDirectoryName, segments[zero][zero], segments[1][zero], segments[2][zero]);
|
||||
personDisplayDirectories = Directory.GetDirectories(innerGroupDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||
(changes, collection) = GetPersonContainersGroup(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, individuals, personDirectory, personDisplayDirectories);
|
||||
(changes, collection) = GetPersonContainersGroup(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, personDirectory, personDisplayDirectories);
|
||||
allChanges.AddRange(changes);
|
||||
results.AddRange(collection);
|
||||
}
|
||||
@ -249,7 +244,7 @@ internal abstract class PersonContainer
|
||||
return new(allChanges, results);
|
||||
}
|
||||
|
||||
private static List<Models.PersonContainer> GetPersonContainersGroups(string mappingDefaultName, string personBirthdayFormat, string facesFileNameExtension, char[] personCharacters, ReadOnlyDictionary<string, string[]> individuals, string[] groupDirectories)
|
||||
private static List<Models.PersonContainer> GetPersonContainersGroups(string mappingDefaultName, string personBirthdayFormat, string facesFileNameExtension, char[] personCharacters, string[] groupDirectories)
|
||||
{
|
||||
List<Models.PersonContainer> results;
|
||||
const int zero = 0;
|
||||
@ -263,7 +258,7 @@ internal abstract class PersonContainer
|
||||
groupDirectoryName = Path.GetFileName(groupDirectory);
|
||||
if (!personCharacters.Contains(groupDirectoryName[zero]))
|
||||
continue;
|
||||
(changes, collection) = GetPersonContainersInnerGroups(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, individuals, groupDirectory, groupDirectoryName);
|
||||
(changes, collection) = GetPersonContainersInnerGroups(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, groupDirectory, groupDirectoryName);
|
||||
allChanges.AddRange(changes);
|
||||
personContainers.AddRange(collection);
|
||||
}
|
||||
@ -273,7 +268,7 @@ internal abstract class PersonContainer
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static List<Models.PersonContainer> GetPersonContainers(Properties.IStorage storage, string mappingDefaultName, string personBirthdayFormat, char[] personCharacters, string facesFileNameExtension, ReadOnlyDictionary<string, string[]> individuals)
|
||||
internal static List<Models.PersonContainer> GetPersonContainers(Properties.IStorage storage, string mappingDefaultName, string personBirthdayFormat, char[] personCharacters, string facesFileNameExtension)
|
||||
{
|
||||
List<Models.PersonContainer> results;
|
||||
string a2PeopleSingletonDirectory = Path.Combine(storage.PeopleRootDirectory, "{}");
|
||||
@ -290,7 +285,7 @@ internal abstract class PersonContainer
|
||||
if (!groupDirectories.Any())
|
||||
results = new();
|
||||
else
|
||||
results = GetPersonContainersGroups(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, individuals, groupDirectories);
|
||||
results = GetPersonContainersGroups(mappingDefaultName, personBirthdayFormat, facesFileNameExtension, personCharacters, groupDirectories);
|
||||
return results;
|
||||
}
|
||||
|
||||
@ -329,34 +324,7 @@ internal abstract class PersonContainer
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static List<Models.PersonContainer> GetNonSpecificPeopleCollection(string mappingDefaultName, int personBirthdayFirstYear, char[] personCharacters, List<Models.PersonContainer> personContainers, long ticks)
|
||||
{
|
||||
List<Models.PersonContainer> results = new();
|
||||
long personKey;
|
||||
Models.Person person;
|
||||
int? approximateYears = null;
|
||||
Models.PersonBirthday personBirthday;
|
||||
Models.PersonContainer personContainer;
|
||||
List<long> personKeys = GetPersonKeys(personContainers);
|
||||
string[] personDisplayDirectoryAllFiles = Array.Empty<string>();
|
||||
DateTime incrementDate = new(personBirthdayFirstYear, 1, 1);
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
personKey = incrementDate.Ticks;
|
||||
incrementDate = incrementDate.AddDays(1);
|
||||
if (incrementDate.Ticks > ticks)
|
||||
break;
|
||||
if (personKeys.Contains(personKey))
|
||||
continue;
|
||||
personBirthday = IPersonBirthday.GetPersonBirthday(personKey);
|
||||
person = IPerson.GetPerson(mappingDefaultName, personCharacters, mappingDefaultName, personKey, personBirthday);
|
||||
personContainer = new(approximateYears, new Models.PersonBirthday[] { personBirthday }, personDisplayDirectoryAllFiles, mappingDefaultName, personKey, person);
|
||||
results.Add(personContainer);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<string, string> GetPersonKeyFormattedToPersonFullName(string personBirthdayFormat, List<Models.PersonContainer> personContainers)
|
||||
internal static ReadOnlyDictionary<string, string> GetPersonKeyFormattedToPersonFullName(string personBirthdayFormat, ReadOnlyCollection<Models.PersonContainer> personContainers)
|
||||
{
|
||||
Dictionary<string, string> results = new();
|
||||
string? value;
|
||||
@ -376,118 +344,4 @@ internal abstract class PersonContainer
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> GetFamilyIndexToCollection(List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations)
|
||||
{
|
||||
Dictionary<int, List<GenealogicalDataCommunicationRelation>> results = new();
|
||||
List<GenealogicalDataCommunicationRelation>? relations;
|
||||
foreach (GenealogicalDataCommunicationRelation genealogicalDataCommunicationRelation in genealogicalDataCommunicationRelations)
|
||||
{
|
||||
if (!results.TryGetValue(genealogicalDataCommunicationRelation.FamilyIndex, out relations))
|
||||
{
|
||||
results.Add(genealogicalDataCommunicationRelation.FamilyIndex, new());
|
||||
if (!results.TryGetValue(genealogicalDataCommunicationRelation.FamilyIndex, out relations))
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
relations.Add(genealogicalDataCommunicationRelation);
|
||||
}
|
||||
return new(results);
|
||||
}
|
||||
|
||||
private static void WriteAll(long ticks, string a2PeopleContentDirectory, List<string[]> frontMatterLinesCollections, string weekOfYear)
|
||||
{
|
||||
string json;
|
||||
string[] segments;
|
||||
string? directory;
|
||||
string frontMatterLastLine;
|
||||
DateTime dateTime = new(ticks);
|
||||
List<string> allFrontMatterLines = new();
|
||||
foreach (string[] frontMatterLines in frontMatterLinesCollections)
|
||||
{
|
||||
allFrontMatterLines.Add("{");
|
||||
frontMatterLastLine = frontMatterLines.Last();
|
||||
foreach (string frontMatterLine in frontMatterLines)
|
||||
{
|
||||
segments = frontMatterLine.Split(": ");
|
||||
if (segments.Length != 2)
|
||||
continue;
|
||||
if (frontMatterLine == frontMatterLastLine)
|
||||
allFrontMatterLines.Add($"\"{string.Join("\": ", segments)}");
|
||||
else
|
||||
allFrontMatterLines.Add($"\"{string.Join("\": ", segments)},");
|
||||
}
|
||||
allFrontMatterLines.Add("},");
|
||||
}
|
||||
directory = Path.Combine(a2PeopleContentDirectory, $"{dateTime.Year}-Markdown", $"{dateTime.Year}-Week-{weekOfYear}", ticks.ToString());
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
json = $"[{string.Join(Environment.NewLine, allFrontMatterLines.ToArray(), 0, allFrontMatterLines.Count - 1)}{allFrontMatterLines.Last()[..^1]}]";
|
||||
Models.GenealogicalDataCommunication[]? genealogicalDataCommunications = JsonSerializer.Deserialize(json, GenealogicalDataCommunicationSourceCollectionGenerationContext.Default.GenealogicalDataCommunicationArray);
|
||||
if (genealogicalDataCommunications is null)
|
||||
throw new NullReferenceException(nameof(genealogicalDataCommunications));
|
||||
json = JsonSerializer.Serialize(genealogicalDataCommunications, GenealogicalDataCommunicationSourceCollectionGenerationContext.Default.GenealogicalDataCommunicationArray);
|
||||
_ = IPath.WriteAllText(Path.Combine(directory, $"{ticks}.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
}
|
||||
|
||||
internal static void MaybeWriteMarkDownFiles(string mappingDefaultName, string personBirthdayFormat, long ticks, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, List<Models.PersonContainer> personContainers, string a2PeopleContentDirectory)
|
||||
{
|
||||
bool? male;
|
||||
bool? first;
|
||||
string fullName;
|
||||
string[] matches;
|
||||
string? directory;
|
||||
bool isDefaultName;
|
||||
const int zero = 0;
|
||||
string personKeyFormatted;
|
||||
string lowerHyphenFullName;
|
||||
List<string> frontMatterLines;
|
||||
string pattern = "[^a-z0-9-]";
|
||||
DateTime dateTime = new(ticks);
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
List<(string? Id, string[] FrontMatterLines)> collection = new();
|
||||
Models.GenealogicalDataCommunication genealogicalDataCommunication;
|
||||
GenealogicalDataCommunicationLines? genealogicalDataCommunicationLines;
|
||||
string weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
|
||||
ReadOnlyDictionary<string, string> personKeyFormattedToPersonFullName = GetPersonKeyFormattedToPersonFullName(personBirthdayFormat, personContainers);
|
||||
ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection = GetFamilyIndexToCollection(genealogicalDataCommunicationRelations);
|
||||
foreach (Models.PersonContainer personContainer in personContainers.OrderByDescending(l => l.Key))
|
||||
{
|
||||
if (personContainer.Key is null || personContainer.Birthdays is null || personContainer.Person is null || personContainer.PersonDirectory is null || !personContainer.Birthdays.Any())
|
||||
continue;
|
||||
male = personContainer.PersonDirectory.Sex == 'U' ? null : personContainer.PersonDirectory.Sex == 'M' || (personContainer.PersonDirectory.Sex == 'F' ? false : throw new Exception());
|
||||
first = personContainer.PersonDirectory.First == 'U' ? null : personContainer.PersonDirectory.First == 'Y' || (personContainer.PersonDirectory.First == 'N' ? false : throw new Exception());
|
||||
if (first is null)
|
||||
continue;
|
||||
isDefaultName = IPerson.IsDefaultName(mappingDefaultName, personContainer.DisplayDirectoryName);
|
||||
personKeyFormatted = IPersonBirthday.GetFormatted(personBirthdayFormat, personContainer.Key.Value);
|
||||
matches = (from l in personContainer.DisplayDirectoryAllFiles where l.Contains(personKeyFormatted) select l).ToArray();
|
||||
if (!matches.Any())
|
||||
continue;
|
||||
directory = Path.GetDirectoryName(matches[zero]);
|
||||
if (directory is null)
|
||||
continue;
|
||||
genealogicalDataCommunicationLines = personContainer.GenealogicalDataCommunicationRelationIndividualsLines is null ? null : GenealogicalDataCommunication.GetGenealogicalDataCommunicationLines(personContainer.Birthdays[zero], personContainer.GenealogicalDataCommunicationRelationIndividualsLines);
|
||||
if (genealogicalDataCommunicationLines is null)
|
||||
continue;
|
||||
genealogicalDataCommunication = GenealogicalDataCommunication.GetGenealogicalDataCommunication(first.Value, genealogicalDataCommunicationLines);
|
||||
if (genealogicalDataCommunication.Sex != personContainer.PersonDirectory.Sex)
|
||||
continue;
|
||||
if (genealogicalDataCommunication.Birth is not null && !directory.EndsWith(genealogicalDataCommunication.Birth.Value.Hour.ToString()))
|
||||
continue;
|
||||
if (genealogicalDataCommunication.Death is null && personContainer.PersonDirectory.Status == 'D' || genealogicalDataCommunication.Death is not null && personContainer.PersonDirectory.Status == 'A')
|
||||
continue;
|
||||
fullName = PersonName.GetFullName(personContainer.Person.Name);
|
||||
lowerHyphenFullName = $"{Regex.Replace(fullName.ToLower(), pattern, "-")}";
|
||||
frontMatterLines = MarkDown.GetFrontMatterLines(ticks, fullName, lowerHyphenFullName, genealogicalDataCommunication);
|
||||
if (!frontMatterLines.Any())
|
||||
continue;
|
||||
collection.Add((genealogicalDataCommunication.Id, frontMatterLines.ToArray()));
|
||||
MarkDown.WriteFile(personKeyFormatted, ticks, genealogicalDataCommunicationRelations, a2PeopleContentDirectory, calendar, pattern, personKeyFormattedToPersonFullName, familyIndexToCollection, genealogicalDataCommunication, fullName, lowerHyphenFullName, frontMatterLines);
|
||||
}
|
||||
if (collection.Any())
|
||||
{
|
||||
List<string[]> frontMatterLinesCollections = (from l in collection orderby l.Id.Length, l.Id where l.Id is not null select l.FrontMatterLines).ToList();
|
||||
WriteAll(ticks, a2PeopleContentDirectory, frontMatterLinesCollections, weekOfYear);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user