Use shared before local

This commit is contained in:
2023-04-01 13:56:11 -07:00
parent d3794bf9cc
commit 5c3a151cd3
4 changed files with 33 additions and 24 deletions

View File

@ -68,23 +68,22 @@ public class Person
string fileName;
Task<byte[]> task;
int age;
int hours;
bool alive;
string json;
string code;
string? day;
string alias;
string? line;
string? year;
string? month;
bool deceased;
ConsoleKey sex;
long personKey;
string? lastName;
string[] segments;
string middleName;
string? firstName;
DateTime? dateTime;
PersonName personName;
string checkDirectory;
PersonName? personName;
DateTime parseDateTime;
ConsoleKey? consoleKey;
string? approximateYears;
@ -93,6 +92,7 @@ public class Person
log.Information($"Ready to create / update a person? [{ticks}]");
for (int y = 0; y < int.MaxValue; y++)
{
personName = null;
log.Information("Press \"Y\" key to continue, \"N\" key exit or close console");
consoleKey = System.Console.ReadKey().Key;
log.Information(". . .");
@ -116,11 +116,12 @@ public class Person
lastName = null;
for (int f = 0; f < 5; f++)
{
segments = firstName.Split(' ');
if (segments.Length > 1)
lastName = segments[^1];
personName = IPerson.GetPersonName(firstName);
if (!string.IsNullOrEmpty(personName.First.Value) && !string.IsNullOrEmpty(personName.Last.Value))
lastName = personName.Last.Value;
else
{
personName = null;
log.Information("Enter persons last name (minimum length of two characters)");
line = System.Console.ReadLine();
log.Information(". . .");
@ -132,9 +133,8 @@ public class Person
}
if (lastName is null)
continue;
segments = firstName.Split(' ');
if (segments.Length > 2)
middleName = segments[1];
if (personName is not null)
middleName = personName.Middle.Value;
else
{
log.Information("Enter persons middle name (press enter if they don't have a middle name)");
@ -146,7 +146,7 @@ public class Person
line = System.Console.ReadLine();
log.Information(". . .");
alias = string.IsNullOrEmpty(line) ? string.Empty : line;
personName = new(new(firstName), new(middleName), new(lastName), new(alias));
personName ??= new(new(firstName), new(middleName), new(lastName), new(alias));
json = JsonSerializer.Serialize(personName, new JsonSerializerOptions { WriteIndented = true });
log.Information("Is the person \"M\" (Male), \"F\" (Female) or \"U\" (Unknown)");
consoleKey = System.Console.ReadKey().Key;
@ -154,12 +154,12 @@ public class Person
if (consoleKey is not ConsoleKey.M and not ConsoleKey.F and not ConsoleKey.U)
continue;
sex = consoleKey.Value;
log.Information("Is the person deceased \"Y\" or \"N\"");
log.Information("Is the person alive \"Y\" or \"N\"");
consoleKey = System.Console.ReadKey().Key;
log.Information(". . .");
if (consoleKey is not ConsoleKey.Y and not ConsoleKey.N)
continue;
deceased = consoleKey == ConsoleKey.Y;
alive = consoleKey == ConsoleKey.Y;
dateTime = null;
approximateYears = null;
for (int f = 0; f < 5; f++)
@ -259,12 +259,9 @@ public class Person
personKeyFormatted = "2";
else
{
personKey = dateTime.Value.Ticks;
if (deceased)
code = sex is ConsoleKey.M ? "05" : sex is ConsoleKey.F ? "04" : sex is ConsoleKey.U ? "02" : throw new NotImplementedException();
else
code = sex is ConsoleKey.M ? "15" : sex is ConsoleKey.F ? "14" : sex is ConsoleKey.U ? "03" : throw new NotImplementedException();
personKeyFormatted = $"{IPersonBirthday.GetFormatted(_Configuration.PersonBirthdayFormat, personKey)[..^2]}{code}";
hours = IPersonBirthday.GetHour(alive, sex);
personKey = dateTime.Value.AddHours(hours).Ticks;
personKeyFormatted = IPersonBirthday.GetFormatted(_Configuration.PersonBirthdayFormat, personKey);
}
checkDirectory = Path.Combine(personDisplayDirectory, personKeyFormatted);
log.Information($"Working directory <{checkDirectory}>");