Moved more to Map library

This commit is contained in:
2022-08-29 08:45:01 -07:00
parent 674555b4fc
commit c1d30b5bbc
46 changed files with 1631 additions and 697 deletions

View File

@ -1,4 +1,5 @@
using System.Text.Json;
using System.Text.RegularExpressions;
namespace View_by_Distance.Shared.Models.Stateless.Methods;
@ -166,9 +167,9 @@ internal abstract class Person
Models.PersonName name;
List<Models.PersonURL> urls;
Models.PersonBirthday birthday;
List<Models.PersonComment> comments;
List<Models.PersonEmail> emails = new();
List<Models.PersonNumber> numbers = new();
List<Models.PersonComment> comments = new();
List<Models.PersonAddress> addresses = new();
Dictionary<DateTime, PersonImport> keyValuePairs = GetPersonCollection(localKnownPeopleFile);
foreach (KeyValuePair<DateTime, PersonImport> keyValuePair in keyValuePairs)
@ -176,6 +177,7 @@ internal abstract class Person
if (string.IsNullOrEmpty(keyValuePair.Value.Name))
continue;
urls = new();
comments = new();
birthday = new(keyValuePair.Key);
name = PersonName.Create(keyValuePair.Value.Name);
if (name.First is null || string.IsNullOrEmpty(name.First.Value))
@ -242,7 +244,54 @@ internal abstract class Person
results = GetPeopleFromText(storage, localKnownPeopleFile);
}
}
SaveToDirectory(storage, results);
return results.ToArray();
}
private static void SaveToDirectory(Properties.IStorage storage, List<Models.Person> people)
{
int years;
TimeSpan? timeSpan;
string personDirectory;
string? personFullName;
DateTime createdDateTime;
string birthdayDirectory;
string personJsonFileName;
string personDirectoryName;
string? peopleDirectory = null;
DateTime dateTime = DateTime.Now;
string? personJsonFileNameWithoutExtension;
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
foreach (Models.Person person in people)
{
personJsonFileName = IPerson.GetFileFullName(storage, person);
if (string.IsNullOrEmpty(peopleDirectory))
peopleDirectory = Path.GetDirectoryName(personJsonFileName);
if (string.IsNullOrEmpty(peopleDirectory))
break;
personJsonFileNameWithoutExtension = Path.GetFileNameWithoutExtension(personJsonFileName);
if (string.IsNullOrEmpty(personJsonFileNameWithoutExtension))
break;
personFullName = Regex.Replace(person.GetFullName(), pattern, string.Empty);
timeSpan = IPersonBirthday.GetTimeSpan(dateTime, person.Birthday);
if (timeSpan is null || timeSpan.Value.Ticks < 0)
personDirectoryName = $"{personFullName}~";
else
{
createdDateTime = new FileInfo(personJsonFileName).CreationTime;
(years, timeSpan) = IPersonBirthday.GetAge(createdDateTime, person.Birthday);
personDirectoryName = $"{personFullName}^{years}-{Math.Floor(timeSpan.Value.TotalDays):000}";
}
personDirectory = Path.Combine(peopleDirectory, personDirectoryName);
if (!Directory.Exists(personDirectory))
_ = Directory.CreateDirectory(personDirectory);
birthdayDirectory = Path.Combine(personDirectory, personJsonFileNameWithoutExtension);
if (!Directory.Exists(birthdayDirectory))
{
_ = Directory.CreateDirectory(birthdayDirectory);
File.Copy(personJsonFileName, Path.Combine(birthdayDirectory, $"{personJsonFileNameWithoutExtension}.json"));
}
}
}
}