|
|
|
@ -1,4 +1,3 @@
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using View_by_Distance.Property.Models;
|
|
|
|
|
using View_by_Distance.Shared.Models;
|
|
|
|
@ -10,9 +9,8 @@ namespace View_by_Distance.Map.Models;
|
|
|
|
|
public class MapLogic
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
protected readonly List<long> _NotMappedTicks;
|
|
|
|
|
protected readonly List<double> _SkipCollection;
|
|
|
|
|
protected readonly List<(int, string[])> _AllCollection;
|
|
|
|
|
protected readonly List<long> _NotMappedPersonKeys;
|
|
|
|
|
protected readonly Dictionary<int, int[]> _KeyValuePairs;
|
|
|
|
|
protected readonly Dictionary<int, int[]> _IndicesFromNew;
|
|
|
|
|
protected readonly Dictionary<int, string[]> _SixCharacterNamedFaceInfo;
|
|
|
|
@ -38,7 +36,6 @@ public class MapLogic
|
|
|
|
|
public MapLogic(int maxDegreeOfParallelism, Configuration configuration, string resizeFilenameExtension, string facesFilenameExtension, string facesHiddenFilenameExtension, string facePartsFilenameExtension, long ticks, Person[] people, string peopleDateGroupDirectory, string zResultsFullGroupDirectory)
|
|
|
|
|
{
|
|
|
|
|
_Ticks = ticks;
|
|
|
|
|
_AllCollection = new();
|
|
|
|
|
_Configuration = configuration;
|
|
|
|
|
_Log = Serilog.Log.ForContext<MapLogic>();
|
|
|
|
|
_FacesFilenameExtension = facesFilenameExtension;
|
|
|
|
@ -130,7 +127,7 @@ public class MapLogic
|
|
|
|
|
_KeyValuePairs = keyValuePairs;
|
|
|
|
|
_IndicesFromNew = indicesFromNew;
|
|
|
|
|
_SkipCollection = skipCollection;
|
|
|
|
|
_NotMappedTicks = notMappedTicks;
|
|
|
|
|
_NotMappedPersonKeys = notMappedTicks;
|
|
|
|
|
_PeopleKeyValuePairs = peopleKeyValuePairs;
|
|
|
|
|
_SixCharacterNamedFaceInfo = sixCharacterNamedFaceInfo;
|
|
|
|
|
_ZPropertyHolderContentDirectory = zPropertyHolderContentDirectory;
|
|
|
|
@ -175,8 +172,8 @@ public class MapLogic
|
|
|
|
|
{
|
|
|
|
|
string fileName;
|
|
|
|
|
string fullName;
|
|
|
|
|
string personKey;
|
|
|
|
|
DateTime minimumDateTime;
|
|
|
|
|
string personKeyFormatted;
|
|
|
|
|
PersonBirthday personBirthday;
|
|
|
|
|
WindowsShortcut windowsShortcut;
|
|
|
|
|
(string DisplayDirectoryName, int? ApproximateYears, PersonBirthday[] _, long Ticks) person;
|
|
|
|
@ -205,8 +202,8 @@ public class MapLogic
|
|
|
|
|
if (ticks is null)
|
|
|
|
|
continue;
|
|
|
|
|
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(ticks.Value);
|
|
|
|
|
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
|
|
|
|
if (juliePhares.Contains(personKey) && !string.IsNullOrEmpty(copyDirectory))
|
|
|
|
|
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
|
|
|
|
if (juliePhares.Contains(personKeyFormatted) && !string.IsNullOrEmpty(copyDirectory))
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(copyDirectory))
|
|
|
|
|
_ = Directory.CreateDirectory(copyDirectory);
|
|
|
|
@ -227,28 +224,26 @@ public class MapLogic
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UseKeyValuePairsSaveFaceEncoding(Container[] containers)
|
|
|
|
|
public void UseKeyValuePairsSaveFaceEncoding(Item[] items)
|
|
|
|
|
{
|
|
|
|
|
Dictionary<int, List<Face>> keyValuePairs = new();
|
|
|
|
|
List<(PersonBirthday PersonBirthday, double IdAndNormalizedPixelPercentage)> deterministicHashCodeCollection = new();
|
|
|
|
|
List<(PersonBirthday PersonBirthday, double IdAndNormalizedPixelPercentage)> incorrectDeterministicHashCodeCollection = new();
|
|
|
|
|
foreach (Container container in containers)
|
|
|
|
|
foreach (Item item in items)
|
|
|
|
|
{
|
|
|
|
|
foreach (Item item in container.Items)
|
|
|
|
|
if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null)
|
|
|
|
|
continue;
|
|
|
|
|
if (!item.Faces.Any())
|
|
|
|
|
continue;
|
|
|
|
|
if (keyValuePairs.ContainsKey(item.Property.Id.Value))
|
|
|
|
|
{
|
|
|
|
|
if (item.ImageFileHolder is null || item.Property?.Id is null || !item.Faces.Any())
|
|
|
|
|
continue;
|
|
|
|
|
if (keyValuePairs.ContainsKey(item.Property.Id.Value))
|
|
|
|
|
{
|
|
|
|
|
if (keyValuePairs[item.Property.Id.Value].Count != item.Faces.Count)
|
|
|
|
|
throw new Exception();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
keyValuePairs.Add(item.Property.Id.Value, item.Faces);
|
|
|
|
|
if (keyValuePairs[item.Property.Id.Value].Count != item.Faces.Count)
|
|
|
|
|
throw new Exception();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
keyValuePairs.Add(item.Property.Id.Value, item.Faces);
|
|
|
|
|
}
|
|
|
|
|
Stateless.ByDeterministicHashCode.SetKeyValuePairs(_ZPropertyHolderContentDirectory, deterministicHashCodeCollection, incorrectDeterministicHashCodeCollection, keyValuePairs);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
@ -268,64 +263,27 @@ public class MapLogic
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddToMapLogicAllCollection(Item[] filteredItems)
|
|
|
|
|
public static void AppendToItems(List<Item> items, List<(int, Item)> idAndItemCollection)
|
|
|
|
|
{
|
|
|
|
|
if (_SixCharacterNamedFaceInfo.Any())
|
|
|
|
|
foreach (Item item in items)
|
|
|
|
|
{
|
|
|
|
|
string[] keys;
|
|
|
|
|
Item item;
|
|
|
|
|
for (int i = 0; i < filteredItems.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
item = filteredItems[i];
|
|
|
|
|
if (item.Property?.Id is null)
|
|
|
|
|
continue;
|
|
|
|
|
foreach (int sixCharacterIndex in item.Property.Indices)
|
|
|
|
|
{
|
|
|
|
|
if (!_SixCharacterNamedFaceInfo.ContainsKey(sixCharacterIndex))
|
|
|
|
|
continue;
|
|
|
|
|
keys = _SixCharacterNamedFaceInfo[sixCharacterIndex];
|
|
|
|
|
_AllCollection.Add(new(item.Property.Id.Value, keys));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null)
|
|
|
|
|
continue;
|
|
|
|
|
idAndItemCollection.Add(new(item.Property.Id.Value, item));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveAllCollection()
|
|
|
|
|
{
|
|
|
|
|
if (_AllCollection.Any())
|
|
|
|
|
{
|
|
|
|
|
string[] keys;
|
|
|
|
|
long ticks = DateTime.Now.Ticks;
|
|
|
|
|
string? rootDirectoryParent = Path.GetDirectoryName(_Configuration.RootDirectory);
|
|
|
|
|
if (string.IsNullOrEmpty(rootDirectoryParent))
|
|
|
|
|
throw new NullReferenceException(nameof(rootDirectoryParent));
|
|
|
|
|
Dictionary<int, string[]> namedFaceInfoDeterministicHashCodeIndices = new();
|
|
|
|
|
List<(int, string[])> allCollection = _AllCollection.OrderBy(l => l.Item1).ToList();
|
|
|
|
|
foreach ((int deterministicHashCode, string[] values) in allCollection)
|
|
|
|
|
{
|
|
|
|
|
if (namedFaceInfoDeterministicHashCodeIndices.ContainsKey(deterministicHashCode))
|
|
|
|
|
{
|
|
|
|
|
keys = namedFaceInfoDeterministicHashCodeIndices[deterministicHashCode];
|
|
|
|
|
if (JsonSerializer.Serialize(values) == JsonSerializer.Serialize(keys))
|
|
|
|
|
continue;
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
namedFaceInfoDeterministicHashCodeIndices.Add(deterministicHashCode, values);
|
|
|
|
|
}
|
|
|
|
|
string json = JsonSerializer.Serialize(namedFaceInfoDeterministicHashCodeIndices, new JsonSerializerOptions { WriteIndented = true });
|
|
|
|
|
string checkFile = Path.Combine(rootDirectoryParent, "NamedFaceInfoDeterministicHashCodeIndices.json");
|
|
|
|
|
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(checkFile, json, updateDateWhenMatches: true, compareBeforeWrite: true);
|
|
|
|
|
_ = LogDelta(ticks, new StackFrame().GetMethod()?.Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int AddToMapping(List<Item> items)
|
|
|
|
|
public int AddToMapping(long ticks, List<Item> items)
|
|
|
|
|
{
|
|
|
|
|
int result = 0;
|
|
|
|
|
long ticks;
|
|
|
|
|
long personKey;
|
|
|
|
|
Mapping mapping;
|
|
|
|
|
bool? isWrongYear;
|
|
|
|
|
bool forced = false;
|
|
|
|
|
int? approximateYears;
|
|
|
|
|
string mappingSegmentB;
|
|
|
|
|
DateTime minimumDateTime;
|
|
|
|
|
string personKeyFormatted;
|
|
|
|
|
string displayDirectoryName;
|
|
|
|
|
PersonBirthday personBirthday;
|
|
|
|
|
double deterministicHashCodeKey;
|
|
|
|
@ -333,9 +291,7 @@ public class MapLogic
|
|
|
|
|
(string DisplayDirectoryName, int? ApproximateYears, PersonBirthday[] PersonBirthdays, long Ticks) person;
|
|
|
|
|
foreach (Item item in items)
|
|
|
|
|
{
|
|
|
|
|
if (item.ImageFileHolder is null)
|
|
|
|
|
continue;
|
|
|
|
|
if (item.Property?.Id is null || item.ResizedFileHolder is null)
|
|
|
|
|
if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null)
|
|
|
|
|
continue;
|
|
|
|
|
foreach (Face face in item.Faces)
|
|
|
|
|
{
|
|
|
|
@ -351,14 +307,18 @@ public class MapLogic
|
|
|
|
|
personBirthdays.AddRange(_DeterministicHashCodeKeyValuePairs[deterministicHashCodeKey]);
|
|
|
|
|
for (int i = 0; i < personBirthdays.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
ticks = personBirthdays[i].Value.Ticks;
|
|
|
|
|
if (!_PeopleKeyValuePairs.ContainsKey(ticks))
|
|
|
|
|
personKey = personBirthdays[i].Value.Ticks;
|
|
|
|
|
if (!_PeopleKeyValuePairs.ContainsKey(personKey))
|
|
|
|
|
continue;
|
|
|
|
|
person = _PeopleKeyValuePairs[ticks];
|
|
|
|
|
person = _PeopleKeyValuePairs[personKey];
|
|
|
|
|
personBirthday = person.PersonBirthdays[0];
|
|
|
|
|
approximateYears = person.ApproximateYears;
|
|
|
|
|
displayDirectoryName = person.DisplayDirectoryName;
|
|
|
|
|
mapping = new(approximateYears, displayDirectoryName, forced, face.Location.NormalizedPixelPercentage, personBirthday);
|
|
|
|
|
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
|
|
|
|
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
|
|
|
|
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder.FullName, minimumDateTime);
|
|
|
|
|
mappingSegmentB = Stateless.MapLogic.GetMappingSegmentB(ticks, personBirthday, approximateYears, minimumDateTime, isWrongYear);
|
|
|
|
|
mapping = new(approximateYears, displayDirectoryName, forced, face.Location.NormalizedPixelPercentage, personBirthday, mappingSegmentB);
|
|
|
|
|
item.Mapping.Add(mapping);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -369,14 +329,18 @@ public class MapLogic
|
|
|
|
|
personBirthdays.AddRange(_DeterministicHashCodeUnknownFaceKeyValuePairs[item.Property.Id.Value]);
|
|
|
|
|
for (int i = 0; i < personBirthdays.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
ticks = personBirthdays[i].Value.Ticks;
|
|
|
|
|
if (!_PeopleKeyValuePairs.ContainsKey(ticks))
|
|
|
|
|
personKey = personBirthdays[i].Value.Ticks;
|
|
|
|
|
if (!_PeopleKeyValuePairs.ContainsKey(personKey))
|
|
|
|
|
continue;
|
|
|
|
|
person = _PeopleKeyValuePairs[ticks];
|
|
|
|
|
person = _PeopleKeyValuePairs[personKey];
|
|
|
|
|
personBirthday = person.PersonBirthdays[0];
|
|
|
|
|
approximateYears = person.ApproximateYears;
|
|
|
|
|
displayDirectoryName = person.DisplayDirectoryName;
|
|
|
|
|
mapping = new(approximateYears, displayDirectoryName, forced, personBirthday);
|
|
|
|
|
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
|
|
|
|
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
|
|
|
|
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder.FullName, minimumDateTime);
|
|
|
|
|
mappingSegmentB = Stateless.MapLogic.GetMappingSegmentB(ticks, personBirthday, approximateYears, minimumDateTime, isWrongYear);
|
|
|
|
|
mapping = new(approximateYears, displayDirectoryName, forced, personBirthday, mappingSegmentB);
|
|
|
|
|
item.Mapping.Add(mapping);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -438,16 +402,16 @@ public class MapLogic
|
|
|
|
|
public void SaveNotMappedTicks()
|
|
|
|
|
{
|
|
|
|
|
string directory;
|
|
|
|
|
string personKey;
|
|
|
|
|
string personKeyFormatted;
|
|
|
|
|
SaveContainer saveContainer;
|
|
|
|
|
PersonBirthday personBirthday;
|
|
|
|
|
List<SaveContainer> saveContainers = new();
|
|
|
|
|
const string facePopulatedKey = nameof(Closest);
|
|
|
|
|
foreach (long ticks in _NotMappedTicks)
|
|
|
|
|
foreach (long personKey in _NotMappedPersonKeys)
|
|
|
|
|
{
|
|
|
|
|
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(ticks);
|
|
|
|
|
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"{facePopulatedKey}NotMapped", personKey, Property.Models.Stateless.IResult.AllInOne);
|
|
|
|
|
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(personKey);
|
|
|
|
|
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"{facePopulatedKey}NotMapped", personKeyFormatted, Property.Models.Stateless.IResult.AllInOne);
|
|
|
|
|
saveContainer = new(directory);
|
|
|
|
|
saveContainers.Add(saveContainer);
|
|
|
|
|
}
|
|
|
|
@ -460,9 +424,8 @@ public class MapLogic
|
|
|
|
|
int years;
|
|
|
|
|
Face face;
|
|
|
|
|
Item item;
|
|
|
|
|
long? ticks;
|
|
|
|
|
long? personKey;
|
|
|
|
|
string directory;
|
|
|
|
|
string personKey;
|
|
|
|
|
bool? isWrongYear;
|
|
|
|
|
const int zero = 0;
|
|
|
|
|
TimeSpan? timeSpan;
|
|
|
|
@ -475,6 +438,7 @@ public class MapLogic
|
|
|
|
|
DateTime minimumDateTime;
|
|
|
|
|
List<int> indices = new();
|
|
|
|
|
List<Face> faceCollection;
|
|
|
|
|
string personKeyFormatted;
|
|
|
|
|
PersonBirthday personBirthday;
|
|
|
|
|
PersonBirthday[] personBirthdays;
|
|
|
|
|
DateTime dateTime = DateTime.Now;
|
|
|
|
@ -490,13 +454,13 @@ public class MapLogic
|
|
|
|
|
relativePath = Path.GetDirectoryName($"C:{item.RelativePath}");
|
|
|
|
|
if (string.IsNullOrEmpty(relativePath) || relativePath.Length < 3)
|
|
|
|
|
continue;
|
|
|
|
|
if (item.Property?.Id is null || item.ResizedFileHolder is null)
|
|
|
|
|
if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null)
|
|
|
|
|
continue;
|
|
|
|
|
collection = new();
|
|
|
|
|
if (!_DeterministicHashCodeUnknownFaceKeyValuePairs.ContainsKey(item.Property.Id.Value))
|
|
|
|
|
{
|
|
|
|
|
faceCollection = new();
|
|
|
|
|
ticks = null;
|
|
|
|
|
personKey = null;
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"Unnamed{relativePath[2..]}");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -509,24 +473,24 @@ public class MapLogic
|
|
|
|
|
subDirectoryName = $"{isWrongYearFlag}{minimumDateTime:yyyy}";
|
|
|
|
|
if (!faceCollection.Any())
|
|
|
|
|
{
|
|
|
|
|
ticks = null;
|
|
|
|
|
personKey = null;
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"None{relativePath[2..]}", subDirectoryName);
|
|
|
|
|
}
|
|
|
|
|
else if (personBirthdays.Length != 1)
|
|
|
|
|
{
|
|
|
|
|
ticks = null;
|
|
|
|
|
personKey = null;
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"Not Supported{relativePath[2..]}", subDirectoryName);
|
|
|
|
|
}
|
|
|
|
|
else if (faceCollection.Count != 1)
|
|
|
|
|
{
|
|
|
|
|
ticks = null;
|
|
|
|
|
personKey = null;
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"Many{relativePath[2..]}", subDirectoryName);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
indices.Add(zero);
|
|
|
|
|
personBirthday = personBirthdays[zero];
|
|
|
|
|
ticks = personBirthday.Value.Ticks;
|
|
|
|
|
personKey = personBirthday.Value.Ticks;
|
|
|
|
|
timeSpan = Shared.Models.Stateless.Methods.IPersonBirthday.GetTimeSpan(minimumDateTime, isWrongYear, personBirthday);
|
|
|
|
|
if (timeSpan.HasValue)
|
|
|
|
|
{
|
|
|
|
@ -539,128 +503,170 @@ public class MapLogic
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
face = faceCollection[zero];
|
|
|
|
|
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, "Shortcuts", personKey, subDirectoryName);
|
|
|
|
|
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, "Shortcuts", personKeyFormatted, subDirectoryName);
|
|
|
|
|
if (face.FaceEncoding is not null && face.Location?.NormalizedPixelPercentage is not null)
|
|
|
|
|
copyDirectory = Path.Combine(_ZPropertyHolderContentTicksDirectory, "Images", personKey, subDirectoryName);
|
|
|
|
|
copyDirectory = Path.Combine(_ZPropertyHolderContentTicksDirectory, "Images", personKeyFormatted, subDirectoryName);
|
|
|
|
|
else
|
|
|
|
|
copyDirectory = Path.Combine(_ZPropertyHolderContentTicksDirectory, "ImagesBut", personKey, subDirectoryName);
|
|
|
|
|
copyDirectory = Path.Combine(_ZPropertyHolderContentTicksDirectory, "ImagesBut", personKeyFormatted, subDirectoryName);
|
|
|
|
|
copyFileName = Path.Combine(copyDirectory, $"{item.Property.Id.Value}{item.ResizedFileHolder.ExtensionLowered}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
shortcutFileName = Path.Combine(directory, $"{item.Property.Id.Value}.lnk");
|
|
|
|
|
if (ticks is null || !indices.Any())
|
|
|
|
|
collection.Add(new(ticks, null, (directory, copyDirectory, copyFileName, shortcutFileName)));
|
|
|
|
|
if (personKey is null || !indices.Any())
|
|
|
|
|
collection.Add(new(personKey, null, (directory, copyDirectory, copyFileName, shortcutFileName)));
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (int index in indices)
|
|
|
|
|
collection.Add(new(ticks, faceCollection[index], (directory, copyDirectory, copyFileName, shortcutFileName)));
|
|
|
|
|
collection.Add(new(personKey, faceCollection[index], (directory, copyDirectory, copyFileName, shortcutFileName)));
|
|
|
|
|
}
|
|
|
|
|
results.Add(new(item, collection.ToArray()));
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddToClosest(int maxDegreeOfParallelism, string argZero, Container[] containers)
|
|
|
|
|
public void AddToClosest(int maxDegreeOfParallelism, Item[] items)
|
|
|
|
|
{
|
|
|
|
|
string key;
|
|
|
|
|
string dateKey;
|
|
|
|
|
Closest closest;
|
|
|
|
|
string personKey;
|
|
|
|
|
DateTime minimumDateTime;
|
|
|
|
|
string personKeyFormatted;
|
|
|
|
|
Closest[] closestCollection;
|
|
|
|
|
double deterministicHashCodeKey;
|
|
|
|
|
DateTime dateTime = DateTime.Now;
|
|
|
|
|
Dictionary<string, int> keyValuePairs = new();
|
|
|
|
|
foreach (Container container in containers)
|
|
|
|
|
foreach (Item item in items)
|
|
|
|
|
{
|
|
|
|
|
if (!container.Items.Any())
|
|
|
|
|
if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null)
|
|
|
|
|
continue;
|
|
|
|
|
if (!container.SourceDirectory.StartsWith(argZero))
|
|
|
|
|
continue;
|
|
|
|
|
foreach (Item item in container.Items)
|
|
|
|
|
foreach (Face face in item.Faces)
|
|
|
|
|
{
|
|
|
|
|
if (item.ImageFileHolder is null || item.Property is null)
|
|
|
|
|
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
|
|
|
|
continue;
|
|
|
|
|
foreach (Face face in item.Faces)
|
|
|
|
|
deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(item, face);
|
|
|
|
|
if (_DeterministicHashCodeKeyValuePairs.ContainsKey(deterministicHashCodeKey))
|
|
|
|
|
continue;
|
|
|
|
|
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
|
|
|
|
closestCollection = Shared.Models.Stateless.Methods.IClosest.GetCollection(face, minimumDateTime, face.FaceDistances);
|
|
|
|
|
face.FaceDistances.Clear();
|
|
|
|
|
for (int j = 0; j < closestCollection.Length; j++)
|
|
|
|
|
{
|
|
|
|
|
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
|
|
|
|
closest = closestCollection[j];
|
|
|
|
|
if (_IncorrectDeterministicHashCodeKeyValuePairs.ContainsKey(deterministicHashCodeKey) && _IncorrectDeterministicHashCodeKeyValuePairs[deterministicHashCodeKey].Contains(closest.Mapping.PersonBirthday))
|
|
|
|
|
continue;
|
|
|
|
|
deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(item, face);
|
|
|
|
|
if (_DeterministicHashCodeKeyValuePairs.ContainsKey(deterministicHashCodeKey))
|
|
|
|
|
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(closest.Mapping.PersonBirthday);
|
|
|
|
|
key = string.Concat(personKeyFormatted, closest.Mapping.SegmentB);
|
|
|
|
|
if (!keyValuePairs.ContainsKey(key))
|
|
|
|
|
keyValuePairs.Add(key, 0);
|
|
|
|
|
else if (keyValuePairs[key] > IClosest.MaximumPer)
|
|
|
|
|
continue;
|
|
|
|
|
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
|
|
|
|
closestCollection = Shared.Models.Stateless.Methods.IClosest.GetCollection(face, minimumDateTime, face.FaceDistances);
|
|
|
|
|
face.FaceDistances.Clear();
|
|
|
|
|
for (int j = 0; j < closestCollection.Length; j++)
|
|
|
|
|
{
|
|
|
|
|
closest = closestCollection[j];
|
|
|
|
|
if (_IncorrectDeterministicHashCodeKeyValuePairs.ContainsKey(deterministicHashCodeKey) && _IncorrectDeterministicHashCodeKeyValuePairs[deterministicHashCodeKey].Contains(closest.Mapping.PersonBirthday))
|
|
|
|
|
continue;
|
|
|
|
|
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(closest.Mapping.PersonBirthday);
|
|
|
|
|
dateKey = Stateless.MapLogic.GetDateKey(dateTime, closest.Mapping, closest.MinimumDateTime, closest.IsWrongYear);
|
|
|
|
|
key = string.Concat(personKey, dateKey);
|
|
|
|
|
if (!keyValuePairs.ContainsKey(key))
|
|
|
|
|
keyValuePairs.Add(key, 0);
|
|
|
|
|
else if (keyValuePairs[key] > IClosest.MaximumPer)
|
|
|
|
|
continue;
|
|
|
|
|
keyValuePairs[key] += 1;
|
|
|
|
|
item.Closest.Add(closest);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
keyValuePairs[key] += 1;
|
|
|
|
|
item.Closest.Add(closest);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<SaveContainer> GetMappingSaveContainers(string argZero, Container[] containers, string dFacesContentDirectory, string d2ResultsFullGroupDirectory)
|
|
|
|
|
private List<SaveContainer> GetMappingSaveContainers(Item[] items, string dFacesContentDirectory, string d2ResultsFullGroupDirectory)
|
|
|
|
|
{
|
|
|
|
|
List<SaveContainer> results = new();
|
|
|
|
|
string key;
|
|
|
|
|
string json;
|
|
|
|
|
string dateKey;
|
|
|
|
|
Mapping? match;
|
|
|
|
|
string personKey;
|
|
|
|
|
string checkFile;
|
|
|
|
|
string directory;
|
|
|
|
|
bool? isWrongYear;
|
|
|
|
|
string shortcutFile;
|
|
|
|
|
string? directoryName;
|
|
|
|
|
string facesDirectory;
|
|
|
|
|
string personDirectory;
|
|
|
|
|
List<int> used = new();
|
|
|
|
|
DateTime minimumDateTime;
|
|
|
|
|
string personKeyFormatted;
|
|
|
|
|
FileHolder faceFileHolder;
|
|
|
|
|
string facePartsDirectory;
|
|
|
|
|
SaveContainer saveContainer;
|
|
|
|
|
FileHolder facePartsFileHolder;
|
|
|
|
|
FileHolder hiddenFaceFileHolder;
|
|
|
|
|
double deterministicHashCodeKey;
|
|
|
|
|
DateTime dateTime = DateTime.Now;
|
|
|
|
|
const string facePopulatedKey = nameof(Mapping);
|
|
|
|
|
bool deterministicHashCodeKeyValuePairsAny = _DeterministicHashCodeKeyValuePairs.Any();
|
|
|
|
|
foreach (Container container in containers)
|
|
|
|
|
foreach (Item item in items)
|
|
|
|
|
{
|
|
|
|
|
if (!container.Items.Any())
|
|
|
|
|
used.Clear();
|
|
|
|
|
if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null)
|
|
|
|
|
continue;
|
|
|
|
|
if (!container.SourceDirectory.StartsWith(argZero))
|
|
|
|
|
continue;
|
|
|
|
|
foreach (Item item in container.Items)
|
|
|
|
|
directoryName = Path.GetDirectoryName(item.RelativePath);
|
|
|
|
|
if (directoryName is null)
|
|
|
|
|
throw new Exception();
|
|
|
|
|
foreach (Face face in item.Faces)
|
|
|
|
|
{
|
|
|
|
|
used.Clear();
|
|
|
|
|
if (item.ImageFileHolder is null || item.Property?.Id is null || item.ResizedFileHolder is null)
|
|
|
|
|
match = null;
|
|
|
|
|
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
|
|
|
|
continue;
|
|
|
|
|
directoryName = Path.GetDirectoryName(item.RelativePath);
|
|
|
|
|
if (directoryName is null)
|
|
|
|
|
foreach (Mapping mapping in item.Mapping)
|
|
|
|
|
{
|
|
|
|
|
if (mapping.NormalizedPixelPercentage is null || mapping.NormalizedPixelPercentage.Value != face.Location.NormalizedPixelPercentage.Value)
|
|
|
|
|
continue;
|
|
|
|
|
match = mapping;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (match is null)
|
|
|
|
|
continue;
|
|
|
|
|
foreach (Closest closest in item.Closest)
|
|
|
|
|
{
|
|
|
|
|
if (closest.Mapping.Forced)
|
|
|
|
|
continue;
|
|
|
|
|
if (closest.NormalizedPixelPercentage != face.Location.NormalizedPixelPercentage.Value)
|
|
|
|
|
continue;
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(match.PersonBirthday);
|
|
|
|
|
if (match.Filtered is null)
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"{facePopulatedKey}Null", personKeyFormatted, match.SegmentB);
|
|
|
|
|
else if (match.Filtered.Value)
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"{facePopulatedKey}OutOfControl", personKeyFormatted, match.SegmentB);
|
|
|
|
|
else
|
|
|
|
|
continue;
|
|
|
|
|
personDirectory = Path.Combine(directory, match.DisplayDirectoryName[..1], "lnk");
|
|
|
|
|
saveContainer = new(personDirectory);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
facesDirectory = string.Concat(dFacesContentDirectory, Path.Combine(directoryName, item.ImageFileHolder.NameWithoutExtension));
|
|
|
|
|
facePartsDirectory = string.Concat(d2ResultsFullGroupDirectory, Path.Combine(directoryName, item.ImageFileHolder.NameWithoutExtension));
|
|
|
|
|
deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(item, face);
|
|
|
|
|
checkFile = Path.Combine(directory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}");
|
|
|
|
|
faceFileHolder = new(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacesFilenameExtension}"));
|
|
|
|
|
hiddenFaceFileHolder = new(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacesHiddenFilenameExtension}"));
|
|
|
|
|
facePartsFileHolder = new(Path.Combine(facePartsDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacePartsFilenameExtension}"));
|
|
|
|
|
if (string.IsNullOrEmpty(personDirectory))
|
|
|
|
|
shortcutFile = string.Empty;
|
|
|
|
|
else
|
|
|
|
|
shortcutFile = Path.Combine(personDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}.lnk");
|
|
|
|
|
saveContainer = new(checkFile, directory, faceFileHolder, hiddenFaceFileHolder, string.Empty, facePartsFileHolder, item.ResizedFileHolder, shortcutFile);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
if (!string.IsNullOrEmpty(checkFile) && IMapping.SaveFaceEncoding)
|
|
|
|
|
{
|
|
|
|
|
checkFile = Path.Combine(directory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}.json");
|
|
|
|
|
json = JsonSerializer.Serialize(face.FaceEncoding);
|
|
|
|
|
saveContainer = new(checkFile, directory, json);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
}
|
|
|
|
|
personDirectory = Path.Combine(directory, match.DisplayDirectoryName[..1], "lnk", match.DisplayDirectoryName);
|
|
|
|
|
saveContainer = new(personDirectory);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
used.Add(face.Location.NormalizedPixelPercentage.Value);
|
|
|
|
|
}
|
|
|
|
|
if (deterministicHashCodeKeyValuePairsAny && IMapping.UseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping)
|
|
|
|
|
{
|
|
|
|
|
foreach (Face face in item.Faces)
|
|
|
|
|
{
|
|
|
|
|
match = null;
|
|
|
|
|
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
|
|
|
|
continue;
|
|
|
|
|
if (used.Contains(face.Location.NormalizedPixelPercentage.Value))
|
|
|
|
|
continue;
|
|
|
|
|
// if (item.Faces.Count != 1 || item.Mapping.Count != 1)
|
|
|
|
|
// continue;
|
|
|
|
|
foreach (Mapping mapping in item.Mapping)
|
|
|
|
|
{
|
|
|
|
|
if (mapping.NormalizedPixelPercentage is null || mapping.NormalizedPixelPercentage.Value != face.Location.NormalizedPixelPercentage.Value)
|
|
|
|
|
if (mapping.NormalizedPixelPercentage is not null)
|
|
|
|
|
continue;
|
|
|
|
|
match = mapping;
|
|
|
|
|
break;
|
|
|
|
@ -675,15 +681,11 @@ public class MapLogic
|
|
|
|
|
continue;
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
|
|
|
|
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder.FullName, minimumDateTime);
|
|
|
|
|
dateKey = Stateless.MapLogic.GetDateKey(dateTime, match, minimumDateTime, isWrongYear);
|
|
|
|
|
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(match.PersonBirthday);
|
|
|
|
|
key = string.Concat(personKey, dateKey);
|
|
|
|
|
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(match.PersonBirthday);
|
|
|
|
|
if (match.Filtered is null)
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"{facePopulatedKey}Null", personKey, dateKey);
|
|
|
|
|
else if (match.Filtered.Value)
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"{facePopulatedKey}OutOfControl", personKey, dateKey);
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"{facePopulatedKey}WithButNull", personKeyFormatted, match.SegmentB);
|
|
|
|
|
else if (!match.Filtered.Value)
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"{facePopulatedKey}WithButOutOfControl", personKeyFormatted, match.SegmentB);
|
|
|
|
|
else
|
|
|
|
|
continue;
|
|
|
|
|
personDirectory = Path.Combine(directory, match.DisplayDirectoryName[..1], "lnk");
|
|
|
|
@ -714,92 +716,24 @@ public class MapLogic
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
used.Add(face.Location.NormalizedPixelPercentage.Value);
|
|
|
|
|
}
|
|
|
|
|
if (deterministicHashCodeKeyValuePairsAny && IMapping.UseDeterministicHashCodeUnknownFaceKeyValuePairsForSaveMapping)
|
|
|
|
|
{
|
|
|
|
|
foreach (Face face in item.Faces)
|
|
|
|
|
{
|
|
|
|
|
match = null;
|
|
|
|
|
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
|
|
|
|
continue;
|
|
|
|
|
if (used.Contains(face.Location.NormalizedPixelPercentage.Value))
|
|
|
|
|
continue;
|
|
|
|
|
// if (item.Faces.Count != 1 || item.Mapping.Count != 1)
|
|
|
|
|
// continue;
|
|
|
|
|
foreach (Mapping mapping in item.Mapping)
|
|
|
|
|
{
|
|
|
|
|
if (mapping.NormalizedPixelPercentage is not null)
|
|
|
|
|
continue;
|
|
|
|
|
match = mapping;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (match is null)
|
|
|
|
|
continue;
|
|
|
|
|
foreach (Closest closest in item.Closest)
|
|
|
|
|
{
|
|
|
|
|
if (closest.Mapping.Forced)
|
|
|
|
|
continue;
|
|
|
|
|
if (closest.NormalizedPixelPercentage != face.Location.NormalizedPixelPercentage.Value)
|
|
|
|
|
continue;
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(match.PersonBirthday);
|
|
|
|
|
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
|
|
|
|
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder.FullName, minimumDateTime);
|
|
|
|
|
dateKey = Stateless.MapLogic.GetDateKey(dateTime, match, minimumDateTime, isWrongYear);
|
|
|
|
|
if (match.Filtered is null)
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"{facePopulatedKey}WithButNull", personKey, dateKey);
|
|
|
|
|
else if (!match.Filtered.Value)
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, $"{facePopulatedKey}WithButOutOfControl", personKey, dateKey);
|
|
|
|
|
else
|
|
|
|
|
continue;
|
|
|
|
|
personDirectory = Path.Combine(directory, match.DisplayDirectoryName[..1], "lnk");
|
|
|
|
|
saveContainer = new(personDirectory);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
facesDirectory = string.Concat(dFacesContentDirectory, Path.Combine(directoryName, item.ImageFileHolder.NameWithoutExtension));
|
|
|
|
|
facePartsDirectory = string.Concat(d2ResultsFullGroupDirectory, Path.Combine(directoryName, item.ImageFileHolder.NameWithoutExtension));
|
|
|
|
|
deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(item, face);
|
|
|
|
|
checkFile = Path.Combine(directory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}");
|
|
|
|
|
faceFileHolder = new(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacesFilenameExtension}"));
|
|
|
|
|
hiddenFaceFileHolder = new(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacesHiddenFilenameExtension}"));
|
|
|
|
|
facePartsFileHolder = new(Path.Combine(facePartsDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacePartsFilenameExtension}"));
|
|
|
|
|
if (string.IsNullOrEmpty(personDirectory))
|
|
|
|
|
shortcutFile = string.Empty;
|
|
|
|
|
else
|
|
|
|
|
shortcutFile = Path.Combine(personDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}.lnk");
|
|
|
|
|
saveContainer = new(checkFile, directory, faceFileHolder, hiddenFaceFileHolder, string.Empty, facePartsFileHolder, item.ResizedFileHolder, shortcutFile);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
if (!string.IsNullOrEmpty(checkFile) && IMapping.SaveFaceEncoding)
|
|
|
|
|
{
|
|
|
|
|
checkFile = Path.Combine(directory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}.json");
|
|
|
|
|
json = JsonSerializer.Serialize(face.FaceEncoding);
|
|
|
|
|
saveContainer = new(checkFile, directory, json);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
}
|
|
|
|
|
personDirectory = Path.Combine(directory, match.DisplayDirectoryName[..1], "lnk", match.DisplayDirectoryName);
|
|
|
|
|
saveContainer = new(personDirectory);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
used.Add(face.Location.NormalizedPixelPercentage.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<SaveContainer> GetClosestSaveContainers(string argZero, Container[] containers, string dFacesContentDirectory, string d2ResultsFullGroupDirectory)
|
|
|
|
|
private List<SaveContainer> GetClosestSaveContainers(Item[] items, string dFacesContentDirectory, string d2ResultsFullGroupDirectory)
|
|
|
|
|
{
|
|
|
|
|
List<SaveContainer> results = new();
|
|
|
|
|
Closest? match;
|
|
|
|
|
string dateKey;
|
|
|
|
|
string checkFile;
|
|
|
|
|
string directory;
|
|
|
|
|
string personKey;
|
|
|
|
|
string shortcutFile;
|
|
|
|
|
string? directoryName;
|
|
|
|
|
string facesDirectory;
|
|
|
|
|
string personDirectory;
|
|
|
|
|
List<int> used = new();
|
|
|
|
|
FileHolder faceFileHolder;
|
|
|
|
|
string personKeyFormatted;
|
|
|
|
|
string facePartsDirectory;
|
|
|
|
|
SaveContainer saveContainer;
|
|
|
|
|
PersonBirthday personBirthday;
|
|
|
|
@ -808,139 +742,132 @@ public class MapLogic
|
|
|
|
|
double deterministicHashCodeKey;
|
|
|
|
|
DateTime dateTime = DateTime.Now;
|
|
|
|
|
const string facePopulatedKey = nameof(Closest);
|
|
|
|
|
foreach (Container container in containers)
|
|
|
|
|
foreach (Item item in items)
|
|
|
|
|
{
|
|
|
|
|
if (!container.Items.Any())
|
|
|
|
|
used.Clear();
|
|
|
|
|
if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null)
|
|
|
|
|
continue;
|
|
|
|
|
if (!container.SourceDirectory.StartsWith(argZero))
|
|
|
|
|
if (!item.Closest.Any())
|
|
|
|
|
continue;
|
|
|
|
|
foreach (Item item in container.Items)
|
|
|
|
|
directoryName = Path.GetDirectoryName(item.RelativePath);
|
|
|
|
|
if (directoryName is null)
|
|
|
|
|
throw new Exception();
|
|
|
|
|
foreach (Face face in item.Faces)
|
|
|
|
|
{
|
|
|
|
|
used.Clear();
|
|
|
|
|
if (item.ImageFileHolder is null || item.Property?.Id is null || item.ResizedFileHolder is null)
|
|
|
|
|
match = null;
|
|
|
|
|
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
|
|
|
|
continue;
|
|
|
|
|
if (!item.Closest.Any())
|
|
|
|
|
continue;
|
|
|
|
|
directoryName = Path.GetDirectoryName(item.RelativePath);
|
|
|
|
|
if (directoryName is null)
|
|
|
|
|
throw new Exception();
|
|
|
|
|
foreach (Face face in item.Faces)
|
|
|
|
|
{
|
|
|
|
|
match = null;
|
|
|
|
|
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
|
|
|
|
continue;
|
|
|
|
|
foreach (Closest closest in item.Closest)
|
|
|
|
|
{
|
|
|
|
|
if (closest.NormalizedPixelPercentage != face.Location.NormalizedPixelPercentage.Value)
|
|
|
|
|
continue;
|
|
|
|
|
match = closest;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (match is null)
|
|
|
|
|
continue;
|
|
|
|
|
foreach (Mapping mapping in item.Mapping)
|
|
|
|
|
{
|
|
|
|
|
if (mapping.Forced)
|
|
|
|
|
continue;
|
|
|
|
|
if (mapping.NormalizedPixelPercentage is null || mapping.NormalizedPixelPercentage.Value != face.Location.NormalizedPixelPercentage.Value)
|
|
|
|
|
continue;
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
if (!match.AboveTolerance)
|
|
|
|
|
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(match.Mapping.PersonBirthday);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
personKey = string.Empty;
|
|
|
|
|
foreach (long ticks in _NotMappedTicks)
|
|
|
|
|
{
|
|
|
|
|
if (ticks == match.Mapping.PersonBirthday.Value.Ticks)
|
|
|
|
|
continue;
|
|
|
|
|
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(ticks);
|
|
|
|
|
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(personKey))
|
|
|
|
|
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(match.Mapping.PersonBirthday);
|
|
|
|
|
}
|
|
|
|
|
dateKey = Stateless.MapLogic.GetDateKey(dateTime, match.Mapping, match.MinimumDateTime, match.IsWrongYear);
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, facePopulatedKey, personKey, dateKey);
|
|
|
|
|
personDirectory = Path.Combine(directory, match.Mapping.DisplayDirectoryName[..1], "lnk");
|
|
|
|
|
saveContainer = new(personDirectory);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
facesDirectory = string.Concat(dFacesContentDirectory, Path.Combine(directoryName, item.ImageFileHolder.NameWithoutExtension));
|
|
|
|
|
facePartsDirectory = string.Concat(d2ResultsFullGroupDirectory, Path.Combine(directoryName, item.ImageFileHolder.NameWithoutExtension));
|
|
|
|
|
deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(item, face);
|
|
|
|
|
checkFile = Path.Combine(directory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}");
|
|
|
|
|
faceFileHolder = new(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacesFilenameExtension}"));
|
|
|
|
|
hiddenFaceFileHolder = new(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacesHiddenFilenameExtension}"));
|
|
|
|
|
facePartsFileHolder = new(Path.Combine(facePartsDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacePartsFilenameExtension}"));
|
|
|
|
|
if (string.IsNullOrEmpty(personDirectory))
|
|
|
|
|
shortcutFile = string.Empty;
|
|
|
|
|
else
|
|
|
|
|
shortcutFile = Path.Combine(personDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}.lnk");
|
|
|
|
|
saveContainer = new(checkFile, directory, faceFileHolder, hiddenFaceFileHolder, string.Empty, facePartsFileHolder, item.ResizedFileHolder, shortcutFile);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
personDirectory = Path.Combine(directory, match.Mapping.DisplayDirectoryName[..1], "lnk", match.Mapping.DisplayDirectoryName);
|
|
|
|
|
saveContainer = new(personDirectory);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
used.Add(face.Location.NormalizedPixelPercentage.Value);
|
|
|
|
|
}
|
|
|
|
|
foreach (Closest closest in item.Closest)
|
|
|
|
|
{
|
|
|
|
|
if (used.Contains(closest.NormalizedPixelPercentage))
|
|
|
|
|
if (closest.NormalizedPixelPercentage != face.Location.NormalizedPixelPercentage.Value)
|
|
|
|
|
continue;
|
|
|
|
|
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(closest.Mapping.PersonBirthday);
|
|
|
|
|
dateKey = Stateless.MapLogic.GetDateKey(dateTime, closest.Mapping, closest.MinimumDateTime, closest.IsWrongYear);
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, facePopulatedKey, personKey, dateKey);
|
|
|
|
|
personDirectory = Path.Combine(directory, closest.Mapping.DisplayDirectoryName, "lnk");
|
|
|
|
|
saveContainer = new(personDirectory);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
facesDirectory = string.Concat(dFacesContentDirectory, Path.Combine(directoryName, item.ImageFileHolder.NameWithoutExtension));
|
|
|
|
|
facePartsDirectory = string.Concat(d2ResultsFullGroupDirectory, Path.Combine(directoryName, item.ImageFileHolder.NameWithoutExtension));
|
|
|
|
|
deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(item, closest);
|
|
|
|
|
checkFile = Path.Combine(directory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}");
|
|
|
|
|
faceFileHolder = new(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacesFilenameExtension}"));
|
|
|
|
|
hiddenFaceFileHolder = new(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacesHiddenFilenameExtension}"));
|
|
|
|
|
facePartsFileHolder = new(Path.Combine(facePartsDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacePartsFilenameExtension}"));
|
|
|
|
|
if (string.IsNullOrEmpty(personDirectory))
|
|
|
|
|
shortcutFile = string.Empty;
|
|
|
|
|
else
|
|
|
|
|
shortcutFile = Path.Combine(personDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}.lnk");
|
|
|
|
|
saveContainer = new(checkFile, directory, faceFileHolder, hiddenFaceFileHolder, string.Empty, facePartsFileHolder, item.ResizedFileHolder, shortcutFile);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
personDirectory = Path.Combine(directory, closest.Mapping.DisplayDirectoryName[..1], "lnk", closest.Mapping.DisplayDirectoryName);
|
|
|
|
|
saveContainer = new(personDirectory);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
used.Add(closest.NormalizedPixelPercentage);
|
|
|
|
|
match = closest;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (match is null)
|
|
|
|
|
continue;
|
|
|
|
|
foreach (Mapping mapping in item.Mapping)
|
|
|
|
|
{
|
|
|
|
|
if (mapping.Forced)
|
|
|
|
|
continue;
|
|
|
|
|
if (mapping.NormalizedPixelPercentage is null || mapping.NormalizedPixelPercentage.Value != face.Location.NormalizedPixelPercentage.Value)
|
|
|
|
|
continue;
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
if (!match.AboveTolerance)
|
|
|
|
|
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(match.Mapping.PersonBirthday);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
personKeyFormatted = string.Empty;
|
|
|
|
|
foreach (long personKey in _NotMappedPersonKeys)
|
|
|
|
|
{
|
|
|
|
|
if (personKey == match.Mapping.PersonBirthday.Value.Ticks)
|
|
|
|
|
continue;
|
|
|
|
|
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(personKey);
|
|
|
|
|
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(personKeyFormatted))
|
|
|
|
|
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(match.Mapping.PersonBirthday);
|
|
|
|
|
}
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, facePopulatedKey, personKeyFormatted, match.Mapping.SegmentB);
|
|
|
|
|
personDirectory = Path.Combine(directory, match.Mapping.DisplayDirectoryName[..1], "lnk");
|
|
|
|
|
saveContainer = new(personDirectory);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
facesDirectory = string.Concat(dFacesContentDirectory, Path.Combine(directoryName, item.ImageFileHolder.NameWithoutExtension));
|
|
|
|
|
facePartsDirectory = string.Concat(d2ResultsFullGroupDirectory, Path.Combine(directoryName, item.ImageFileHolder.NameWithoutExtension));
|
|
|
|
|
deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(item, face);
|
|
|
|
|
checkFile = Path.Combine(directory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}");
|
|
|
|
|
faceFileHolder = new(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacesFilenameExtension}"));
|
|
|
|
|
hiddenFaceFileHolder = new(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacesHiddenFilenameExtension}"));
|
|
|
|
|
facePartsFileHolder = new(Path.Combine(facePartsDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacePartsFilenameExtension}"));
|
|
|
|
|
if (string.IsNullOrEmpty(personDirectory))
|
|
|
|
|
shortcutFile = string.Empty;
|
|
|
|
|
else
|
|
|
|
|
shortcutFile = Path.Combine(personDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}.lnk");
|
|
|
|
|
saveContainer = new(checkFile, directory, faceFileHolder, hiddenFaceFileHolder, string.Empty, facePartsFileHolder, item.ResizedFileHolder, shortcutFile);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
personDirectory = Path.Combine(directory, match.Mapping.DisplayDirectoryName[..1], "lnk", match.Mapping.DisplayDirectoryName);
|
|
|
|
|
saveContainer = new(personDirectory);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
used.Add(face.Location.NormalizedPixelPercentage.Value);
|
|
|
|
|
}
|
|
|
|
|
foreach (Closest closest in item.Closest)
|
|
|
|
|
{
|
|
|
|
|
if (used.Contains(closest.NormalizedPixelPercentage))
|
|
|
|
|
continue;
|
|
|
|
|
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(closest.Mapping.PersonBirthday);
|
|
|
|
|
directory = Path.Combine(_ZPropertyHolderContentTicksDirectory, facePopulatedKey, personKeyFormatted, closest.Mapping.SegmentB);
|
|
|
|
|
personDirectory = Path.Combine(directory, closest.Mapping.DisplayDirectoryName, "lnk");
|
|
|
|
|
saveContainer = new(personDirectory);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
facesDirectory = string.Concat(dFacesContentDirectory, Path.Combine(directoryName, item.ImageFileHolder.NameWithoutExtension));
|
|
|
|
|
facePartsDirectory = string.Concat(d2ResultsFullGroupDirectory, Path.Combine(directoryName, item.ImageFileHolder.NameWithoutExtension));
|
|
|
|
|
deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(item, closest);
|
|
|
|
|
checkFile = Path.Combine(directory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}");
|
|
|
|
|
faceFileHolder = new(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacesFilenameExtension}"));
|
|
|
|
|
hiddenFaceFileHolder = new(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacesHiddenFilenameExtension}"));
|
|
|
|
|
facePartsFileHolder = new(Path.Combine(facePartsDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FacePartsFilenameExtension}"));
|
|
|
|
|
if (string.IsNullOrEmpty(personDirectory))
|
|
|
|
|
shortcutFile = string.Empty;
|
|
|
|
|
else
|
|
|
|
|
shortcutFile = Path.Combine(personDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}.lnk");
|
|
|
|
|
saveContainer = new(checkFile, directory, faceFileHolder, hiddenFaceFileHolder, string.Empty, facePartsFileHolder, item.ResizedFileHolder, shortcutFile);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
personDirectory = Path.Combine(directory, closest.Mapping.DisplayDirectoryName[..1], "lnk", closest.Mapping.DisplayDirectoryName);
|
|
|
|
|
saveContainer = new(personDirectory);
|
|
|
|
|
results.Add(saveContainer);
|
|
|
|
|
used.Add(closest.NormalizedPixelPercentage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveMapping(string argZero, Container[] containers, string dFacesContentDirectory, string d2ResultsFullGroupDirectory)
|
|
|
|
|
public void SaveMapping(Item[] items, string dFacesContentDirectory, string d2ResultsFullGroupDirectory)
|
|
|
|
|
{
|
|
|
|
|
List<SaveContainer> saveContainers = GetMappingSaveContainers(argZero, containers, dFacesContentDirectory, d2ResultsFullGroupDirectory);
|
|
|
|
|
List<SaveContainer> saveContainers = GetMappingSaveContainers(items, dFacesContentDirectory, d2ResultsFullGroupDirectory);
|
|
|
|
|
SaveContainers(saveContainers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SaveClosest(string argZero, Container[] containers, string dFacesContentDirectory, string d2ResultsFullGroupDirectory)
|
|
|
|
|
public void SaveClosest(Item[] items, string dFacesContentDirectory, string d2ResultsFullGroupDirectory)
|
|
|
|
|
{
|
|
|
|
|
List<SaveContainer> saveContainers = GetClosestSaveContainers(argZero, containers, dFacesContentDirectory, d2ResultsFullGroupDirectory);
|
|
|
|
|
List<SaveContainer> saveContainers = GetClosestSaveContainers(items, dFacesContentDirectory, d2ResultsFullGroupDirectory);
|
|
|
|
|
SaveContainers(saveContainers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ForceSingleImage(string[] ignoreRelativePaths, string argZero, Container[] containers, int totalNotMapped, Random random)
|
|
|
|
|
public void ForceSingleImage(long ticks, Item[] items, int totalNotMapped, Random random)
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
Closest closest;
|
|
|
|
|
Mapping mapping;
|
|
|
|
|
bool? isWrongYear;
|
|
|
|
|
long? ticks = null;
|
|
|
|
|
const int zero = 0;
|
|
|
|
|
bool forced = true;
|
|
|
|
|
const int zero = 0;
|
|
|
|
|
int randomSelection;
|
|
|
|
|
string mappingSegmentB;
|
|
|
|
|
long? personKey = null;
|
|
|
|
|
DateTime minimumDateTime;
|
|
|
|
|
string personKeyFormatted;
|
|
|
|
|
bool aboveTolerance = false;
|
|
|
|
|
int? approximateYears = null;
|
|
|
|
|
PersonBirthday personBirthday;
|
|
|
|
@ -949,77 +876,65 @@ public class MapLogic
|
|
|
|
|
{
|
|
|
|
|
count = 0;
|
|
|
|
|
randomSelection = random.Next(0, totalNotMapped);
|
|
|
|
|
foreach (Container container in containers)
|
|
|
|
|
foreach (Item item in items)
|
|
|
|
|
{
|
|
|
|
|
if (!_NotMappedTicks.Any())
|
|
|
|
|
break;
|
|
|
|
|
if (!container.Items.Any())
|
|
|
|
|
if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null)
|
|
|
|
|
continue;
|
|
|
|
|
if (!container.SourceDirectory.StartsWith(argZero))
|
|
|
|
|
if (item.Mapping.Any())
|
|
|
|
|
continue;
|
|
|
|
|
if (ignoreRelativePaths.Contains(Path.GetFileName(container.SourceDirectory)))
|
|
|
|
|
continue;
|
|
|
|
|
foreach (Item item in container.Items)
|
|
|
|
|
foreach (Face face in item.Faces)
|
|
|
|
|
{
|
|
|
|
|
if (item.ImageFileHolder is null || item.Property?.Id is null || item.Mapping.Any())
|
|
|
|
|
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
|
|
|
|
continue;
|
|
|
|
|
foreach (Face face in item.Faces)
|
|
|
|
|
{
|
|
|
|
|
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
|
|
|
|
continue;
|
|
|
|
|
if (face.Location.Confidence < ILocation.MinimumConfidence)
|
|
|
|
|
continue;
|
|
|
|
|
count += 1;
|
|
|
|
|
if (count < randomSelection)
|
|
|
|
|
continue;
|
|
|
|
|
ticks = _NotMappedTicks[zero];
|
|
|
|
|
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
|
|
|
|
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder.FullName, minimumDateTime);
|
|
|
|
|
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(ticks.Value);
|
|
|
|
|
mapping = new(approximateYears, displayDirectoryName, forced, face.Location.NormalizedPixelPercentage, personBirthday);
|
|
|
|
|
closest = new(aboveTolerance, zero, face.Location.NormalizedPixelPercentage.Value, isWrongYear, mapping, zero, minimumDateTime, null);
|
|
|
|
|
item.Closest.Add(closest);
|
|
|
|
|
item.Mapping.Add(mapping);
|
|
|
|
|
if (ticks is not null)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (ticks is not null)
|
|
|
|
|
if (face.Location.Confidence < ILocation.MinimumConfidence)
|
|
|
|
|
continue;
|
|
|
|
|
count += 1;
|
|
|
|
|
if (count < randomSelection)
|
|
|
|
|
continue;
|
|
|
|
|
personKey = _NotMappedPersonKeys[zero];
|
|
|
|
|
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
|
|
|
|
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder.FullName, minimumDateTime);
|
|
|
|
|
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(personKey.Value);
|
|
|
|
|
personKeyFormatted = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
|
|
|
|
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
|
|
|
|
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder.FullName, minimumDateTime);
|
|
|
|
|
mappingSegmentB = Stateless.MapLogic.GetMappingSegmentB(ticks, personBirthday, approximateYears, minimumDateTime, isWrongYear);
|
|
|
|
|
mapping = new(approximateYears, displayDirectoryName, forced, face.Location.NormalizedPixelPercentage, personBirthday, mappingSegmentB);
|
|
|
|
|
closest = new(aboveTolerance, zero, face.Location.NormalizedPixelPercentage.Value, isWrongYear, mapping, zero, minimumDateTime, null);
|
|
|
|
|
item.Closest.Add(closest);
|
|
|
|
|
item.Mapping.Add(mapping);
|
|
|
|
|
if (personKey is not null)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (ticks is not null)
|
|
|
|
|
if (personKey is not null)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (ticks is not null || count == 0)
|
|
|
|
|
if (personKey is not null || count == 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (ticks is null && count != 0)
|
|
|
|
|
if (personKey is null && count != 0)
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SavePropertyHolders(string argZero, Container[] containers)
|
|
|
|
|
public void SavePropertyHolders(Item[] items)
|
|
|
|
|
{
|
|
|
|
|
string json;
|
|
|
|
|
FileInfo fileInfo;
|
|
|
|
|
bool updateDateWhenMatches = false;
|
|
|
|
|
JsonSerializerOptions jsonSerializerOptions = new() { WriteIndented = true };
|
|
|
|
|
foreach (Container container in containers)
|
|
|
|
|
foreach (Item item in items)
|
|
|
|
|
{
|
|
|
|
|
if (!container.Items.Any())
|
|
|
|
|
if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null)
|
|
|
|
|
continue;
|
|
|
|
|
if (!container.SourceDirectory.StartsWith(argZero))
|
|
|
|
|
if (!item.Faces.Any() || !item.Closest.Any())
|
|
|
|
|
continue;
|
|
|
|
|
foreach (Item item in container.Items)
|
|
|
|
|
{
|
|
|
|
|
if (item.ImageFileHolder is null || item.Property is null || !item.Faces.Any() || !item.Closest.Any())
|
|
|
|
|
continue;
|
|
|
|
|
json = JsonSerializer.Serialize(item, jsonSerializerOptions);
|
|
|
|
|
fileInfo = new(Path.GetFullPath(string.Concat(_ZPropertyHolderSingletonTicksDirectory, item.RelativePath, ".json")));
|
|
|
|
|
if (fileInfo.Directory is null)
|
|
|
|
|
continue;
|
|
|
|
|
if (!fileInfo.Directory.Exists)
|
|
|
|
|
continue;
|
|
|
|
|
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches, compareBeforeWrite: true);
|
|
|
|
|
}
|
|
|
|
|
json = JsonSerializer.Serialize(item, jsonSerializerOptions);
|
|
|
|
|
fileInfo = new(Path.GetFullPath(string.Concat(_ZPropertyHolderSingletonTicksDirectory, item.RelativePath, ".json")));
|
|
|
|
|
if (fileInfo.Directory is null)
|
|
|
|
|
continue;
|
|
|
|
|
if (!fileInfo.Directory.Exists)
|
|
|
|
|
continue;
|
|
|
|
|
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches, compareBeforeWrite: true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|