Person Require People File

This commit is contained in:
2022-09-17 11:25:02 -07:00
parent 1ec9b7673d
commit 9ec5da1e7a
12 changed files with 125 additions and 127 deletions

View File

@ -10,10 +10,10 @@ public interface IPerson
static Dictionary<DateTime, string[]> Split(int personBirthdayFirstYear, string personKeyFormat, string knownPeopleFile) =>
Person.Split(personBirthdayFirstYear, personKeyFormat, knownPeopleFile);
Models.Person[] TestStatic_GetPeople(Properties.IStorage storage, int personBirthdayFirstYear, string personBirthdayFormat, string personKeyFormat) =>
GetPeople(storage, personBirthdayFirstYear, personBirthdayFormat, personKeyFormat);
static Models.Person[] GetPeople(Properties.IStorage storage, int personBirthdayFirstYear, string personBirthdayFormat, string personKeyFormat) =>
Person.GetPeople(storage, personBirthdayFirstYear, personBirthdayFormat, personKeyFormat);
Models.Person[] TestStatic_GetPeople(Properties.IStorage storage, int personBirthdayFirstYear, string personBirthdayFormat, string personKeyFormat, bool personRequirePeopleFile) =>
GetPeople(storage, personBirthdayFirstYear, personBirthdayFormat, personKeyFormat, personRequirePeopleFile);
static Models.Person[] GetPeople(Properties.IStorage storage, int personBirthdayFirstYear, string personBirthdayFormat, string personKeyFormat, bool personRequirePeopleFile) =>
Person.GetPeople(storage, personBirthdayFirstYear, personBirthdayFormat, personKeyFormat, personRequirePeopleFile);
void TestStatic_SavePerson(Properties.IStorage storage, string personBirthdayFormat, Models.Person person) =>
SavePerson(storage, personBirthdayFormat, person);

View File

@ -196,7 +196,7 @@ internal abstract class Person
return results;
}
internal static Models.Person[] GetPeople(Properties.IStorage storage, int personBirthdayFirstYear, string personBirthdayFormat, string personKeyFormat)
internal static Models.Person[] GetPeople(Properties.IStorage storage, int personBirthdayFirstYear, string personBirthdayFormat, string personKeyFormat, bool personRequirePeopleFile)
{
List<Models.Person> results = new();
string json;
@ -210,18 +210,15 @@ internal abstract class Person
if (!Directory.Exists(peopleSingletonDirectory))
_ = Directory.CreateDirectory(peopleSingletonDirectory);
if (!Directory.Exists(peopleContentDirectory))
localKnownPeopleFile = string.Empty;
else
{
files = Directory.GetFiles(peopleContentDirectory, "*People*.txt", SearchOption.TopDirectoryOnly);
if (files.Any())
localKnownPeopleFile = files[0];
else
localKnownPeopleFile = string.Empty;
}
files = Directory.GetFiles(peopleSingletonDirectory, "*.json", SearchOption.TopDirectoryOnly);
if (!files.Any() && string.IsNullOrEmpty(localKnownPeopleFile))
_ = Directory.CreateDirectory(peopleContentDirectory);
files = Directory.GetFiles(peopleContentDirectory, "*People*.txt", SearchOption.TopDirectoryOnly);
if (!files.Any() && personRequirePeopleFile)
throw new Exception("Copy \"KnownPeople.txt\" file from server!");
if (files.Any())
localKnownPeopleFile = files[0];
else
localKnownPeopleFile = string.Empty;
files = Directory.GetFiles(peopleSingletonDirectory, "*.json", SearchOption.TopDirectoryOnly);
foreach (string file in files)
{
fileInfo = new(file);