Move const usage out of Shared
This commit is contained in:
@ -8,7 +8,7 @@ internal abstract class Person
|
||||
|
||||
// ...
|
||||
|
||||
private static List<string> ValidatePerson(Properties.IStorage storage, Models.PersonId id, Models.PersonBirthday birthday, Models.PersonName name)
|
||||
private static List<string> ValidatePerson(Properties.IStorage storage, string personBirthdayFormat, Models.PersonId id, Models.PersonBirthday birthday, Models.PersonName name)
|
||||
{
|
||||
List<string> results = new();
|
||||
if (birthday is null)
|
||||
@ -21,18 +21,18 @@ internal abstract class Person
|
||||
results.Add("Id must be Birthday ticks!");
|
||||
if (name.First is null || string.IsNullOrEmpty(name.First.Value))
|
||||
results.Add("Fist Name must be supplied!");
|
||||
if (PersonBirthday.DoesBirthDateExits(storage, birthday))
|
||||
if (PersonBirthday.DoesBirthDateExits(storage, personBirthdayFormat, birthday))
|
||||
results.Add("BirthDate already exits!");
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static Models.Person CreatePerson(Properties.IStorage storage, Models.PersonBirthday birthday, Models.PersonName name, List<Models.PersonComment> comments, List<Models.PersonURL> urls, List<Models.PersonNumber> numbers, List<Models.PersonEmail> emails, List<Models.PersonAddress> addresses)
|
||||
internal static Models.Person CreatePerson(Properties.IStorage storage, string personBirthdayFormat, Models.PersonBirthday birthday, Models.PersonName name, List<Models.PersonComment> comments, List<Models.PersonURL> urls, List<Models.PersonNumber> numbers, List<Models.PersonEmail> emails, List<Models.PersonAddress> addresses)
|
||||
{
|
||||
Models.Person result;
|
||||
Models.PersonId id = new(birthday.Value.Ticks);
|
||||
if (birthday.Value == DateTime.MinValue)
|
||||
birthday = PersonBirthday.GetNextBirthDate(storage);
|
||||
List<string> results = ValidatePerson(storage, id, birthday, name);
|
||||
List<string> results = ValidatePerson(storage, personBirthdayFormat, id, birthday, name);
|
||||
if (results.Any())
|
||||
throw new Exception(string.Join(Environment.NewLine, results));
|
||||
if (comments is null)
|
||||
@ -61,12 +61,12 @@ internal abstract class Person
|
||||
}
|
||||
}
|
||||
|
||||
internal static Dictionary<DateTime, string[]> Split(string knownPeopleFile)
|
||||
internal static Dictionary<DateTime, string[]> Split(int personBirthdayFirstYear, string personKeyFormat, string knownPeopleFile)
|
||||
{
|
||||
Dictionary<DateTime, string[]> results = new();
|
||||
string[] segments;
|
||||
DateTime personKey;
|
||||
DateTime incrementDate = new(Stateless.IPersonBirthday.FirstYear, 1, 1);
|
||||
DateTime incrementDate = new(personBirthdayFirstYear, 1, 1);
|
||||
string[] lines = File.ReadAllLines(knownPeopleFile);
|
||||
_ = incrementDate.AddDays(lines.Length);
|
||||
System.Globalization.CultureInfo cultureInfo = System.Globalization.CultureInfo.InvariantCulture;
|
||||
@ -77,8 +77,8 @@ internal abstract class Person
|
||||
segments = line.Replace(" //", "\t//").Split('\t');
|
||||
if (segments.Length < 1)
|
||||
continue;
|
||||
SetSegments(ref segments, Stateless.IPerson.KeyFormat, ref incrementDate);
|
||||
personKey = DateTime.ParseExact(segments[0], Stateless.IPerson.KeyFormat, cultureInfo);
|
||||
SetSegments(ref segments, personKeyFormat, ref incrementDate);
|
||||
personKey = DateTime.ParseExact(segments[0], personKeyFormat, cultureInfo);
|
||||
if (results.ContainsKey(personKey))
|
||||
continue;
|
||||
results.Add(personKey, segments);
|
||||
@ -90,7 +90,7 @@ internal abstract class Person
|
||||
for (int i = 1; i < (1000 - countBefore); i++)
|
||||
{
|
||||
personKey = minimumDateTime.AddDays(i * -1);
|
||||
results.Add(personKey, new string[] { personKey.ToString(Stateless.IPerson.KeyFormat) });
|
||||
results.Add(personKey, new string[] { personKey.ToString(personKeyFormat) });
|
||||
}
|
||||
}
|
||||
return results.OrderBy(l => l.Key).ToDictionary(l => l.Key, l => l.Value);
|
||||
@ -118,7 +118,7 @@ internal abstract class Person
|
||||
SetValues(ref name, ref comment, ref mergeName, splitLine);
|
||||
}
|
||||
|
||||
private static Dictionary<DateTime, PersonImport> GetPersonCollection(string knownPeopleFile)
|
||||
private static Dictionary<DateTime, PersonImport> GetPersonCollection(int personBirthdayFirstYear, string personKeyFormat, string knownPeopleFile)
|
||||
{
|
||||
Dictionary<DateTime, PersonImport> results = new();
|
||||
string name;
|
||||
@ -127,7 +127,7 @@ internal abstract class Person
|
||||
string oldName;
|
||||
string mergeName;
|
||||
PersonImport person;
|
||||
Dictionary<DateTime, string[]> splitLines = Split(knownPeopleFile);
|
||||
Dictionary<DateTime, string[]> splitLines = Split(personBirthdayFirstYear, personKeyFormat, knownPeopleFile);
|
||||
foreach (KeyValuePair<DateTime, string[]> splitLine in splitLines)
|
||||
{
|
||||
name = string.Empty;
|
||||
@ -142,9 +142,9 @@ internal abstract class Person
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static void SavePerson(Properties.IStorage storage, Models.Person person)
|
||||
internal static void SavePerson(Properties.IStorage storage, string personBirthdayFormat, Models.Person person)
|
||||
{
|
||||
string fileName = IPerson.GetFileFullName(storage, person);
|
||||
string fileName = IPerson.GetFileFullName(storage, personBirthdayFormat, person);
|
||||
string json = JsonSerializer.Serialize(person, new JsonSerializerOptions { WriteIndented = true });
|
||||
_ = IStorage.WriteAllText(fileName, json, updateDateWhenMatches: true, compareBeforeWrite: true);
|
||||
}
|
||||
@ -162,7 +162,7 @@ internal abstract class Person
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<Models.Person> GetPeopleFromText(Properties.IStorage storage, string localKnownPeopleFile)
|
||||
private static List<Models.Person> GetPeopleFromText(Properties.IStorage storage, int personBirthdayFirstYear, string personBirthdayFormat, string personKeyFormat, string localKnownPeopleFile)
|
||||
{
|
||||
List<Models.Person> results = new();
|
||||
string comment;
|
||||
@ -174,7 +174,7 @@ internal abstract class Person
|
||||
List<Models.PersonEmail> emails = new();
|
||||
List<Models.PersonNumber> numbers = new();
|
||||
List<Models.PersonAddress> addresses = new();
|
||||
Dictionary<DateTime, PersonImport> keyValuePairs = GetPersonCollection(localKnownPeopleFile);
|
||||
Dictionary<DateTime, PersonImport> keyValuePairs = GetPersonCollection(personBirthdayFirstYear, personKeyFormat, localKnownPeopleFile);
|
||||
foreach (KeyValuePair<DateTime, PersonImport> keyValuePair in keyValuePairs)
|
||||
{
|
||||
if (string.IsNullOrEmpty(keyValuePair.Value.Name))
|
||||
@ -189,14 +189,14 @@ internal abstract class Person
|
||||
comment = GetComment(urls, comments, keyValuePair);
|
||||
if (!string.IsNullOrEmpty(keyValuePair.Value.OldName))
|
||||
comments.Add(new(new(keyValuePair.Value.OldName)));
|
||||
person = IPerson.CreatePerson(storage, birthday, name, comments, urls, numbers, emails, addresses);
|
||||
SavePerson(storage, person);
|
||||
person = IPerson.CreatePerson(storage, personBirthdayFormat, birthday, name, comments, urls, numbers, emails, addresses);
|
||||
SavePerson(storage, personBirthdayFormat, person);
|
||||
results.Add(person);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static Models.Person[] GetPeople(Properties.IStorage storage)
|
||||
internal static Models.Person[] GetPeople(Properties.IStorage storage, int personBirthdayFirstYear, string personBirthdayFormat, string personKeyFormat)
|
||||
{
|
||||
List<Models.Person> results = new();
|
||||
string json;
|
||||
@ -234,7 +234,7 @@ internal abstract class Person
|
||||
results.Add(person);
|
||||
}
|
||||
if (!results.Any())
|
||||
results = GetPeopleFromText(storage, localKnownPeopleFile);
|
||||
results = GetPeopleFromText(storage, personBirthdayFirstYear, personBirthdayFormat, personKeyFormat, localKnownPeopleFile);
|
||||
else if (!string.IsNullOrEmpty(localKnownPeopleFile))
|
||||
{
|
||||
fileInfo = new FileInfo(localKnownPeopleFile);
|
||||
@ -242,14 +242,14 @@ internal abstract class Person
|
||||
{
|
||||
foreach (string file in files)
|
||||
File.Delete(file);
|
||||
results = GetPeopleFromText(storage, localKnownPeopleFile);
|
||||
results = GetPeopleFromText(storage, personBirthdayFirstYear, personBirthdayFormat, personKeyFormat, localKnownPeopleFile);
|
||||
}
|
||||
}
|
||||
SaveToDirectory(storage, results);
|
||||
SaveToDirectory(storage, personBirthdayFormat, results);
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
private static void SaveToDirectory(Properties.IStorage storage, List<Models.Person> people)
|
||||
private static void SaveToDirectory(Properties.IStorage storage, string personBirthdayFormat, List<Models.Person> people)
|
||||
{
|
||||
int years;
|
||||
TimeSpan? timeSpan;
|
||||
@ -265,7 +265,7 @@ internal abstract class Person
|
||||
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
|
||||
foreach (Models.Person person in people)
|
||||
{
|
||||
personJsonFileName = IPerson.GetFileFullName(storage, person);
|
||||
personJsonFileName = IPerson.GetFileFullName(storage, personBirthdayFormat, person);
|
||||
if (string.IsNullOrEmpty(peopleDirectory))
|
||||
peopleDirectory = Path.GetDirectoryName(personJsonFileName);
|
||||
if (string.IsNullOrEmpty(peopleDirectory))
|
||||
|
Reference in New Issue
Block a user