CreateTree
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
using System.Text;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Person
|
||||
@ -15,7 +17,42 @@ internal abstract class Person
|
||||
return new(personBirthday, personKeyFormatted);
|
||||
}
|
||||
|
||||
internal static Models.Person GetPerson(long personKey, Models.PersonBirthday personBirthday, string[] segments)
|
||||
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())
|
||||
{
|
||||
StringBuilder stringBuilder = new();
|
||||
_ = stringBuilder.Append("0 @I").Append(personKeyFormatted).AppendLine("@ INDI");
|
||||
_ = stringBuilder.Append("1 NAME ").Append(name.First.Value).Append(" /").Append(name.Last.Value).AppendLine("/");
|
||||
if (!string.IsNullOrEmpty(name.First.Value))
|
||||
_ = stringBuilder.Append("2 GIVN ").AppendLine(name.First.Value);
|
||||
if (!string.IsNullOrEmpty(name.Last.Value))
|
||||
_ = stringBuilder.Append("2 SURN ").AppendLine(name.Last.Value);
|
||||
if (!string.IsNullOrEmpty(name.Alias.Value))
|
||||
{
|
||||
_ = stringBuilder.Append("2 NICK ").AppendLine(name.Alias.Value);
|
||||
if (name.Alias.Value.Contains(" Jr"))
|
||||
_ = stringBuilder.Append("2 NSFX ").AppendLine("Jr");
|
||||
else if (name.Alias.Value.Contains(" Sr"))
|
||||
_ = stringBuilder.Append("2 NSFX ").AppendLine("Sr");
|
||||
}
|
||||
_ = stringBuilder.AppendLine("1 SEX U");
|
||||
if (!IPersonBirthday.IsCounterPersonBirthday(personBirthday))
|
||||
{
|
||||
_ = stringBuilder.AppendLine("1 BIRT");
|
||||
_ = stringBuilder.Append("2 DATE ").AppendLine(personBirthday.Value.ToString("dd MMM yyyy"));
|
||||
}
|
||||
string? directory = Path.GetDirectoryName(matches[0]);
|
||||
if (directory is null)
|
||||
throw new Exception();
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
File.WriteAllText(Path.Combine(directory, $"{personKeyFormatted}.pged"), stringBuilder.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
internal static Models.Person GetPerson(string[] personDisplayDirectoryAllFiles, string? personKeyFormatted, long personKey, Models.PersonBirthday personBirthday, string[] segments)
|
||||
{
|
||||
Models.Person result;
|
||||
const int zero = 0;
|
||||
@ -26,6 +63,9 @@ internal abstract class Person
|
||||
List<Models.PersonComment> comments = new();
|
||||
List<Models.PersonAddress> 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 (matches.Any())
|
||||
WriteGedFile(personKeyFormatted, personBirthday, name, matches);
|
||||
result = new(id, personBirthday, name, comments, urls, numbers, emails, addresses);
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user