namespace View_by_Distance.Shared.Models.Stateless.Methods; internal abstract class Person { // ... internal static (Models.PersonBirthday?, string) Get(string personBirthdayFormat, string personDisplayDirectory, string personKeyDirectory, DateTime birthday) { Models.PersonBirthday? personBirthday = new(birthday); string personKeyFormatted = IPersonBirthday.GetFormatted(personBirthdayFormat, personBirthday); string convertedPersonKeyDirectory = Path.Combine(personDisplayDirectory, personKeyFormatted); if (!Directory.Exists(convertedPersonKeyDirectory)) Directory.Move(personKeyDirectory, convertedPersonKeyDirectory); return new(personBirthday, personKeyFormatted); } private static void WriteGedFile(string personKeyFormatted, Models.PersonBirthday personBirthday, Models.PersonName name, string[] matches) { string[] pGedFiles = (from l in matches where l.EndsWith(".pged") select l).ToArray(); if (!pGedFiles.Any()) { string? directory = Path.GetDirectoryName(matches[0]); if (directory is null) throw new Exception(); string? sexLine; string? deathLine = null; string nameLine = $"1 NAME {name.First.Value} /{name.Last.Value}/"; if (personKeyFormatted[^2..] is "23" or "21" or "19" or "17" or "15") { sexLine = "1 SEX M"; deathLine = "1 DEAT Y"; } else if (personKeyFormatted[^2..] is "22" or "20" or "18" or "16" or "14") { sexLine = "1 SEX F"; deathLine = "1 DEAT Y"; } else if (personKeyFormatted[^2..] is "13" or "11" or "09" or "07" or "05") sexLine = "1 SEX M"; else if (personKeyFormatted[^2..] is "12" or "10" or "08" or "06" or "04") sexLine = "1 SEX F"; else { sexLine = null; // string[] sourceLines = File.ReadAllLines("D:/1) Images A/Images-9b89679-Results/A2) People/9b89679/([])/FamilyEcho/638157228251558818-RootsMagic-Export.ged"); string[] sourceLines = File.ReadAllLines("D:/1) Images A/Images-9b89679-Results/A2) People/9b89679/([])/638157314010628679.ged"); for (int i = 0; i < sourceLines.Length; i++) { if (sourceLines[i] != nameLine) continue; for (int j = i + 1; j < sourceLines.Length; j++) { i = j; if (sourceLines[j].StartsWith("0 @I")) break; if (sourceLines[j].StartsWith("1 SEX ")) sexLine = sourceLines[j]; else if (sourceLines[j].StartsWith("1 DEAT ")) deathLine = sourceLines[j]; } } if (sexLine is null) sexLine = "1 SEX U"; else { string sex; if (deathLine is null or not "1 DEAT Y") sex = sexLine[6] is 'M' ? "05" : sexLine[6] is 'F' ? "04" : sexLine[6] is 'U' ? "02" : throw new NotImplementedException(); else sex = sexLine[6] is 'M' ? "15" : sexLine[6] is 'F' ? "14" : sexLine[6] is 'U' ? "03" : throw new NotImplementedException(); if (directory.EndsWith("00")) directory = string.Concat(directory[..^2], sex); else if (directory.EndsWith("01")) directory = string.Concat(directory[..^2], sex); // else if (directory.EndsWith("04")) // Cameran // directory = string.Concat(directory[..^2], sex); // else if (directory.EndsWith("05")) // Daisy // directory = string.Concat(directory[..^2], sex); // else if (directory.EndsWith("18")) // Meghan // directory = string.Concat(directory[..^2], sex); // else if (directory.EndsWith("20")) // Joey // directory = string.Concat(directory[..^2], sex); else throw new NotImplementedException(); personKeyFormatted = $"{personKeyFormatted[..^2]}{sex}"; } } List pGedLines = new() { $"0 @I{personKeyFormatted}@ INDI", nameLine }; if (!string.IsNullOrEmpty(name.First.Value)) pGedLines.Add($"2 GIVN {name.First.Value}"); if (!string.IsNullOrEmpty(name.Last.Value)) pGedLines.Add($"2 SURN {name.Last.Value}"); if (!string.IsNullOrEmpty(name.Alias.Value)) { pGedLines.Add($"2 NICK {name.Alias.Value}"); if (name.Alias.Value.Contains(" Jr")) pGedLines.Add("2 NSFX Jr"); else if (name.Alias.Value.Contains(" Sr")) pGedLines.Add("2 NSFX Sr"); } pGedLines.Add(sexLine); if (!string.IsNullOrEmpty(deathLine)) pGedLines.Add(deathLine); if (!IPersonBirthday.IsCounterPersonBirthday(personBirthday)) { pGedLines.Add("1 BIRT"); pGedLines.Add($"2 DATE {personBirthday.Value:dd MMM yyyy}"); } if (!Directory.Exists(directory)) _ = Directory.CreateDirectory(directory); string text = string.Join(Environment.NewLine, pGedLines); _ = IPath.WriteAllText(Path.Combine(directory, $"{personKeyFormatted}.pged"), text, updateDateWhenMatches: false, compareBeforeWrite: true); } } internal static Models.Person GetPerson(string[] personDisplayDirectoryAllFiles, string? personKeyFormatted, long personKey, Models.PersonBirthday personBirthday, string[] segments) { Models.Person result; const int zero = 0; List urls = new(); Models.PersonId id = new(personKey); List emails = new(); List numbers = new(); List comments = new(); List addresses = new(); Models.PersonName name = PersonName.Create(segments[zero]); string[] matches = (from l in personDisplayDirectoryAllFiles where !string.IsNullOrEmpty(personKeyFormatted) && l.Contains(personKeyFormatted) select l).ToArray(); if (!string.IsNullOrEmpty(personKeyFormatted) && matches.Any()) WriteGedFile(personKeyFormatted, personBirthday, name, matches); result = new(id, personBirthday, name, comments, urls, numbers, emails, addresses); return result; } }