After testing E_Distance.SaveGroupedFaceEncodings

This commit is contained in:
2022-08-07 12:29:46 -07:00
parent 2158b4cfc2
commit daf5f428b9
57 changed files with 2626 additions and 660 deletions

View File

@ -65,37 +65,37 @@ public class Configuration
public static void Verify(Configuration? propertyConfiguration)
{
if (propertyConfiguration is null)
throw new Exception($"{nameof(propertyConfiguration)} must be set!");
throw new ArgumentNullException(nameof(propertyConfiguration));
if (propertyConfiguration.ForcePropertyLastWriteTimeToCreationTime is null)
throw new Exception($"{nameof(propertyConfiguration.ForcePropertyLastWriteTimeToCreationTime)} must be set!");
throw new ArgumentNullException(nameof(propertyConfiguration.ForcePropertyLastWriteTimeToCreationTime));
if (propertyConfiguration.IgnoreExtensions is null || !propertyConfiguration.IgnoreExtensions.Any())
throw new Exception($"{nameof(propertyConfiguration.IgnoreExtensions)} must be set!");
throw new ArgumentNullException(nameof(propertyConfiguration.IgnoreExtensions));
if (propertyConfiguration.PopulatePropertyId is null)
throw new Exception($"{nameof(propertyConfiguration.PopulatePropertyId)} must be set!");
throw new ArgumentNullException(nameof(propertyConfiguration.PopulatePropertyId));
if (propertyConfiguration.PropertiesChangedForProperty is null)
throw new Exception($"{nameof(propertyConfiguration.PropertiesChangedForProperty)} must be set!");
throw new ArgumentNullException(nameof(propertyConfiguration.PropertiesChangedForProperty));
if (propertyConfiguration.PropertyContentCollectionFiles is null)
throw new Exception($"{nameof(propertyConfiguration.PropertyContentCollectionFiles)} must be set!");
throw new ArgumentNullException(nameof(propertyConfiguration.PropertyContentCollectionFiles));
if (propertyConfiguration.ValidImageFormatExtensions is null || !propertyConfiguration.ValidImageFormatExtensions.Any())
throw new Exception($"{nameof(propertyConfiguration.ValidImageFormatExtensions)} must be set!");
throw new ArgumentNullException(nameof(propertyConfiguration.ValidImageFormatExtensions));
if (propertyConfiguration.ValidMetadataExtensions is null || !propertyConfiguration.ValidMetadataExtensions.Any())
throw new Exception($"{nameof(propertyConfiguration.ValidMetadataExtensions)} must be set!");
throw new ArgumentNullException(nameof(propertyConfiguration.ValidMetadataExtensions));
if (propertyConfiguration.VerifyToSeason is null || !propertyConfiguration.VerifyToSeason.Any())
throw new Exception($"{nameof(propertyConfiguration.VerifyToSeason)} must be set!");
throw new ArgumentNullException(nameof(propertyConfiguration.VerifyToSeason));
if (propertyConfiguration.WriteBitmapDataBytes is null)
throw new Exception($"{nameof(propertyConfiguration.WriteBitmapDataBytes)} must be set!");
throw new ArgumentNullException(nameof(propertyConfiguration.WriteBitmapDataBytes));
if (Path.GetPathRoot(propertyConfiguration.RootDirectory) == propertyConfiguration.RootDirectory)
throw new Exception($"{nameof(propertyConfiguration.RootDirectory)} should have at least one level!");
throw new ArgumentNullException(nameof(propertyConfiguration.RootDirectory));
if (propertyConfiguration is null)
throw new Exception($"{nameof(propertyConfiguration)} must be set!");
throw new ArgumentNullException(nameof(propertyConfiguration));
if (string.IsNullOrEmpty(propertyConfiguration.DateGroup))
throw new Exception($"{nameof(propertyConfiguration.DateGroup)} must have a value!");
throw new ArgumentNullException(nameof(propertyConfiguration.DateGroup));
if (string.IsNullOrEmpty(propertyConfiguration.FileNameDirectorySeparator))
throw new Exception($"{nameof(propertyConfiguration.FileNameDirectorySeparator)} must have a value!");
throw new ArgumentNullException(nameof(propertyConfiguration.FileNameDirectorySeparator));
if (string.IsNullOrEmpty(propertyConfiguration.Pattern))
throw new Exception($"{nameof(propertyConfiguration.Pattern)} must have a value!");
throw new ArgumentNullException(nameof(propertyConfiguration.Pattern));
if (string.IsNullOrEmpty(propertyConfiguration.RootDirectory) || !Directory.Exists(propertyConfiguration.RootDirectory))
throw new Exception($"{nameof(propertyConfiguration.RootDirectory)} must have a value and exits!");
throw new ArgumentNullException(nameof(propertyConfiguration.RootDirectory));
}
public void ChangeRootDirectory(string rootDirectory) => _RootDirectory = rootDirectory;

