60 lines
3.1 KiB
C#
60 lines
3.1 KiB
C#
using System.Text.Json;
|
|
using View_by_Distance.Shared.Models;
|
|
|
|
namespace View_by_Distance.Instance.Models;
|
|
|
|
/// <summary>
|
|
// ?
|
|
/// </summary>
|
|
internal class A2_People
|
|
{
|
|
|
|
internal static void WriteAllText(Property.Models.Configuration configuration, string outputResolution, List<G2_Identify> identifiedCollection)
|
|
{
|
|
string key;
|
|
string json;
|
|
string jsonFile;
|
|
FileInfo fileInfo;
|
|
string[] segments;
|
|
string directoryFullName;
|
|
Dictionary<string, List<G2_Identify>> keyValuePairs = new();
|
|
JsonSerializerOptions writeIndentedJsonSerializerOptions = new() { WriteIndented = true };
|
|
string a2PeopleCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A2_People), "[]");
|
|
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(Property.Models.A_Property), "{}");
|
|
foreach (G2_Identify identified in identifiedCollection)
|
|
{
|
|
fileInfo = new FileInfo(string.Concat(aPropertySingletonDirectory, identified.RelativePath));
|
|
if (fileInfo?.Directory is null || !fileInfo.Directory.Exists || fileInfo.Exists)
|
|
continue;
|
|
key = string.Concat(identified.ParentDirectoryName, '|', identified.Person);
|
|
if (!keyValuePairs.ContainsKey(key))
|
|
keyValuePairs.Add(key, new List<G2_Identify>());
|
|
keyValuePairs[key].Add(identified);
|
|
}
|
|
foreach (KeyValuePair<string, List<G2_Identify>> keyValuePair in keyValuePairs)
|
|
{
|
|
segments = keyValuePair.Key.Split('|');
|
|
directoryFullName = Path.Combine(a2PeopleCollectionDirectory, segments[0]);
|
|
if (!Directory.Exists(directoryFullName))
|
|
_ = Directory.CreateDirectory(directoryFullName);
|
|
jsonFile = Path.Combine(directoryFullName, $"{segments[1]}.json");
|
|
json = JsonSerializer.Serialize(keyValuePair.Value, writeIndentedJsonSerializerOptions);
|
|
if (!Shared.Models.Stateless.Methods.IPath.WriteAllText(jsonFile, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
|
continue;
|
|
}
|
|
}
|
|
|
|
internal static PersonContainer[] GetPersonContainers(Configuration configuration, Property.Models.Configuration propertyConfiguration, string facesFileNameExtension)
|
|
{
|
|
PersonContainer[] results;
|
|
string rootDirectory = propertyConfiguration.RootDirectory;
|
|
string peopleRootDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(A2_People));
|
|
string? rootResultsDirectory = Path.GetDirectoryName(Path.GetDirectoryName(peopleRootDirectory));
|
|
if (rootResultsDirectory is null)
|
|
throw new Exception();
|
|
Storage storage = new(rootDirectory, rootResultsDirectory, peopleRootDirectory);
|
|
results = Shared.Models.Stateless.Methods.IPersonContainer.GetPersonContainers(storage, configuration.LocationDigits, configuration.PersonBirthdayFormat, facesFileNameExtension);
|
|
return results;
|
|
}
|
|
|
|
} |