Person Containers Inner Groups
This commit is contained in:
@ -114,12 +114,13 @@ internal abstract class GenealogicalDataCommunication
|
||||
internal static List<string> GetMappedLines(string genealogicalDataCommunicationFile, bool requireNickName)
|
||||
{
|
||||
List<string> results = new();
|
||||
Models.PersonBirthday personBirthday = new(DateTime.Now);
|
||||
GenealogicalDataCommunicationLines genealogicalDataCommunicationLines;
|
||||
(string[] headerLines, Dictionary<string, List<string>> individuals, string[] footerLines) = GetIndividuals(genealogicalDataCommunicationFile, requireNickName);
|
||||
results.AddRange(headerLines);
|
||||
foreach (KeyValuePair<string, List<string>> keyValuePair in individuals)
|
||||
{
|
||||
genealogicalDataCommunicationLines = GetGenealogicalDataCommunicationLines(keyValuePair.Value);
|
||||
genealogicalDataCommunicationLines = GetGenealogicalDataCommunicationLines(personBirthday, keyValuePair.Value);
|
||||
if (!string.IsNullOrEmpty(genealogicalDataCommunicationLines.Id))
|
||||
results.Add(genealogicalDataCommunicationLines.Id);
|
||||
if (!string.IsNullOrEmpty(genealogicalDataCommunicationLines.UId))
|
||||
@ -142,7 +143,7 @@ internal abstract class GenealogicalDataCommunication
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static GenealogicalDataCommunicationLines GetGenealogicalDataCommunicationLines(List<string> individualsLines)
|
||||
internal static GenealogicalDataCommunicationLines GetGenealogicalDataCommunicationLines(Models.PersonBirthday personBirthday, List<string> individualsLines)
|
||||
{
|
||||
GenealogicalDataCommunicationLines result;
|
||||
string? idLine = null;
|
||||
@ -202,11 +203,16 @@ internal abstract class GenealogicalDataCommunication
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!birthLines.Any())
|
||||
{
|
||||
birthLines.Add("1 BIRT");
|
||||
birthLines.Add($"2 DATE {personBirthday.Value:dd MMM yyyy}");
|
||||
}
|
||||
result = new(idLine, uIdLine, nameLine, givenNameLine, surNameLine, suffixLine, nickNameLine, sexLine, birthLines, deathLines, changedLines);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static Models.GenealogicalDataCommunication GetGenealogicalDataCommunication(Models.PersonBirthday personBirthday, GenealogicalDataCommunicationLines genealogicalDataCommunicationLines)
|
||||
internal static Models.GenealogicalDataCommunication GetGenealogicalDataCommunication(GenealogicalDataCommunicationLines genealogicalDataCommunicationLines)
|
||||
{
|
||||
Models.GenealogicalDataCommunication result;
|
||||
DateTime? birth;
|
||||
@ -245,47 +251,20 @@ internal abstract class GenealogicalDataCommunication
|
||||
birth = birth.Value.AddHours(hours);
|
||||
if (age < 1)
|
||||
birth = null;
|
||||
if (death is null && (!alive || age > 110))
|
||||
if (death is null && (!alive || (age > 110 && !IPersonBirthday.IsCounterPersonBirthday(new(birth.Value)))))
|
||||
death = birth;
|
||||
}
|
||||
death ??= !genealogicalDataCommunicationLines.Death.Any(l => l == "1 DEAT Y") ? null : birth is not null ? birth : personBirthday.Value;
|
||||
death ??= !genealogicalDataCommunicationLines.Death.Any(l => l == "1 DEAT Y") ? null : birth;
|
||||
result = new(id, uId, name, givenName, surName, suffix, nickName, sex, birth, death, changed);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static void WriteFile(string personKeyFormatted, Models.PersonBirthday personBirthday, Models.PersonName personName, List<string>? individualsLines, bool isDefaultName, string directory, Models.GenealogicalDataCommunication? genealogicalDataCommunication, bool verify)
|
||||
internal static void WriteFile(string personKeyFormatted, Models.PersonName personName, List<string>? individualsLines, bool isDefaultName, string directory, Models.GenealogicalDataCommunication genealogicalDataCommunication, bool verify, bool first)
|
||||
{
|
||||
char sex;
|
||||
bool alive;
|
||||
bool first;
|
||||
if (personKeyFormatted[^2..] is "15")
|
||||
(sex, alive, first) = ('M', false, true);
|
||||
else if (personKeyFormatted[^2..] is "14")
|
||||
(sex, alive, first) = ('F', false, true);
|
||||
else if (personKeyFormatted[^2..] is "05")
|
||||
(sex, alive, first) = ('M', true, true);
|
||||
else if (personKeyFormatted[^2..] is "04")
|
||||
(sex, alive, first) = ('F', true, true);
|
||||
else if (personKeyFormatted[^2..] is "23" or "21" or "19" or "17")
|
||||
(sex, alive, first) = ('M', false, false);
|
||||
else if (personKeyFormatted[^2..] is "22" or "20" or "18" or "16")
|
||||
(sex, alive, first) = ('F', false, false);
|
||||
else if (personKeyFormatted[^2..] is "13" or "11" or "09" or "07")
|
||||
(sex, alive, first) = ('M', true, false);
|
||||
else if (personKeyFormatted[^2..] is "12" or "10" or "08" or "06")
|
||||
(sex, alive, first) = ('F', true, false);
|
||||
else
|
||||
(sex, alive, first) = ('U', true, false);
|
||||
if (verify && genealogicalDataCommunication is not null)
|
||||
if (verify)
|
||||
{
|
||||
if (genealogicalDataCommunication.SurName != personName.Last.Value)
|
||||
throw new Exception($"{genealogicalDataCommunication.Name} - {personKeyFormatted}");
|
||||
if (genealogicalDataCommunication.Sex != sex)
|
||||
throw new Exception($"{genealogicalDataCommunication.Name} - {personKeyFormatted}");
|
||||
if (genealogicalDataCommunication.Death is not null && alive || genealogicalDataCommunication.Death is null && !alive)
|
||||
throw new Exception($"{genealogicalDataCommunication.Name} - {personKeyFormatted}");
|
||||
if (genealogicalDataCommunication.Birth is not null && genealogicalDataCommunication.Birth.Value.ToString("yyyy-MM-dd") != personBirthday.Value.ToString("yyyy-MM-dd"))
|
||||
throw new Exception($"{genealogicalDataCommunication.Name} - {personKeyFormatted}");
|
||||
}
|
||||
string jrOrSr;
|
||||
if (string.IsNullOrEmpty(personName.Alias.Value))
|
||||
@ -299,7 +278,7 @@ internal abstract class GenealogicalDataCommunication
|
||||
else
|
||||
jrOrSr = string.Empty;
|
||||
}
|
||||
string code = IPersonBirthday.GetHour(alive, sex).ToString("00");
|
||||
string code = IPersonBirthday.GetHour(genealogicalDataCommunication.Death is null, genealogicalDataCommunication.Sex).ToString("00");
|
||||
if (directory.EndsWith("00"))
|
||||
directory = string.Concat(directory[..^2], code);
|
||||
else if (directory.EndsWith("01"))
|
||||
@ -325,13 +304,17 @@ internal abstract class GenealogicalDataCommunication
|
||||
if (!string.IsNullOrEmpty(jrOrSr))
|
||||
pGedLines.Add($"2 NSFX {jrOrSr.Trim()}");
|
||||
pGedLines.Add($"2 NICK {personKeyFormatted}");
|
||||
pGedLines.Add($"1 SEX {sex}");
|
||||
if (!IPersonBirthday.IsCounterPersonBirthday(personBirthday))
|
||||
pGedLines.Add($"1 SEX {genealogicalDataCommunication.Sex}");
|
||||
if (genealogicalDataCommunication.Birth is not null)
|
||||
{
|
||||
pGedLines.Add("1 BIRT");
|
||||
pGedLines.Add($"2 DATE {personBirthday.Value:dd MMM yyyy}");
|
||||
Models.PersonBirthday personBirthday = new(genealogicalDataCommunication.Birth.Value);
|
||||
if (!IPersonBirthday.IsCounterPersonBirthday(personBirthday))
|
||||
{
|
||||
pGedLines.Add("1 BIRT");
|
||||
pGedLines.Add($"2 DATE {genealogicalDataCommunication.Birth.Value:dd MMM yyyy}");
|
||||
}
|
||||
}
|
||||
if (!alive)
|
||||
if (genealogicalDataCommunication.Death is not null)
|
||||
{
|
||||
if (genealogicalDataCommunication?.Death is null || genealogicalDataCommunication.Death == genealogicalDataCommunication.Birth || IPersonBirthday.IsCounterPersonBirthday(new(genealogicalDataCommunication.Death.Value)))
|
||||
pGedLines.Add("1 DEAT Y");
|
||||
|
Reference in New Issue
Block a user