View File

@ -1,4 +1,6 @@
using System.Text.Json.Serialization;
using View_by_Distance.Shared.Models;
using View_by_Distance.Shared.Models.Properties;
namespace View_by_Distance.Property.Models;
@ -7,13 +9,13 @@ public class PropertyHolder
protected readonly bool? _Abandoned;
protected readonly bool? _Changed;
protected List<object> _Faces;
protected List<IFace> _Faces;
protected readonly FileInfo? _ImageFileInfo;
protected readonly string _ImageFileNameWithoutExtension;
protected readonly int _G;
protected DateTime? _MinimumDateTime;
protected bool? _Moved;
protected List<(bool?, string, TimeSpan?)> _Named;
protected List<(bool?, DateTime, PersonBirthday, double?)> _Named;
protected readonly bool? _NoJson;
protected A_Property? _Property;
protected readonly int _R;
@ -24,14 +26,14 @@ public class PropertyHolder
protected bool? _ValidImageFormatExtension;
public bool? Abandoned => _Abandoned;
public bool? Changed => _Changed;
public List<object> Faces => _Faces;
public List<IFace> Faces => _Faces;
public FileInfo? ImageFileInfo => _ImageFileInfo;
public string ImageFileNameWithoutExtension => _ImageFileNameWithoutExtension;
public int G => _G;
public DateTime? MinimumDateTime => _MinimumDateTime;
public bool? Moved => _Moved;
public bool? NoJson => _NoJson;
public List<(bool? IsWrongYear, string PersonKey, TimeSpan? TimeSpan)> Named => _Named;
public List<(bool? isWrongYear, DateTime minimumDateTime, PersonBirthday personBirthday, double? pixelPercentage)> Named => _Named;
public A_Property? Property => _Property;
public int R => _R;
public string RelativePath => _RelativePath;
@ -96,20 +98,15 @@ public class PropertyHolder
_MinimumDateTime = Stateless.A_Property.GetMinimumDateTime(property);
}
public static void AddToFaces(PropertyHolder[] filteredPropertyHolderCollection, object[] faces)
{
foreach (PropertyHolder propertyHolder in filteredPropertyHolderCollection)
propertyHolder.Faces.AddRange(faces);
}
public static void AddToNamed(PropertyLogic propertyLogic, PropertyHolder[] filteredPropertyHolderCollection)
{
bool? isWrongYear;
TimeSpan? timeSpan;
DateTime? birthDate;
string[] segments;
string[] personKeys;
double? pixelPercentage;
DateTime minimumDateTime;
PropertyHolder propertyHolder;
PersonBirthday? personBirthday;
for (int i = 0; i < filteredPropertyHolderCollection.Length; i++)
{
propertyHolder = filteredPropertyHolderCollection[i];
@ -122,21 +119,187 @@ public class PropertyHolder
minimumDateTime = Stateless.A_Property.GetMinimumDateTime(propertyHolder.Property);
personKeys = propertyLogic.NamedFaceInfoDeterministicHashCodeIndices[propertyHolder.Property.Id.Value];
(isWrongYear, _) = propertyHolder.Property.IsWrongYear(propertyHolder.ImageFileInfo.FullName, minimumDateTime);
foreach (string personKey in personKeys)
for (int j = 0; j < personKeys.Length; j++)
{
if (isWrongYear is null || isWrongYear.Value || personKey[..2] is not "19" and not "20")
timeSpan = null;
segments = Shared.Models.Stateless.Methods.IPersonBirthday.GetSegments(personKeys[j]);
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(personKeys[j]);
if (personBirthday is null)
continue;
if (segments.Length <= 1 || !double.TryParse(segments[1], out double value))
pixelPercentage = null;
else
{
birthDate = Shared.Models.Stateless.Methods.IPersonBirthday.Get(personKey);
if (birthDate is null)
timeSpan = null;
else
timeSpan = new(minimumDateTime.Ticks - birthDate.Value.Ticks);
}
propertyHolder.Named.Add(new(isWrongYear, personKey, timeSpan));
pixelPercentage = value;
propertyHolder.Named.Add(new(isWrongYear, minimumDateTime, personBirthday, pixelPercentage));
}
}
}
public static List<(PropertyHolder, (string, IFace?, (string, string, string, string))[])> GetCollection(PropertyLogic propertyLogic, PropertyHolder[] filteredPropertyHolderCollection, string dFacesContentDirectory)
{
List<(PropertyHolder, (string, IFace?, (string, string, string, string))[])> results = new();
string[] keys;
string directory;
string personKey;
bool? isWrongYear;
string[] segments;
const int zero = 0;
TimeSpan? timeSpan;
string copyFileName;
string copyDirectory;
string? relativePath;
string isWrongYearFlag;
string shortcutFileName;
string subDirectoryName;
List<int> indices = new();
List<IFace> faceCollection;
PropertyHolder propertyHolder;
PersonBirthday? personBirthday;
List<(string, IFace?, (string, string, string, string))> collection;
for (int i = 0; i < filteredPropertyHolderCollection.Length; i++)
{
indices.Clear();
personKey = string.Empty;
copyFileName = string.Empty;
copyDirectory = string.Empty;
propertyHolder = filteredPropertyHolderCollection[i];
if (propertyHolder.ImageFileInfo is null)
continue;
relativePath = Path.GetDirectoryName($"C:{propertyHolder.RelativePath}");
if (string.IsNullOrEmpty(relativePath) || relativePath.Length < 3)
continue;
if (propertyHolder.Property?.Id is null || propertyHolder.MinimumDateTime is null || propertyHolder.ResizedFileInfo is null)
continue;
collection = new();
if (!propertyLogic.NamedFaceInfoDeterministicHashCodeIndices.ContainsKey(propertyHolder.Property.Id.Value))
{
faceCollection = new();
directory = Path.Combine(dFacesContentDirectory, $"Unnamed{relativePath[2..]}");
}
else
{
faceCollection = propertyHolder.Faces;
keys = propertyLogic.NamedFaceInfoDeterministicHashCodeIndices[propertyHolder.Property.Id.Value];
(isWrongYear, _) = propertyHolder.Property.IsWrongYear(propertyHolder.ImageFileInfo.FullName, propertyHolder.MinimumDateTime.Value);
isWrongYearFlag = GetWrongYearFlag(isWrongYear);
subDirectoryName = $"{isWrongYearFlag}{propertyHolder.MinimumDateTime.Value:yyyy}";
if (!faceCollection.Any())
directory = Path.Combine(dFacesContentDirectory, $"None{relativePath[2..]}", subDirectoryName);
else if (keys.Length != 1)
directory = Path.Combine(dFacesContentDirectory, $"Not Supported{relativePath[2..]}", subDirectoryName);
else if (faceCollection.Count != 1)
directory = Path.Combine(dFacesContentDirectory, $"Many{relativePath[2..]}", subDirectoryName);
else
{
indices.Add(zero);
segments = Shared.Models.Stateless.Methods.IPersonBirthday.GetSegments(keys[zero]);
personBirthday = Shared.Models.Stateless.Methods.IPersonBirthday.GetPersonBirthday(keys[zero]);
if (personBirthday is null)
continue;
timeSpan = Shared.Models.Stateless.Methods.IPersonBirthday.GetTimeSpan(propertyHolder.MinimumDateTime.Value, isWrongYear, personBirthday);
if (timeSpan.HasValue)
{
if (timeSpan.Value.Ticks < 0)
subDirectoryName = "!---";
else
subDirectoryName = $"^{Math.Floor(timeSpan.Value.TotalDays / 365):000}";
}
personKey = segments[zero];
directory = Path.Combine(dFacesContentDirectory, "Shortcuts", personKey, subDirectoryName);
if (faceCollection[zero].Populated)
copyDirectory = Path.Combine(dFacesContentDirectory, "Images", personKey, subDirectoryName);
else
copyDirectory = Path.Combine(dFacesContentDirectory, "ImagesBut", personKey, subDirectoryName);
copyFileName = Path.Combine(copyDirectory, $"{propertyHolder.Property.Id.Value}{propertyHolder.ResizedFileInfo.Extension}");
}
}
shortcutFileName = Path.Combine(directory, $"{propertyHolder.Property.Id.Value}.lnk");
if (string.IsNullOrEmpty(personKey) || !indices.Any())
collection.Add(new(personKey, null, (directory, copyDirectory, copyFileName, shortcutFileName)));
else
{
foreach (int index in indices)
collection.Add(new(personKey, faceCollection[index], (directory, copyDirectory, copyFileName, shortcutFileName)));
}
results.Add(new(propertyHolder, collection.ToArray()));
}
return results;
}
private static Dictionary<string, List<(string[], PersonBirthday, IFace)>> GetKeyValuePairs(string argZero, List<PropertyHolder[]> propertyHolderCollections, string eDistanceCollectionDirectory)
{
Dictionary<string, List<(string[], PersonBirthday, IFace)>> results = new();
string key;
string personKey;
TimeSpan? timeSpan;
string[] directories;
string isWrongYearFlag;
string facePopulatedKey;
foreach (PropertyHolder[] propertyHolderCollection in propertyHolderCollections)
{
if (!propertyHolderCollection.Any())
continue;
if (!propertyHolderCollection[0].SourceDirectory.StartsWith(argZero))
continue;
foreach (PropertyHolder propertyHolder in propertyHolderCollection)
{
if (propertyHolder.ImageFileInfo is null || propertyHolder.Property is null || !propertyHolder.Named.Any())
continue;
foreach ((bool? isWrongYear, DateTime minimumDateTime, PersonBirthday personBirthday, double? pixelPercentage) in propertyHolder.Named)
{
if (propertyHolder.MinimumDateTime is null)
continue;
if (pixelPercentage is null && (propertyHolder.Named.Count != 1 || propertyHolder.Faces.Count != 1))
continue;
foreach (IFace face in propertyHolder.Faces)
{
if (pixelPercentage.HasValue && pixelPercentage.Value != face.Location.PixelPercentage)
continue;
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
timeSpan = Shared.Models.Stateless.Methods.IPersonBirthday.GetTimeSpan(minimumDateTime, isWrongYear, personBirthday);
if (face.Populated)
facePopulatedKey = "Images";
else
facePopulatedKey = "ImagesBut";
if (timeSpan.HasValue && timeSpan.Value.Ticks < 0)
directories = new string[] { string.Empty, facePopulatedKey, personKey, "!---" };
else if (timeSpan.HasValue)
directories = new string[] { string.Empty, facePopulatedKey, personKey, $"^{Math.Floor(timeSpan.Value.TotalDays / 365):000}" };
else
{
isWrongYearFlag = GetWrongYearFlag(isWrongYear);
directories = new string[] { string.Empty, facePopulatedKey, personKey, $"{isWrongYearFlag}{propertyHolder.MinimumDateTime.Value:yyyy}" };
}
key = string.Join('\t', directories);
if (!results.ContainsKey(key))
results.Add(key, new());
directories[0] = eDistanceCollectionDirectory;
results[key].Add(new(directories, personBirthday, face));
if (pixelPercentage is null)
break;
}
}
}
}
return results;
}
public static List<(string, PersonBirthday, IFace)[]> GetCollection(string argZero, List<PropertyHolder[]> propertyHolderCollections, string eDistanceCollectionDirectory)
{
List<(string, PersonBirthday, IFace)[]> results = new();
string directory;
List<(string, PersonBirthday, IFace)> group;
Dictionary<string, List<(string[], PersonBirthday, IFace)>> keyValuePairs = GetKeyValuePairs(argZero, propertyHolderCollections, eDistanceCollectionDirectory);
foreach (KeyValuePair<string, List<(string[], PersonBirthday, IFace)>> keyValuePair in keyValuePairs)
{
group = new();
foreach ((string[] directories, PersonBirthday personBirthday, IFace face) in keyValuePair.Value)
{
directory = Path.Combine(directories);
group.Add(new(directory, personBirthday, face));
}
results.Add(group.ToArray());
}
return results;
}
}

View File

@ -57,7 +57,7 @@ public class PropertyLogic
Dictionary<int, string[]>? sixCharacterNamedFaceInfo;
string? rootDirectoryParent = Path.GetDirectoryName(configuration.RootDirectory);
if (string.IsNullOrEmpty(rootDirectoryParent))
throw new Exception($"{nameof(rootDirectoryParent)} is null!");
throw new ArgumentNullException(nameof(rootDirectoryParent));
files = Directory.GetFiles(rootDirectoryParent, "*DeterministicHashCode*.json", SearchOption.TopDirectoryOnly);
if (files.Length != 1)
namedFaceInfoDeterministicHashCodeIndices = new();
@ -66,7 +66,7 @@ public class PropertyLogic
json = File.ReadAllText(files[0]);
namedFaceInfoDeterministicHashCodeIndices = JsonSerializer.Deserialize<Dictionary<int, string[]>>(json);
if (namedFaceInfoDeterministicHashCodeIndices is null)
throw new Exception($"{nameof(namedFaceInfoDeterministicHashCodeIndices)} is null!");
throw new ArgumentNullException(nameof(namedFaceInfoDeterministicHashCodeIndices));
}
if (namedFaceInfoDeterministicHashCodeIndices.Any())
sixCharacterNamedFaceInfo = new();
@ -80,7 +80,7 @@ public class PropertyLogic
json = File.ReadAllText(files[0]);
sixCharacterNamedFaceInfo = JsonSerializer.Deserialize<Dictionary<int, string[]>>(json);
if (sixCharacterNamedFaceInfo is null)
throw new Exception($"{nameof(sixCharacterNamedFaceInfo)} is null!");
throw new ArgumentNullException(nameof(sixCharacterNamedFaceInfo));
}
}
files = Directory.GetFiles(rootDirectoryParent, "*keyValuePairs*.json", SearchOption.TopDirectoryOnly);
@ -91,7 +91,7 @@ public class PropertyLogic
json = File.ReadAllText(files[0]);
keyValuePairs = JsonSerializer.Deserialize<Dictionary<int, int[]>>(json);
if (keyValuePairs is null)
throw new Exception($"{nameof(keyValuePairs)} is null!");
throw new ArgumentNullException(nameof(keyValuePairs));
}
foreach (string propertyContentCollectionFile in configuration.PropertyContentCollectionFiles)
{
@ -103,7 +103,7 @@ public class PropertyLogic
json = File.ReadAllText(fullPath);
collection = JsonSerializer.Deserialize<List<KeyValuePair<int, int[]>>>(json);
if (collection is null)
throw new Exception($"{nameof(collection)} is null!");
throw new ArgumentNullException(nameof(collection));
foreach (KeyValuePair<int, int[]> keyValuePair in collection)
{
if (indicesFromNew.ContainsKey(keyValuePair.Key))
@ -127,7 +127,7 @@ public class PropertyLogic
{
long result;
if (_Log is null)
throw new Exception($"{nameof(_Log)} is null!");
throw new ArgumentNullException(nameof(_Log));
double delta = new TimeSpan(DateTime.Now.Ticks - ticks).TotalMilliseconds;
_Log.Debug($"{methodName} took {Math.Floor(delta)} millisecond(s)");
result = DateTime.Now.Ticks;
@ -172,9 +172,9 @@ public class PropertyLogic
{
A_Property result;
if (_Log is null)
throw new Exception($"{nameof(_Log)} is null!");
throw new ArgumentNullException(nameof(_Log));
if (_Configuration.WriteBitmapDataBytes is null)
throw new Exception($"{nameof(_Configuration.WriteBitmapDataBytes)} is null!");
throw new ArgumentNullException(nameof(_Configuration.WriteBitmapDataBytes));
long ticks;
byte[] bytes;
string value;
@ -340,11 +340,11 @@ public class PropertyLogic
{
A_Property? result;
if (_Configuration.ForcePropertyLastWriteTimeToCreationTime is null)
throw new Exception($"{nameof(_Configuration.ForcePropertyLastWriteTimeToCreationTime)} is null!");
throw new ArgumentNullException(nameof(_Configuration.ForcePropertyLastWriteTimeToCreationTime));
if (_Configuration.PopulatePropertyId is null)
throw new Exception($"{nameof(_Configuration.PopulatePropertyId)} is null!");
throw new ArgumentNullException(nameof(_Configuration.PopulatePropertyId));
if (_Configuration.PropertiesChangedForProperty is null)
throw new Exception($"{nameof(_Configuration.PropertiesChangedForProperty)} is null!");
throw new ArgumentNullException(nameof(_Configuration.PropertiesChangedForProperty));
string json;
int? id = null;
List<int> indices = new();
@ -464,7 +464,7 @@ public class PropertyLogic
throw new ArgumentException($"{propertyHolder.ImageFileInfo} is null!");
result = GetImageProperty(angleBracket, propertyHolder.ImageFileInfo, populateId, isIgnoreExtension, isValidImageFormatExtension, isValidMetadataExtensions, id, indices);
json = JsonSerializer.Serialize(result, _WriteIndentedJsonSerializerOptions);
if (populateId && IPath.WriteAllText(fileInfo.FullName, json, compareBeforeWrite: true))
if (populateId && IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches: true, compareBeforeWrite: true))
{
if (!_Configuration.ForcePropertyLastWriteTimeToCreationTime.Value && (!fileInfo.Exists || fileInfo.LastWriteTime == fileInfo.CreationTime))
filteredSourceDirectoryFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), DateTime.Now));
@ -479,7 +479,7 @@ public class PropertyLogic
else if (hasWrongYearProperty)
{
json = JsonSerializer.Serialize(result, _WriteIndentedJsonSerializerOptions);
if (IPath.WriteAllText(fileInfo.FullName, json, compareBeforeWrite: true))
if (IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches: true, compareBeforeWrite: true))
{
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
fileInfo.Refresh();
@ -493,7 +493,7 @@ public class PropertyLogic
{
bool result = false;
if (_Log is null)
throw new Exception($"{nameof(_Log)} is null!");
throw new ArgumentNullException(nameof(_Log));
int season;
string[] matches;
string deleteFile;
@ -603,41 +603,10 @@ public class PropertyLogic
return result;
}
private void WriteGroup(int sourceDirectoryLength, PropertyHolder[] filteredPropertyHolderCollection, string angleBracket)
{
if (!(from l in filteredPropertyHolderCollection where l?.Property?.Width is null select true).Any())
{
string key;
string json;
string checkFile;
string checkDirectory;
List<KeyValuePair<string, A_Property>> propertyCollectionKeyValuePairs = new();
JsonSerializerOptions writeIndentedJsonSerializerOptions = new() { WriteIndented = false };
(int level, List<string> directories) = IPath.Get(_Configuration.RootDirectory, filteredPropertyHolderCollection[0].SourceDirectory);
string fileName = string.Concat(string.Join(_Configuration.FileNameDirectorySeparator, directories), ".json");
foreach (PropertyHolder propertyHolder in filteredPropertyHolderCollection)
{
if (propertyHolder.Property is null)
continue;
if (propertyHolder.ImageFileInfo is null)
continue;
key = IPath.GetRelativePath(propertyHolder.ImageFileInfo.FullName, sourceDirectoryLength);
propertyCollectionKeyValuePairs.Add(new KeyValuePair<string, A_Property>(key, propertyHolder.Property));
}
checkDirectory = IPath.GetDirectory(angleBracket, level, "[{}]");
checkFile = Path.Combine(checkDirectory, fileName);
if (File.Exists(checkFile))
File.Move(checkFile, Path.Combine(checkDirectory, fileName));
checkFile = Path.Combine(checkDirectory, fileName);
json = JsonSerializer.Serialize(propertyCollectionKeyValuePairs, writeIndentedJsonSerializerOptions);
_ = IPath.WriteAllText(checkFile, json, compareBeforeWrite: true);
}
}
private void ParallelForWork(bool firstPass, string angleBracket, string sourceDirectory, List<Tuple<string, DateTime>> filteredSourceDirectoryFileTuples, PropertyHolder propertyHolder)
{
if (propertyHolder.ImageFileInfo is null)
throw new Exception($"{nameof(propertyHolder.ImageFileInfo)} is null!");
throw new ArgumentNullException(nameof(propertyHolder.ImageFileInfo));
A_Property property;
List<string> parseExceptions = new();
string extensionLowered = propertyHolder.ImageFileInfo.Extension.ToLower();
@ -708,18 +677,18 @@ public class PropertyLogic
public void ParallelWork(Configuration configuration, Model? model, PredictorModel? predictorModel, long ticks, List<PropertyHolder[]> propertyHolderCollections, bool firstPass)
{
if (_Log is null)
throw new Exception($"{nameof(_Log)} is null!");
throw new ArgumentNullException(nameof(_Log));
if (_Configuration.PopulatePropertyId is null)
throw new Exception($"{nameof(_Configuration.PopulatePropertyId)} is null!");
throw new ArgumentNullException(nameof(_Configuration.PopulatePropertyId));
int g;
int r;
int totalSeconds;
bool? anyFilesMoved;
string angleBracket;
string sourceDirectory;
List<Exception> exceptions = new();
PropertyHolder[] filteredPropertyHolderCollection;
List<Tuple<string, DateTime>> sourceDirectoryChanges = new();
int sourceDirectoryLength = configuration.RootDirectory.Length;
int propertyHolderCollectionsCount = propertyHolderCollections.Count;
string propertyRoot = IResult.GetResultsGroupDirectory(configuration, nameof(A_Property));
foreach (PropertyHolder[] propertyHolderCollection in propertyHolderCollections)
@ -745,13 +714,10 @@ public class PropertyLogic
throw new Exception(string.Concat("All in [", sourceDirectory, "]failed!"));
if (exceptions.Count != 0)
_ExceptionsDirectories.Add(sourceDirectory);
bool? anyFilesMoved;
if (!firstPass || exceptions.Count != 0)
anyFilesMoved = null;
else
anyFilesMoved = AnyFilesMoved(sourceDirectory, filteredPropertyHolderCollection);
if (exceptions.Count == 0 && !firstPass && _Configuration.PopulatePropertyId.Value && (anyFilesMoved is null || !anyFilesMoved.Value))
WriteGroup(sourceDirectoryLength, filteredPropertyHolderCollection, angleBracket);
if (Directory.GetFiles(propertyRoot, "*.txt", SearchOption.TopDirectoryOnly).Any())
{
for (int y = 0; y < int.MaxValue; y++)
@ -843,7 +809,7 @@ public class PropertyLogic
string[] keys;
string? rootDirectoryParent = Path.GetDirectoryName(_Configuration.RootDirectory);
if (string.IsNullOrEmpty(rootDirectoryParent))
throw new Exception($"{nameof(rootDirectoryParent)} is null!");
throw new ArgumentNullException(nameof(rootDirectoryParent));
Dictionary<int, string[]> namedFaceInfoDeterministicHashCodeIndices = new();
List<(int, string[])> allCollection = _AllCollection.OrderBy(l => l.Item1).ToList();
foreach ((int deterministicHashCode, string[] values) in allCollection)
@ -859,7 +825,7 @@ public class PropertyLogic
}
string json = JsonSerializer.Serialize(namedFaceInfoDeterministicHashCodeIndices, new JsonSerializerOptions { WriteIndented = true });
string checkFile = Path.Combine(rootDirectoryParent, "NamedFaceInfoDeterministicHashCodeIndices.json");
_ = IPath.WriteAllText(checkFile, json, compareBeforeWrite: true);
_ = IPath.WriteAllText(checkFile, json, updateDateWhenMatches: true, compareBeforeWrite: true);
}
}

View File

@ -119,7 +119,7 @@ public static class A_Property
public static List<(int g, string sourceDirectory, FileInfo[] sourceDirectoryFiles, int r)> GetFileInfoGroupCollection(Models.Configuration configuration, bool reverse, string searchPattern, List<string> topDirectories)
{
if (configuration.MaxImagesInDirectoryForTopLevelFirstPass is null)
throw new Exception($"{nameof(configuration.MaxImagesInDirectoryForTopLevelFirstPass)} is null!");
throw new ArgumentNullException(nameof(configuration.MaxImagesInDirectoryForTopLevelFirstPass));
List<(int g, string sourceDirectory, FileInfo[] sourceDirectoryFiles, int r)> results = new();
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)>? collection = GetGroupCollection(configuration.RootDirectory, searchPattern, topDirectories, configuration.MaxImagesInDirectoryForTopLevelFirstPass.Value, reverse);
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles, int r) in collection)

View File

@ -12,8 +12,8 @@ public interface IPath
List<string> TestStatic_GetDirectoryNames(string directory);
static List<string> GetDirectoryNames(string directory) => XPath.GetDirectoryNames(directory);
bool TestStatic_WriteAllText(string path, string contents, bool compareBeforeWrite);
static bool WriteAllText(string path, string contents, bool compareBeforeWrite) => XPath.WriteAllText(path, contents, compareBeforeWrite);
bool TestStatic_WriteAllText(string path, string contents, bool updateDateWhenMatches, bool compareBeforeWrite);
static bool WriteAllText(string path, string contents, bool updateDateWhenMatches, bool compareBeforeWrite, DateTime? updateToWhenMatches = null) => XPath.WriteAllText(path, contents, updateDateWhenMatches, compareBeforeWrite, updateToWhenMatches);
(int level, List<string> directories) TestStatic_Get(string rootDirectory, string sourceDirectory);
static (int level, List<string> directories) Get(string rootDirectory, string sourceDirectory) => XPath.Get(rootDirectory, sourceDirectory);

View File

@ -46,7 +46,7 @@ internal class XPath
return result;
}
internal static bool WriteAllText(string path, string contents, bool compareBeforeWrite)
internal static bool WriteAllText(string path, string contents, bool updateDateWhenMatches, bool compareBeforeWrite, DateTime? updateToWhenMatches)
{
bool result;
string text;
@ -59,6 +59,13 @@ internal class XPath
else
text = File.ReadAllText(path);
result = text != contents;
if (!result && updateDateWhenMatches)
{
if (updateToWhenMatches is null)
File.SetLastWriteTime(path, DateTime.Now);
else
File.SetLastWriteTime(path, updateToWhenMatches.Value);
}
}
if (result)
{
@ -85,7 +92,7 @@ internal class XPath
string? pathRoot = Path.GetPathRoot(directory);
string extension = Path.GetExtension(directory);
if (string.IsNullOrEmpty(pathRoot))
throw new Exception($"{nameof(pathRoot)} is null!");
throw new ArgumentNullException(nameof(pathRoot));
if (Directory.Exists(directory))
results.Add(Path.GetFileName(directory));
else if ((string.IsNullOrEmpty(extension) || extension.Length > 3) && !File.Exists(directory))