Added FileHolder
This commit is contained in:
parent
daf5f428b9
commit
3aeab88384
@ -196,7 +196,7 @@ public class DateGroup
|
|||||||
DateTime? minimumDateTime = null;
|
DateTime? minimumDateTime = null;
|
||||||
List<string> destinationCollection;
|
List<string> destinationCollection;
|
||||||
List<string> directoryNames = new();
|
List<string> directoryNames = new();
|
||||||
FileInfo filteredSourceDirectoryFileInfo;
|
FileHolder filteredSourceDirectoryFileHolder;
|
||||||
List<string> topDirectorySegments = new();
|
List<string> topDirectorySegments = new();
|
||||||
StringBuilder destinationDirectoryName = new();
|
StringBuilder destinationDirectoryName = new();
|
||||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||||
@ -233,7 +233,7 @@ public class DateGroup
|
|||||||
}
|
}
|
||||||
if (matches is null)
|
if (matches is null)
|
||||||
matches = Array.Empty<string>();
|
matches = Array.Empty<string>();
|
||||||
for (int i = 0; i < group.SourceDirectoryFileInfoCollection.Length; i++)
|
for (int i = 0; i < group.SourceDirectoryFileHolderCollection.Length; i++)
|
||||||
{
|
{
|
||||||
destinationCollection = new();
|
destinationCollection = new();
|
||||||
directoryNames.Clear();
|
directoryNames.Clear();
|
||||||
@ -241,14 +241,14 @@ public class DateGroup
|
|||||||
property = group.PropertyCollection[i];
|
property = group.PropertyCollection[i];
|
||||||
if (property is null)
|
if (property is null)
|
||||||
continue;
|
continue;
|
||||||
filteredSourceDirectoryFileInfo = group.SourceDirectoryFileInfoCollection[i];
|
filteredSourceDirectoryFileHolder = group.SourceDirectoryFileHolderCollection[i];
|
||||||
minimumDateTime = Property.Models.Stateless.A_Property.GetMinimumDateTime(property);
|
minimumDateTime = Property.Models.Stateless.A_Property.GetMinimumDateTime(property);
|
||||||
directory = filteredSourceDirectoryFileInfo.DirectoryName;
|
directory = filteredSourceDirectoryFileHolder.DirectoryName;
|
||||||
if (string.IsNullOrEmpty(directory))
|
if (string.IsNullOrEmpty(directory))
|
||||||
continue;
|
continue;
|
||||||
day = minimumDateTime.Value.ToString("MM-dd");
|
day = minimumDateTime.Value.ToString("MM-dd");
|
||||||
month = minimumDateTime.Value.ToString("MMMM");
|
month = minimumDateTime.Value.ToString("MMMM");
|
||||||
(propertyWrongYear, _) = property.IsWrongYear(filteredSourceDirectoryFileInfo.FullName, minimumDateTime);
|
(propertyWrongYear, _) = property.IsWrongYear(filteredSourceDirectoryFileHolder.FullName, minimumDateTime);
|
||||||
if (propertyWrongYear is null)
|
if (propertyWrongYear is null)
|
||||||
flag = '#';
|
flag = '#';
|
||||||
else
|
else
|
||||||
@ -317,13 +317,13 @@ public class DateGroup
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!_Configuration.ByHash.Value || property.Id is null)
|
if (!_Configuration.ByHash.Value || property.Id is null)
|
||||||
fileName = filteredSourceDirectoryFileInfo.Name;
|
fileName = filteredSourceDirectoryFileHolder.Name;
|
||||||
else
|
else
|
||||||
fileName = $"{property.Id.Value}{filteredSourceDirectoryFileInfo.Extension.ToLower()}";
|
fileName = $"{property.Id.Value}{filteredSourceDirectoryFileHolder.Extension.ToLower()}";
|
||||||
destinationCollection.Add(destinationDirectory);
|
destinationCollection.Add(destinationDirectory);
|
||||||
destinationCollection.AddRange(directoryNames);
|
destinationCollection.AddRange(directoryNames);
|
||||||
destinationCollection.Add(fileName);
|
destinationCollection.Add(fileName);
|
||||||
results.Add(new(filteredSourceDirectoryFileInfo.FullName, destinationCollection.ToArray()));
|
results.Add(new(filteredSourceDirectoryFileHolder.FullName, destinationCollection.ToArray()));
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
@ -305,10 +305,10 @@ public class DlibDotNet
|
|||||||
throw new Exception("Input directory should be the source and not a resized directory!");
|
throw new Exception("Input directory should be the source and not a resized directory!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FullParallelForWork(PropertyLogic propertyLogic, object @lock, string outputResolution, List<Tuple<string, DateTime>> sourceDirectoryChanges, List<FileInfo?> propertyFileInfoCollection, List<A_Property> propertyCollection, List<List<KeyValuePair<string, string>>> metadataCollections, List<Dictionary<string, int[]>> resizeKeyValuePairs, List<List<D_Face>> imageFaceCollections, string sourceDirectory, int index, PropertyHolder propertyHolder)
|
private void FullParallelForWork(PropertyLogic propertyLogic, string outputResolution, List<Tuple<string, DateTime>> sourceDirectoryChanges, List<FileHolder?> propertyFileHolderCollection, List<A_Property> propertyCollection, List<List<KeyValuePair<string, string>>> metadataCollections, List<Dictionary<string, int[]>> resizeKeyValuePairs, List<List<D_Face>> imageFaceCollections, string sourceDirectory, int index, PropertyHolder propertyHolder)
|
||||||
{
|
{
|
||||||
if (propertyHolder.ImageFileInfo is null)
|
if (propertyHolder.ImageFileHolder is null)
|
||||||
throw new ArgumentNullException(nameof(propertyHolder.ImageFileInfo));
|
throw new ArgumentNullException(nameof(propertyHolder.ImageFileHolder));
|
||||||
if (_AppSettings.MaxDegreeOfParallelism is null)
|
if (_AppSettings.MaxDegreeOfParallelism is null)
|
||||||
throw new ArgumentNullException(nameof(_AppSettings.MaxDegreeOfParallelism));
|
throw new ArgumentNullException(nameof(_AppSettings.MaxDegreeOfParallelism));
|
||||||
if (_Configuration.SaveResizedSubfiles is null)
|
if (_Configuration.SaveResizedSubfiles is null)
|
||||||
@ -328,7 +328,8 @@ public class DlibDotNet
|
|||||||
List<KeyValuePair<string, string>> metadataCollection;
|
List<KeyValuePair<string, string>> metadataCollection;
|
||||||
if (propertyHolder.Property is null)
|
if (propertyHolder.Property is null)
|
||||||
{
|
{
|
||||||
sourceDirectoryChanges.Add(new Tuple<string, DateTime>(nameof(A_Property), propertyHolder.ImageFileInfo.LastWriteTime));
|
lock (sourceDirectoryChanges)
|
||||||
|
sourceDirectoryChanges.Add(new Tuple<string, DateTime>(nameof(A_Property), DateTime.Now));
|
||||||
property = propertyLogic.GetProperty(propertyLogic.AngleBracketCollection[0], propertyHolder, subFileTuples, parseExceptions);
|
property = propertyLogic.GetProperty(propertyLogic.AngleBracketCollection[0], propertyHolder, subFileTuples, parseExceptions);
|
||||||
propertyHolder.Update(property);
|
propertyHolder.Update(property);
|
||||||
}
|
}
|
||||||
@ -336,13 +337,16 @@ public class DlibDotNet
|
|||||||
{
|
{
|
||||||
property = propertyHolder.Property;
|
property = propertyHolder.Property;
|
||||||
if (propertyHolder.Changed.HasValue && propertyHolder.Changed.Value)
|
if (propertyHolder.Changed.HasValue && propertyHolder.Changed.Value)
|
||||||
sourceDirectoryChanges.Add(new Tuple<string, DateTime>(nameof(A_Property), propertyHolder.ImageFileInfo.LastWriteTime));
|
{
|
||||||
|
lock (sourceDirectoryChanges)
|
||||||
|
sourceDirectoryChanges.Add(new Tuple<string, DateTime>(nameof(A_Property), DateTime.Now));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
(int metadataGroups, metadataCollection) = _Metadata.GetMetadataCollection(subFileTuples, parseExceptions, propertyHolder);
|
(int metadataGroups, metadataCollection) = _Metadata.GetMetadataCollection(subFileTuples, parseExceptions, propertyHolder);
|
||||||
if (_AppSettings.MaxDegreeOfParallelism.Value < 2)
|
if (_AppSettings.MaxDegreeOfParallelism.Value < 2)
|
||||||
ticks = LogDelta(ticks, nameof(B_Metadata.GetMetadataCollection));
|
ticks = LogDelta(ticks, nameof(B_Metadata.GetMetadataCollection));
|
||||||
FileInfo resizedFileInfo = new(Path.Combine(_Resize.AngleBracketCollection[0].Replace("<>", "()"), Path.GetFileName(propertyHolder.ImageFileInfo.FullName)));
|
FileHolder resizedFileHolder = new(Path.Combine(_Resize.AngleBracketCollection[0].Replace("<>", "()"), Path.GetFileName(propertyHolder.ImageFileHolder.FullName)));
|
||||||
propertyHolder.SetResizedFileInfo(resizedFileInfo);
|
propertyHolder.SetResizedFileHolder(resizedFileHolder);
|
||||||
imageResizeKeyValuePairs = _Resize.GetResizeKeyValuePairs(subFileTuples, parseExceptions, original, metadataCollection, property, propertyHolder);
|
imageResizeKeyValuePairs = _Resize.GetResizeKeyValuePairs(subFileTuples, parseExceptions, original, metadataCollection, property, propertyHolder);
|
||||||
if (_AppSettings.MaxDegreeOfParallelism.Value < 2)
|
if (_AppSettings.MaxDegreeOfParallelism.Value < 2)
|
||||||
ticks = LogDelta(ticks, nameof(C_Resize.GetResizeKeyValuePairs));
|
ticks = LogDelta(ticks, nameof(C_Resize.GetResizeKeyValuePairs));
|
||||||
@ -351,14 +355,14 @@ public class DlibDotNet
|
|||||||
_Resize.SaveResizedSubfile(outputResolution, subFileTuples, propertyHolder, original, property, imageResizeKeyValuePairs);
|
_Resize.SaveResizedSubfile(outputResolution, subFileTuples, propertyHolder, original, property, imageResizeKeyValuePairs);
|
||||||
if (_AppSettings.MaxDegreeOfParallelism.Value < 2)
|
if (_AppSettings.MaxDegreeOfParallelism.Value < 2)
|
||||||
ticks = LogDelta(ticks, nameof(C_Resize.SaveResizedSubfile));
|
ticks = LogDelta(ticks, nameof(C_Resize.SaveResizedSubfile));
|
||||||
resizedFileInfo.Refresh();
|
propertyHolder.SetResizedFileHolder(FileHolder.Refresh(resizedFileHolder));
|
||||||
}
|
}
|
||||||
else if (outputResolution == _Configuration.OutputResolutions[0] && false)
|
else if (outputResolution == _Configuration.OutputResolutions[0] && false)
|
||||||
{
|
{
|
||||||
byte[] bytes = _Resize.GetResizedBytes(outputResolution, subFileTuples, propertyHolder, property, imageResizeKeyValuePairs);
|
byte[] bytes = _Resize.GetResizedBytes(outputResolution, subFileTuples, propertyHolder, property, imageResizeKeyValuePairs);
|
||||||
if (_AppSettings.MaxDegreeOfParallelism.Value < 2)
|
if (_AppSettings.MaxDegreeOfParallelism.Value < 2)
|
||||||
ticks = LogDelta(ticks, nameof(C_Resize.GetResizedBytes));
|
ticks = LogDelta(ticks, nameof(C_Resize.GetResizedBytes));
|
||||||
string path = Path.Combine(resizedFileInfo.DirectoryName, Path.GetFileNameWithoutExtension(resizedFileInfo.Name));
|
string path = Path.Combine(resizedFileHolder.DirectoryName, resizedFileHolder.NameWithoutExtension);
|
||||||
File.WriteAllBytes(path, bytes);
|
File.WriteAllBytes(path, bytes);
|
||||||
}
|
}
|
||||||
if (!_Configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions.Contains(outputResolution))
|
if (!_Configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions.Contains(outputResolution))
|
||||||
@ -369,7 +373,7 @@ public class DlibDotNet
|
|||||||
int outputResolutionWidth = outputResolutionCollection[0];
|
int outputResolutionWidth = outputResolutionCollection[0];
|
||||||
int outputResolutionHeight = outputResolutionCollection[1];
|
int outputResolutionHeight = outputResolutionCollection[1];
|
||||||
int outputResolutionOrientation = outputResolutionCollection[2];
|
int outputResolutionOrientation = outputResolutionCollection[2];
|
||||||
faceCollection = _Faces.GetFaces(_Configuration.PropertyConfiguration, outputResolution, subFileTuples, parseExceptions, propertyHolder, property, resizedFileInfo, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation);
|
faceCollection = _Faces.GetFaces(_Configuration.PropertyConfiguration, outputResolution, subFileTuples, parseExceptions, propertyHolder, property, resizedFileHolder, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation);
|
||||||
if (_AppSettings.MaxDegreeOfParallelism.Value < 2)
|
if (_AppSettings.MaxDegreeOfParallelism.Value < 2)
|
||||||
ticks = LogDelta(ticks, nameof(D_Face.GetFaces));
|
ticks = LogDelta(ticks, nameof(D_Face.GetFaces));
|
||||||
_Faces.SaveFaces(_Configuration.PropertyConfiguration, subFileTuples, parseExceptions, propertyHolder, faceCollection);
|
_Faces.SaveFaces(_Configuration.PropertyConfiguration, subFileTuples, parseExceptions, propertyHolder, faceCollection);
|
||||||
@ -382,18 +386,18 @@ public class DlibDotNet
|
|||||||
ticks = LogDelta(ticks, nameof(D2_FaceLandmarks.SaveFaceLandmarkImages));
|
ticks = LogDelta(ticks, nameof(D2_FaceLandmarks.SaveFaceLandmarkImages));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lock (@lock)
|
lock (sourceDirectoryChanges)
|
||||||
{
|
{
|
||||||
propertyCollection[index] = property;
|
propertyCollection[index] = property;
|
||||||
imageFaceCollections[index] = faceCollection;
|
imageFaceCollections[index] = faceCollection;
|
||||||
metadataCollections[index] = metadataCollection;
|
metadataCollections[index] = metadataCollection;
|
||||||
resizeKeyValuePairs[index] = imageResizeKeyValuePairs;
|
resizeKeyValuePairs[index] = imageResizeKeyValuePairs;
|
||||||
propertyFileInfoCollection[index] = propertyHolder.ImageFileInfo;
|
propertyFileHolderCollection[index] = propertyHolder.ImageFileHolder;
|
||||||
sourceDirectoryChanges.AddRange(from l in subFileTuples where l.Item2 > dateTime select l);
|
sourceDirectoryChanges.AddRange(from l in subFileTuples where l.Item2 > dateTime select l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int FullParallelWork(object @lock, long ticks, PropertyLogic propertyLogic, string outputResolution, List<Tuple<string, DateTime>> sourceDirectoryChanges, List<FileInfo?> propertyFileInfoCollection, List<A_Property> propertyCollection, List<List<KeyValuePair<string, string>>> metadataCollection, List<Dictionary<string, int[]>> resizeKeyValuePairs, List<List<D_Face>> faceCollections, int propertyHolderCollectionsCount, int g, string sourceDirectory, int r, PropertyHolder[] filteredPropertyHolderCollection)
|
private int FullParallelWork(long ticks, PropertyLogic propertyLogic, string outputResolution, List<Tuple<string, DateTime>> sourceDirectoryChanges, List<FileHolder?> propertyFileHolderCollection, List<A_Property> propertyCollection, List<List<KeyValuePair<string, string>>> metadataCollection, List<Dictionary<string, int[]>> resizeKeyValuePairs, List<List<D_Face>> faceCollections, int propertyHolderCollectionsCount, int g, string sourceDirectory, int r, PropertyHolder[] filteredPropertyHolderCollection)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
if (_Log is null)
|
if (_Log is null)
|
||||||
@ -410,18 +414,19 @@ public class DlibDotNet
|
|||||||
metadataCollection.Add(new());
|
metadataCollection.Add(new());
|
||||||
resizeKeyValuePairs.Add(new());
|
resizeKeyValuePairs.Add(new());
|
||||||
propertyCollection.Add(new());
|
propertyCollection.Add(new());
|
||||||
propertyFileInfoCollection.Add(null);
|
propertyFileHolderCollection.Add(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||||
using (ProgressBar progressBar = new(filteredPropertyHolderCollection.Length, $"{r + 1:000}.{g} / {propertyHolderCollectionsCount:000}) {filteredPropertyHolderCollection.Length:000} file(s) - {totalSeconds} total second(s) - {outputResolution} - {sourceDirectory}", options))
|
string message = $"{r + 1:000}.{g} / {propertyHolderCollectionsCount:000}) {filteredPropertyHolderCollection.Length:000} file(s) - {totalSeconds} total second(s) - {outputResolution} - {sourceDirectory}";
|
||||||
|
using (ProgressBar progressBar = new(filteredPropertyHolderCollection.Length, message, options))
|
||||||
{
|
{
|
||||||
_ = Parallel.For(0, filteredPropertyHolderCollection.Length, parallelOptions, i =>
|
_ = Parallel.For(0, filteredPropertyHolderCollection.Length, parallelOptions, i =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FullParallelForWork(propertyLogic, @lock, outputResolution, sourceDirectoryChanges, propertyFileInfoCollection, propertyCollection, metadataCollection, resizeKeyValuePairs, faceCollections, sourceDirectory, index: i, filteredPropertyHolderCollection[i]);
|
FullParallelForWork(propertyLogic, outputResolution, sourceDirectoryChanges, propertyFileHolderCollection, propertyCollection, metadataCollection, resizeKeyValuePairs, faceCollections, sourceDirectory, index: i, filteredPropertyHolderCollection[i]);
|
||||||
if (sourceDirectoryChanges.Any())
|
if (i == 0 || sourceDirectoryChanges.Any())
|
||||||
progressBar.Tick();
|
progressBar.Tick();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -502,9 +507,9 @@ public class DlibDotNet
|
|||||||
propertyHolder = filteredPropertyHolderCollection[i];
|
propertyHolder = filteredPropertyHolderCollection[i];
|
||||||
if (propertyHolder.Property is null)
|
if (propertyHolder.Property is null)
|
||||||
continue;
|
continue;
|
||||||
if (propertyHolder.ImageFileInfo is null)
|
if (propertyHolder.ImageFileHolder is null)
|
||||||
continue;
|
continue;
|
||||||
key = Property.Models.Stateless.IPath.GetRelativePath(propertyHolder.ImageFileInfo.FullName, sourceDirectoryLength);
|
key = Property.Models.Stateless.IPath.GetRelativePath(propertyHolder.ImageFileHolder.FullName, sourceDirectoryLength);
|
||||||
_FileKeyValuePairs.Add(new KeyValuePair<string, string>(sourceDirectory, key));
|
_FileKeyValuePairs.Add(new KeyValuePair<string, string>(sourceDirectory, key));
|
||||||
_FilePropertiesKeyValuePairs[sourceDirectory].Add(new Tuple<string, A_Property>(key, propertyCollection[i]));
|
_FilePropertiesKeyValuePairs[sourceDirectory].Add(new Tuple<string, A_Property>(key, propertyCollection[i]));
|
||||||
faceCollectionsKeyValuePairs.Add(new KeyValuePair<string, List<D_Face>>(key, faceCollections[i]));
|
faceCollectionsKeyValuePairs.Add(new KeyValuePair<string, List<D_Face>>(key, faceCollections[i]));
|
||||||
@ -564,29 +569,31 @@ public class DlibDotNet
|
|||||||
int g;
|
int g;
|
||||||
int r;
|
int r;
|
||||||
int exceptionCount;
|
int exceptionCount;
|
||||||
object @lock = new();
|
|
||||||
string sourceDirectory;
|
string sourceDirectory;
|
||||||
long ticks = DateTime.Now.Ticks;
|
long ticks = DateTime.Now.Ticks;
|
||||||
|
string eDistanceCollectionDirectory;
|
||||||
List<List<D_Face>> faceCollections = new();
|
List<List<D_Face>> faceCollections = new();
|
||||||
List<A_Property> propertyCollection = new();
|
List<A_Property> propertyCollection = new();
|
||||||
PropertyHolder[] filteredPropertyHolderCollection;
|
PropertyHolder[] filteredPropertyHolderCollection;
|
||||||
List<FileInfo?> propertyFileInfoCollection = new();
|
List<FileHolder?> propertyFileHolderCollection = new();
|
||||||
List<Dictionary<string, int[]>> resizeKeyValuePairs = new();
|
List<Dictionary<string, int[]>> resizeKeyValuePairs = new();
|
||||||
List<Tuple<string, DateTime>> sourceDirectoryChanges = new();
|
List<Tuple<string, DateTime>> sourceDirectoryChanges = new();
|
||||||
List<List<KeyValuePair<string, string>>> metadataCollection = new();
|
List<List<KeyValuePair<string, string>>> metadataCollection = new();
|
||||||
|
List<(string[], PersonBirthday, FaceRecognitionDotNet.FaceEncoding[])> collection;
|
||||||
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
|
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
|
||||||
string propertyRoot = Property.Models.Stateless.IResult.GetResultsGroupDirectory(configuration, nameof(A_Property));
|
string propertyRoot = Property.Models.Stateless.IResult.GetResultsGroupDirectory(configuration, nameof(A_Property));
|
||||||
foreach (string outputResolution in _Configuration.OutputResolutions)
|
foreach (string outputResolution in _Configuration.OutputResolutions)
|
||||||
{
|
{
|
||||||
_FileKeyValuePairs.Clear();
|
_FileKeyValuePairs.Clear();
|
||||||
_FilePropertiesKeyValuePairs.Clear();
|
_FilePropertiesKeyValuePairs.Clear();
|
||||||
|
eDistanceCollectionDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, model, predictorModel, nameof(E_Distance), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), $"[{ticks}]");
|
||||||
foreach (PropertyHolder[] propertyHolderCollection in propertyHolderCollections)
|
foreach (PropertyHolder[] propertyHolderCollection in propertyHolderCollections)
|
||||||
{
|
{
|
||||||
if (!propertyHolderCollection.Any())
|
if (!propertyHolderCollection.Any())
|
||||||
continue;
|
continue;
|
||||||
if (!_ArgZeroIsConfigurationRootDirectory && !propertyHolderCollection[0].SourceDirectory.StartsWith(argZero))
|
if (!_ArgZeroIsConfigurationRootDirectory && !propertyHolderCollection[0].SourceDirectory.StartsWith(argZero))
|
||||||
continue;
|
continue;
|
||||||
filteredPropertyHolderCollection = (from l in propertyHolderCollection where l.ImageFileInfo is not null && l.Property is not null && l.ValidImageFormatExtension.HasValue && l.ValidImageFormatExtension.Value && !_Configuration.IgnoreExtensions.Contains(l.ImageFileInfo.Extension) select l).ToArray();
|
filteredPropertyHolderCollection = (from l in propertyHolderCollection where l.ImageFileHolder is not null && l.Property is not null && l.ValidImageFormatExtension.HasValue && l.ValidImageFormatExtension.Value && !_Configuration.IgnoreExtensions.Contains(l.ImageFileHolder.Extension) select l).ToArray();
|
||||||
if (!filteredPropertyHolderCollection.Any())
|
if (!filteredPropertyHolderCollection.Any())
|
||||||
continue;
|
continue;
|
||||||
faceCollections.Clear();
|
faceCollections.Clear();
|
||||||
@ -594,7 +601,7 @@ public class DlibDotNet
|
|||||||
propertyCollection.Clear();
|
propertyCollection.Clear();
|
||||||
resizeKeyValuePairs.Clear();
|
resizeKeyValuePairs.Clear();
|
||||||
sourceDirectoryChanges.Clear();
|
sourceDirectoryChanges.Clear();
|
||||||
propertyFileInfoCollection.Clear();
|
propertyFileHolderCollection.Clear();
|
||||||
_Faces.AngleBracketCollection.Clear();
|
_Faces.AngleBracketCollection.Clear();
|
||||||
_Resize.AngleBracketCollection.Clear();
|
_Resize.AngleBracketCollection.Clear();
|
||||||
_Metadata.AngleBracketCollection.Clear();
|
_Metadata.AngleBracketCollection.Clear();
|
||||||
@ -665,7 +672,7 @@ public class DlibDotNet
|
|||||||
contentDescription: "n x 2 png file(s) for each face found",
|
contentDescription: "n x 2 png file(s) for each face found",
|
||||||
singletonDescription: string.Empty,
|
singletonDescription: string.Empty,
|
||||||
collectionDescription: string.Empty));
|
collectionDescription: string.Empty));
|
||||||
exceptionCount = FullParallelWork(@lock, ticks, propertyLogic, outputResolution, sourceDirectoryChanges, propertyFileInfoCollection, propertyCollection, metadataCollection, resizeKeyValuePairs, faceCollections, propertyHolderCollections.Count, g, sourceDirectory, r, filteredPropertyHolderCollection);
|
exceptionCount = FullParallelWork(ticks, propertyLogic, outputResolution, sourceDirectoryChanges, propertyFileHolderCollection, propertyCollection, metadataCollection, resizeKeyValuePairs, faceCollections, propertyHolderCollections.Count, g, sourceDirectory, r, filteredPropertyHolderCollection);
|
||||||
if (metadataCollection.Count != filteredPropertyHolderCollection.Length || propertyCollection.Count != filteredPropertyHolderCollection.Length || resizeKeyValuePairs.Count != filteredPropertyHolderCollection.Length || faceCollections.Count != filteredPropertyHolderCollection.Length)
|
if (metadataCollection.Count != filteredPropertyHolderCollection.Length || propertyCollection.Count != filteredPropertyHolderCollection.Length || resizeKeyValuePairs.Count != filteredPropertyHolderCollection.Length || faceCollections.Count != filteredPropertyHolderCollection.Length)
|
||||||
throw new Exception("Counts don't match!");
|
throw new Exception("Counts don't match!");
|
||||||
if (exceptionCount != 0)
|
if (exceptionCount != 0)
|
||||||
@ -708,7 +715,11 @@ public class DlibDotNet
|
|||||||
{
|
{
|
||||||
propertyLogic.SaveAllCollection();
|
propertyLogic.SaveAllCollection();
|
||||||
if (propertyLogic.NamedFaceInfoDeterministicHashCodeIndices.Any())
|
if (propertyLogic.NamedFaceInfoDeterministicHashCodeIndices.Any())
|
||||||
E_Distance.SaveGroupedFaceEncodings(configuration, model, predictorModel, argZero, ticks, peopleCollection, outputResolution, propertyHolderCollections);
|
{
|
||||||
|
collection = E_Distance.GetGroupedFaceEncodings(argZero, propertyHolderCollections);
|
||||||
|
E_Distance.SaveGroupedFaceEncodings(collection, peopleCollection, eDistanceCollectionDirectory);
|
||||||
|
E_Distance.GetClosest(argZero, propertyHolderCollections, collection, peopleCollection, eDistanceCollectionDirectory);
|
||||||
|
}
|
||||||
if (!_Configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions.Any())
|
if (!_Configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions.Any())
|
||||||
break;
|
break;
|
||||||
if (_Exceptions.Count == 0)
|
if (_Exceptions.Count == 0)
|
||||||
|
@ -43,7 +43,7 @@ internal class D2_FaceLandmarks
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SaveFaceLandmarkImages(List<D_Face> faceCollections, List<string[]> imageFiles, int pointSize, FileInfo resizedFileInfo)
|
private static void SaveFaceLandmarkImages(List<D_Face> faceCollections, List<string[]> imageFiles, int pointSize, FileHolder resizedFileHolder)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
@ -63,7 +63,7 @@ internal class D2_FaceLandmarks
|
|||||||
rotatedImageFileFullName = imageFiles[i][1];
|
rotatedImageFileFullName = imageFiles[i][1];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (Image image = Image.FromFile(resizedFileInfo.FullName))
|
using (Image image = Image.FromFile(resizedFileHolder.FullName))
|
||||||
{
|
{
|
||||||
using Graphics graphic = Graphics.FromImage(image);
|
using Graphics graphic = Graphics.FromImage(image);
|
||||||
if (face.FaceLandmarks is null || !face.FaceLandmarks.Any())
|
if (face.FaceLandmarks is null || !face.FaceLandmarks.Any())
|
||||||
@ -92,7 +92,7 @@ internal class D2_FaceLandmarks
|
|||||||
}
|
}
|
||||||
if (face.α.HasValue)
|
if (face.α.HasValue)
|
||||||
{
|
{
|
||||||
using Image image = Image.FromFile(resizedFileInfo.FullName);
|
using Image image = Image.FromFile(resizedFileHolder.FullName);
|
||||||
rotated = RotateBitmap(image, (float)face.α.Value);
|
rotated = RotateBitmap(image, (float)face.α.Value);
|
||||||
if (rotated is not null)
|
if (rotated is not null)
|
||||||
{
|
{
|
||||||
@ -109,8 +109,8 @@ internal class D2_FaceLandmarks
|
|||||||
|
|
||||||
internal void SaveFaceLandmarkImages(List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, PropertyHolder propertyHolder, List<D_Face> faceCollections)
|
internal void SaveFaceLandmarkImages(List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, PropertyHolder propertyHolder, List<D_Face> faceCollections)
|
||||||
{
|
{
|
||||||
if (propertyHolder.ResizedFileInfo is null)
|
if (propertyHolder.ResizedFileHolder is null)
|
||||||
throw new Exception($"{propertyHolder.ResizedFileInfo} is null!");
|
throw new Exception($"{propertyHolder.ResizedFileHolder} is null!");
|
||||||
FileInfo fileInfo;
|
FileInfo fileInfo;
|
||||||
bool check = false;
|
bool check = false;
|
||||||
string parentCheck;
|
string parentCheck;
|
||||||
@ -164,7 +164,7 @@ internal class D2_FaceLandmarks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (check)
|
if (check)
|
||||||
SaveFaceLandmarkImages(faceCollections, imageFiles, pointSize, propertyHolder.ResizedFileInfo);
|
SaveFaceLandmarkImages(faceCollections, imageFiles, pointSize, propertyHolder.ResizedFileHolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -219,7 +219,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SaveFaces(List<D_Face> faceCollection, FileInfo resizedFileInfo, List<string> imageFiles)
|
private static void SaveFaces(List<D_Face> faceCollection, FileHolder resizedFileHolder, List<string> imageFiles)
|
||||||
{
|
{
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
@ -227,7 +227,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
|||||||
Location location;
|
Location location;
|
||||||
Bitmap preRotated;
|
Bitmap preRotated;
|
||||||
Rectangle rectangle;
|
Rectangle rectangle;
|
||||||
using Bitmap source = new(resizedFileInfo.FullName);
|
using Bitmap source = new(resizedFileHolder.FullName);
|
||||||
for (int i = 0; i < faceCollection.Count; i++)
|
for (int i = 0; i < faceCollection.Count; i++)
|
||||||
{
|
{
|
||||||
if (!faceCollection[i].Populated || faceCollection[i]?.Location is null)
|
if (!faceCollection[i].Populated || faceCollection[i]?.Location is null)
|
||||||
@ -251,7 +251,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<D_Face> GetFaces(FileInfo resizedFileInfo, PropertyHolder propertyHolder, A_Property property, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, string facesDirectory)
|
private List<D_Face> GetFaces(FileHolder resizedFileHolder, PropertyHolder propertyHolder, A_Property property, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, string facesDirectory)
|
||||||
{
|
{
|
||||||
List<D_Face> results = new();
|
List<D_Face> results = new();
|
||||||
if (_Configuration.PaddingLoops is null)
|
if (_Configuration.PaddingLoops is null)
|
||||||
@ -262,10 +262,10 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
|||||||
throw new ArgumentNullException(nameof(_Configuration.NumberOfTimesToUpsample));
|
throw new ArgumentNullException(nameof(_Configuration.NumberOfTimesToUpsample));
|
||||||
List<Location> locations;
|
List<Location> locations;
|
||||||
FaceRecognitionDotNet.Image? unknownImage = null;
|
FaceRecognitionDotNet.Image? unknownImage = null;
|
||||||
if (resizedFileInfo.Exists)
|
if (resizedFileHolder.Exists)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{ unknownImage = FaceRecognition.LoadImageFile(resizedFileInfo.FullName); }
|
{ unknownImage = FaceRecognition.LoadImageFile(resizedFileHolder.FullName); }
|
||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
}
|
}
|
||||||
if (unknownImage is null)
|
if (unknownImage is null)
|
||||||
@ -410,7 +410,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
|||||||
_Populated = populated;
|
_Populated = populated;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal List<D_Face> GetFaces(Property.Models.Configuration configuration, string outputResolution, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, PropertyHolder propertyHolder, A_Property property, FileInfo resizedFileInfo, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation)
|
internal List<D_Face> GetFaces(Property.Models.Configuration configuration, string outputResolution, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, PropertyHolder propertyHolder, A_Property property, FileHolder resizedFileHolder, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation)
|
||||||
{
|
{
|
||||||
List<D_Face>? results;
|
List<D_Face>? results;
|
||||||
if (_Configuration.PropertiesChangedForFaces is null)
|
if (_Configuration.PropertiesChangedForFaces is null)
|
||||||
@ -419,8 +419,8 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
|||||||
D_Face face;
|
D_Face face;
|
||||||
bool checkForOutputResolutionChange = false;
|
bool checkForOutputResolutionChange = false;
|
||||||
string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata), nameof(C_Resize) };
|
string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata), nameof(C_Resize) };
|
||||||
string facesDirectory = Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), propertyHolder.ImageFileNameWithoutExtension);
|
|
||||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||||
|
string facesDirectory = Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), propertyHolder.ImageFileNameWithoutExtension);
|
||||||
FileInfo fileInfo = new(Path.Combine(AngleBracketCollection[0].Replace("<>", "[]"), $"{propertyHolder.ImageFileNameWithoutExtension}.json"));
|
FileInfo fileInfo = new(Path.Combine(AngleBracketCollection[0].Replace("<>", "[]"), $"{propertyHolder.ImageFileNameWithoutExtension}.json"));
|
||||||
if (!fileInfo.Exists)
|
if (!fileInfo.Exists)
|
||||||
{
|
{
|
||||||
@ -473,7 +473,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
|||||||
}
|
}
|
||||||
else if (results is null)
|
else if (results is null)
|
||||||
{
|
{
|
||||||
results = GetFaces(resizedFileInfo, propertyHolder, property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, facesDirectory);
|
results = GetFaces(resizedFileHolder, propertyHolder, property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, facesDirectory);
|
||||||
json = JsonSerializer.Serialize(results, _WriteIndentedJsonSerializerOptions);
|
json = JsonSerializer.Serialize(results, _WriteIndentedJsonSerializerOptions);
|
||||||
bool updateDateWhenMatches = dateTimes.Any() && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
bool updateDateWhenMatches = dateTimes.Any() && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
||||||
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
||||||
@ -487,8 +487,8 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
|||||||
{
|
{
|
||||||
if (_Configuration.OverrideForFaceImages is null)
|
if (_Configuration.OverrideForFaceImages is null)
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
if (propertyHolder.ResizedFileInfo is null)
|
if (propertyHolder.ResizedFileHolder is null)
|
||||||
throw new Exception($"{propertyHolder.ResizedFileInfo} is null!");
|
throw new Exception($"{propertyHolder.ResizedFileHolder} is null!");
|
||||||
FileInfo fileInfo;
|
FileInfo fileInfo;
|
||||||
bool check = false;
|
bool check = false;
|
||||||
string parentCheck;
|
string parentCheck;
|
||||||
@ -524,7 +524,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
|||||||
check = true;
|
check = true;
|
||||||
}
|
}
|
||||||
if (check)
|
if (check)
|
||||||
SaveFaces(faceCollection, propertyHolder.ResizedFileInfo, imageFiles);
|
SaveFaces(faceCollection, propertyHolder.ResizedFileHolder, imageFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void SaveShortcuts(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string[] juliePhares, long ticks, Dictionary<string, List<Person>> peopleCollection, PropertyLogic propertyLogic, string outputResolution, PropertyHolder[] filteredPropertyHolderCollection)
|
internal static void SaveShortcuts(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string[] juliePhares, long ticks, Dictionary<string, List<Person>> peopleCollection, PropertyLogic propertyLogic, string outputResolution, PropertyHolder[] filteredPropertyHolderCollection)
|
||||||
@ -544,7 +544,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(personKey))
|
if (string.IsNullOrEmpty(personKey))
|
||||||
continue;
|
continue;
|
||||||
if (propertyHolder.Property?.Id is null || propertyHolder.ImageFileInfo is null || propertyHolder.MinimumDateTime is null || propertyHolder.ResizedFileInfo is null)
|
if (propertyHolder.Property?.Id is null || propertyHolder.ImageFileHolder is null || propertyHolder.MinimumDateTime is null || propertyHolder.ResizedFileHolder is null)
|
||||||
continue;
|
continue;
|
||||||
if (!Directory.Exists(directory))
|
if (!Directory.Exists(directory))
|
||||||
{
|
{
|
||||||
@ -560,14 +560,14 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
|||||||
{
|
{
|
||||||
if (!Directory.Exists(copyDirectory))
|
if (!Directory.Exists(copyDirectory))
|
||||||
_ = Directory.CreateDirectory(copyDirectory);
|
_ = Directory.CreateDirectory(copyDirectory);
|
||||||
fileName = Path.Combine(copyDirectory, $"{propertyHolder.Property.Id.Value}{propertyHolder.ResizedFileInfo.Extension}");
|
fileName = Path.Combine(copyDirectory, $"{propertyHolder.Property.Id.Value}{propertyHolder.ResizedFileHolder.Extension}");
|
||||||
if (!File.Exists(fileName))
|
if (!File.Exists(fileName))
|
||||||
File.Copy(propertyHolder.ResizedFileInfo.FullName, fileName);
|
File.Copy(propertyHolder.ResizedFileHolder.FullName, fileName);
|
||||||
}
|
}
|
||||||
fileName = Path.Combine(directory, $"{propertyHolder.Property.Id.Value}.lnk");
|
fileName = Path.Combine(directory, $"{propertyHolder.Property.Id.Value}.lnk");
|
||||||
if (File.Exists(fileName))
|
if (File.Exists(fileName))
|
||||||
continue;
|
continue;
|
||||||
windowsShortcut = new() { Path = propertyHolder.ImageFileInfo.FullName };
|
windowsShortcut = new() { Path = propertyHolder.ImageFileHolder.FullName };
|
||||||
windowsShortcut.Save(fileName);
|
windowsShortcut.Save(fileName);
|
||||||
windowsShortcut.Dispose();
|
windowsShortcut.Dispose();
|
||||||
if (!File.Exists(fileName))
|
if (!File.Exists(fileName))
|
||||||
|
@ -173,8 +173,7 @@ internal class E_Distance
|
|||||||
|
|
||||||
private void LoadOrCreateThenSaveDistanceResultsForOutputResolutions(Property.Models.Configuration configuration, PropertyHolder[] filteredPropertyHolderCollection, List<List<D_Face>> faceCollections, List<string[]> directories, bool updateDateWhenMatches, DateTime? updateToWhenMatches)
|
private void LoadOrCreateThenSaveDistanceResultsForOutputResolutions(Property.Models.Configuration configuration, PropertyHolder[] filteredPropertyHolderCollection, List<List<D_Face>> faceCollections, List<string[]> directories, bool updateDateWhenMatches, DateTime? updateToWhenMatches)
|
||||||
{
|
{
|
||||||
FileInfo? fileInfo;
|
FileHolder? fileHolder;
|
||||||
string fileNameWithoutExtension;
|
|
||||||
List<int[]> locationIndicesCollection = new();
|
List<int[]> locationIndicesCollection = new();
|
||||||
List<Tuple<string, DateTime>> subFileTuples = new();
|
List<Tuple<string, DateTime>> subFileTuples = new();
|
||||||
List<FaceEncoding> faceEncodingCollection = new();
|
List<FaceEncoding> faceEncodingCollection = new();
|
||||||
@ -186,11 +185,10 @@ internal class E_Distance
|
|||||||
throw new Exception();
|
throw new Exception();
|
||||||
for (int i = 0; i < filteredPropertyHolderCollection.Length; i++)
|
for (int i = 0; i < filteredPropertyHolderCollection.Length; i++)
|
||||||
{
|
{
|
||||||
fileInfo = filteredPropertyHolderCollection[i].ImageFileInfo;
|
fileHolder = filteredPropertyHolderCollection[i].ImageFileHolder;
|
||||||
if (fileInfo is null)
|
if (fileHolder is null)
|
||||||
continue;
|
continue;
|
||||||
fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName);
|
LoadOrCreateThenSaveDistanceResultsForOutputResolutionsLoop(configuration, faceCollections, filteredPropertyHolderCollection.Length, i, faceCollections[i], locationIndicesCollection, subFileTuples, faceEncodingCollection, faceEncodingCollections[i], fileHolder.NameWithoutExtension, directories[i][0], directories[i][1], updateDateWhenMatches, updateToWhenMatches);
|
||||||
LoadOrCreateThenSaveDistanceResultsForOutputResolutionsLoop(configuration, faceCollections, filteredPropertyHolderCollection.Length, i, faceCollections[i], locationIndicesCollection, subFileTuples, faceEncodingCollection, faceEncodingCollections[i], fileNameWithoutExtension, directories[i][0], directories[i][1], updateDateWhenMatches, updateToWhenMatches);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,12 +199,11 @@ internal class E_Distance
|
|||||||
if (_Configuration.PropertiesChangedForDistance is null)
|
if (_Configuration.PropertiesChangedForDistance is null)
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
string json;
|
string json;
|
||||||
FileInfo? fileInfo;
|
|
||||||
bool check = false;
|
bool check = false;
|
||||||
string parentCheck;
|
string parentCheck;
|
||||||
|
FileHolder? fileHolder;
|
||||||
DateTime? dateTime = null;
|
DateTime? dateTime = null;
|
||||||
FileInfo[] fileInfoCollection;
|
FileInfo[] fileInfoCollection;
|
||||||
string fileNameWithoutExtension;
|
|
||||||
bool updateDateWhenMatches = false;
|
bool updateDateWhenMatches = false;
|
||||||
List<string[]> directories = new();
|
List<string[]> directories = new();
|
||||||
System.IO.DirectoryInfo directoryInfo;
|
System.IO.DirectoryInfo directoryInfo;
|
||||||
@ -227,11 +224,10 @@ internal class E_Distance
|
|||||||
collectionDescription: "n json file(s) for each face found (one to many)");
|
collectionDescription: "n json file(s) for each face found (one to many)");
|
||||||
for (int i = 0; i < filteredPropertyHolderCollection.Length; i++)
|
for (int i = 0; i < filteredPropertyHolderCollection.Length; i++)
|
||||||
{
|
{
|
||||||
fileInfo = filteredPropertyHolderCollection[i].ImageFileInfo;
|
fileHolder = filteredPropertyHolderCollection[i].ImageFileHolder;
|
||||||
if (fileInfo is null)
|
if (fileHolder is null)
|
||||||
continue;
|
continue;
|
||||||
fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName);
|
directoryInfo = new System.IO.DirectoryInfo(Path.Combine(directoryInfoCollection[0].Replace("<>", "[]"), fileHolder.NameWithoutExtension));
|
||||||
directoryInfo = new System.IO.DirectoryInfo(Path.Combine(directoryInfoCollection[0].Replace("<>", "[]"), fileNameWithoutExtension));
|
|
||||||
if (!directoryInfo.Exists)
|
if (!directoryInfo.Exists)
|
||||||
{
|
{
|
||||||
if (directoryInfo.Parent?.Parent is null)
|
if (directoryInfo.Parent?.Parent is null)
|
||||||
@ -244,7 +240,7 @@ internal class E_Distance
|
|||||||
Directory.Delete(parentCheck);
|
Directory.Delete(parentCheck);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tvsDirectoryInfo = new System.IO.DirectoryInfo(Path.Combine(directoryInfoCollection[0].Replace("<>", "()"), fileNameWithoutExtension));
|
tvsDirectoryInfo = new System.IO.DirectoryInfo(Path.Combine(directoryInfoCollection[0].Replace("<>", "()"), fileHolder.NameWithoutExtension));
|
||||||
directories.Add(new string[] { directoryInfo.FullName, tvsDirectoryInfo.FullName });
|
directories.Add(new string[] { directoryInfo.FullName, tvsDirectoryInfo.FullName });
|
||||||
if (_Configuration.CheckJsonForDistanceResults.Value && directoryInfo.Exists)
|
if (_Configuration.CheckJsonForDistanceResults.Value && directoryInfo.Exists)
|
||||||
{
|
{
|
||||||
@ -418,80 +414,168 @@ internal class E_Distance
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void SaveGroupedFaceEncodings(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string argZero, long ticks, Dictionary<string, List<Shared.Models.Person>> peopleCollection, string outputResolution, List<PropertyHolder[]> propertyHolderCollections)
|
internal static List<(string[], Shared.Models.PersonBirthday, FaceEncoding[])> GetGroupedFaceEncodings(string argZero, List<PropertyHolder[]> propertyHolderCollections)
|
||||||
{
|
{
|
||||||
|
List<(string[], Shared.Models.PersonBirthday, FaceEncoding[])> results = new();
|
||||||
double lcl;
|
double lcl;
|
||||||
double ucl;
|
double ucl;
|
||||||
string json;
|
double sum;
|
||||||
double average;
|
double average;
|
||||||
int lowestIndex;
|
int lowestIndex;
|
||||||
string checkFile;
|
double lowestSum;
|
||||||
string personKey;
|
const int zero = 0;
|
||||||
double lowestAverage;
|
|
||||||
double standardDeviation;
|
double standardDeviation;
|
||||||
FaceEncoding faceEncoding;
|
FaceEncoding faceEncoding;
|
||||||
List<double> faceDistances;
|
List<double> faceDistances;
|
||||||
List<double[]> rawEncodings;
|
|
||||||
Shared.Models.Person person;
|
|
||||||
List<FaceEncoding> faceEncodings;
|
List<FaceEncoding> faceEncodings;
|
||||||
List<string> checkDirectories = new();
|
Dictionary<string, List<(string[], Shared.Models.PersonBirthday, Shared.Models.Properties.IFace)>> keyValuePairs = PropertyHolder.GetKeyValuePairs(argZero, propertyHolderCollections);
|
||||||
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
|
foreach (KeyValuePair<string, List<(string[] Directories, Shared.Models.PersonBirthday PersonBirthday, Shared.Models.Properties.IFace _)>> keyValuePair in keyValuePairs)
|
||||||
string eDistanceCollectionDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, model, predictorModel, nameof(E_Distance), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), $"[{ticks}]");
|
|
||||||
List<(string, Shared.Models.PersonBirthday, Shared.Models.Properties.IFace)[]> collection = PropertyHolder.GetCollection(argZero, propertyHolderCollections, eDistanceCollectionDirectory);
|
|
||||||
foreach ((string, Shared.Models.PersonBirthday, Shared.Models.Properties.IFace)[] group in collection)
|
|
||||||
{
|
{
|
||||||
lowestIndex = 0;
|
lowestIndex = 0;
|
||||||
rawEncodings = new();
|
|
||||||
faceEncodings = new();
|
faceEncodings = new();
|
||||||
checkDirectories.Clear();
|
lowestSum = double.MaxValue;
|
||||||
checkFile = string.Empty;
|
foreach ((string[] directories, Shared.Models.PersonBirthday personBirthday, Shared.Models.Properties.IFace face) in keyValuePair.Value)
|
||||||
lowestAverage = double.MaxValue;
|
|
||||||
foreach ((string directory, Shared.Models.PersonBirthday personBirthday, Shared.Models.Properties.IFace @interface) in group)
|
|
||||||
{
|
{
|
||||||
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
if (!face.Populated)
|
||||||
if (string.IsNullOrEmpty(personKey) || !peopleCollection.ContainsKey(personKey))
|
|
||||||
continue;
|
continue;
|
||||||
if (@interface is not D_Face face || !face.Populated)
|
|
||||||
continue;
|
|
||||||
person = peopleCollection[personKey][0];
|
|
||||||
faceEncoding = FaceRecognition.LoadFaceEncoding(face.FaceEncoding.RawEncoding);
|
faceEncoding = FaceRecognition.LoadFaceEncoding(face.FaceEncoding.RawEncoding);
|
||||||
checkFile = string.Concat(directory, " - ", Regex.Replace(Shared.Models.Stateless.Methods.IPersonName.GetFullName(person.Name), pattern, string.Empty), ".json");
|
|
||||||
checkDirectories.Add(directory);
|
|
||||||
faceEncodings.Add(faceEncoding);
|
faceEncodings.Add(faceEncoding);
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(checkFile) || !checkDirectories.Any() || faceEncodings.Count < 2)
|
if (keyValuePair.Value.Count != faceEncodings.Count)
|
||||||
|
continue;
|
||||||
|
if (faceEncodings.Count < 2)
|
||||||
continue;
|
continue;
|
||||||
foreach (string checkDirectory in checkDirectories.Distinct())
|
|
||||||
{
|
|
||||||
if (!Directory.Exists(checkDirectory))
|
|
||||||
_ = Directory.CreateDirectory(checkDirectory);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < faceEncodings.Count; i++)
|
for (int i = 0; i < faceEncodings.Count; i++)
|
||||||
{
|
{
|
||||||
faceDistances = FaceRecognition.FaceDistances(faceEncodings, faceEncodings[i]);
|
faceDistances = FaceRecognition.FaceDistances(faceEncodings, faceEncodings[i]);
|
||||||
average = faceDistances.Average();
|
sum = faceDistances.Sum();
|
||||||
if (average > lowestAverage)
|
if (sum > lowestSum)
|
||||||
continue;
|
continue;
|
||||||
lowestIndex = i;
|
lowestIndex = i;
|
||||||
lowestAverage = average;
|
lowestSum = sum;
|
||||||
}
|
}
|
||||||
faceDistances = FaceRecognition.FaceDistances(faceEncodings, faceEncodings[lowestIndex]);
|
faceDistances = FaceRecognition.FaceDistances(faceEncodings, faceEncodings[lowestIndex]);
|
||||||
average = faceDistances.Average();
|
sum = faceDistances.Sum();
|
||||||
if (average != lowestAverage)
|
if (sum != lowestSum)
|
||||||
continue;
|
continue;
|
||||||
|
average = faceDistances.Average();
|
||||||
standardDeviation = GetStandardDeviation(faceDistances, average);
|
standardDeviation = GetStandardDeviation(faceDistances, average);
|
||||||
lcl = average - (standardDeviation * 3);
|
lcl = average - (standardDeviation * 3);
|
||||||
ucl = average + (standardDeviation * 3);
|
ucl = average + (standardDeviation * 3);
|
||||||
for (int i = 0; i < faceEncodings.Count; i++)
|
for (int i = faceEncodings.Count; i > -1; i--)
|
||||||
{
|
{
|
||||||
if (faceDistances[i] < lcl || faceDistances[i] > ucl)
|
if (faceDistances[i] < lcl || faceDistances[i] > ucl)
|
||||||
continue;
|
faceEncodings.RemoveAt(i);
|
||||||
rawEncodings.Add(faceEncodings[i].GetRawEncoding());
|
|
||||||
}
|
}
|
||||||
// outOfControl = faceEncodings.Count - rawEncodings.Count;
|
results.Add(new(keyValuePair.Value[zero].Directories, keyValuePair.Value[zero].PersonBirthday, faceEncodings.ToArray()));
|
||||||
|
}
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void SaveGroupedFaceEncodings(List<(string[], Shared.Models.PersonBirthday, FaceEncoding[])> collection, Dictionary<string, List<Shared.Models.Person>> peopleCollection, string eDistanceCollectionDirectory)
|
||||||
|
{
|
||||||
|
string json;
|
||||||
|
string checkFile;
|
||||||
|
string personKey;
|
||||||
|
string directory;
|
||||||
|
List<double[]> rawEncodings;
|
||||||
|
Shared.Models.Person person;
|
||||||
|
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
|
||||||
|
foreach ((string[] directories, Shared.Models.PersonBirthday personBirthday, FaceEncoding[] faceEncodings) in collection)
|
||||||
|
{
|
||||||
|
directories[0] = eDistanceCollectionDirectory;
|
||||||
|
rawEncodings = new();
|
||||||
|
checkFile = string.Empty;
|
||||||
|
directory = Path.Combine(directories);
|
||||||
|
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
||||||
|
person = peopleCollection[personKey][0];
|
||||||
|
checkFile = string.Concat(directory, " - ", Regex.Replace(Shared.Models.Stateless.Methods.IPersonName.GetFullName(person.Name), pattern, string.Empty), ".json");
|
||||||
|
if (string.IsNullOrEmpty(checkFile))
|
||||||
|
continue;
|
||||||
|
if (!Directory.Exists(directory))
|
||||||
|
_ = Directory.CreateDirectory(directory);
|
||||||
|
for (int i = 0; i < faceEncodings.Length; i++)
|
||||||
|
rawEncodings.Add(faceEncodings[i].GetRawEncoding());
|
||||||
json = JsonSerializer.Serialize(rawEncodings, new JsonSerializerOptions { WriteIndented = true });
|
json = JsonSerializer.Serialize(rawEncodings, new JsonSerializerOptions { WriteIndented = true });
|
||||||
_ = Property.Models.Stateless.IPath.WriteAllText(checkFile, json, updateDateWhenMatches: true, compareBeforeWrite: true);
|
_ = Property.Models.Stateless.IPath.WriteAllText(checkFile, json, updateDateWhenMatches: true, compareBeforeWrite: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void GetKeyValuePairs(string argZero, List<PropertyHolder[]> propertyHolderCollections, List<(string[], Shared.Models.PersonBirthday, FaceEncoding[])> collection)
|
||||||
|
{
|
||||||
|
double average;
|
||||||
|
string personKey;
|
||||||
|
bool? isWrongYear;
|
||||||
|
TimeSpan? timeSpan;
|
||||||
|
double lowestAverage;
|
||||||
|
string[] directories;
|
||||||
|
string isWrongYearFlag;
|
||||||
|
FaceEncoding faceEncoding;
|
||||||
|
List<double> faceDistances;
|
||||||
|
const string facePopulatedKey = "MatchImages";
|
||||||
|
Shared.Models.PersonBirthday? lowestPersonBirthday;
|
||||||
|
foreach (PropertyHolder[] propertyHolderCollection in propertyHolderCollections)
|
||||||
|
{
|
||||||
|
lowestPersonBirthday = null;
|
||||||
|
lowestAverage = double.MaxValue;
|
||||||
|
if (!propertyHolderCollection.Any())
|
||||||
|
continue;
|
||||||
|
if (!propertyHolderCollection[0].SourceDirectory.StartsWith(argZero))
|
||||||
|
continue;
|
||||||
|
foreach (PropertyHolder propertyHolder in propertyHolderCollection)
|
||||||
|
{
|
||||||
|
if (propertyHolder.ImageFileHolder is null || propertyHolder.Property is null || propertyHolder.Named.Any())
|
||||||
|
continue;
|
||||||
|
if (propertyHolder.MinimumDateTime is null)
|
||||||
|
continue;
|
||||||
|
(isWrongYear, _) = propertyHolder.IsWrongYear();
|
||||||
|
foreach (Shared.Models.Properties.IFace face in propertyHolder.Faces)
|
||||||
|
{
|
||||||
|
if (!face.Populated)
|
||||||
|
continue;
|
||||||
|
faceEncoding = FaceRecognition.LoadFaceEncoding(face.FaceEncoding.RawEncoding);
|
||||||
|
foreach ((string[] _, Shared.Models.PersonBirthday personBirthday, FaceEncoding[] faceEncodings) in collection)
|
||||||
|
{
|
||||||
|
faceDistances = FaceRecognition.FaceDistances(faceEncodings, faceEncoding);
|
||||||
|
average = faceDistances.Average();
|
||||||
|
if (average < lowestAverage)
|
||||||
|
continue;
|
||||||
|
lowestPersonBirthday = personBirthday;
|
||||||
|
}
|
||||||
|
if (lowestPersonBirthday is null)
|
||||||
|
continue;
|
||||||
|
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(lowestPersonBirthday);
|
||||||
|
timeSpan = Shared.Models.Stateless.Methods.IPersonBirthday.GetTimeSpan(propertyHolder.MinimumDateTime.Value, isWrongYear, lowestPersonBirthday);
|
||||||
|
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 = PropertyHolder.GetWrongYearFlag(isWrongYear);
|
||||||
|
directories = new string[] { string.Empty, facePopulatedKey, personKey, $"{isWrongYearFlag}{propertyHolder.MinimumDateTime.Value:yyyy}" };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void GetClosest(string argZero, List<PropertyHolder[]> propertyHolderCollections, List<(string[], Shared.Models.PersonBirthday, FaceEncoding[])> collection, Dictionary<string, List<Shared.Models.Person>> peopleCollection, string eDistanceCollectionDirectory)
|
||||||
|
{
|
||||||
|
GetKeyValuePairs(argZero, propertyHolderCollections, collection);
|
||||||
|
if (peopleCollection is null)
|
||||||
|
{ }
|
||||||
|
if (string.IsNullOrEmpty(eDistanceCollectionDirectory))
|
||||||
|
{ }
|
||||||
|
// foreach (KeyValuePair<string, List<(string[] Directories, Shared.Models.PersonBirthday PersonBirthday, Shared.Models.Properties.IFace _)>> keyValuePair in keyValuePairs)
|
||||||
|
// {
|
||||||
|
// foreach ((string[] directories, Shared.Models.PersonBirthday personBirthday, Shared.Models.Properties.IFace face) in keyValuePair.Value)
|
||||||
|
// {
|
||||||
|
// if (face.Populated)
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -81,8 +81,8 @@ public class B_Metadata
|
|||||||
public (int, List<KeyValuePair<string, string>>) GetMetadataCollection(List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Property.Models.PropertyHolder propertyHolder)
|
public (int, List<KeyValuePair<string, string>>) GetMetadataCollection(List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Property.Models.PropertyHolder propertyHolder)
|
||||||
{
|
{
|
||||||
List<KeyValuePair<string, string>> results = new();
|
List<KeyValuePair<string, string>> results = new();
|
||||||
if (propertyHolder.ImageFileInfo is null)
|
if (propertyHolder.ImageFileHolder is null)
|
||||||
throw new Exception($"{propertyHolder.ImageFileInfo} is null!");
|
throw new Exception($"{propertyHolder.ImageFileHolder} is null!");
|
||||||
Dictionary<string, List<KeyValuePair<string, string>>>? dictionary;
|
Dictionary<string, List<KeyValuePair<string, string>>>? dictionary;
|
||||||
string json = string.Empty;
|
string json = string.Empty;
|
||||||
string[] changesFrom = Array.Empty<string>();
|
string[] changesFrom = Array.Empty<string>();
|
||||||
@ -135,7 +135,7 @@ public class B_Metadata
|
|||||||
}
|
}
|
||||||
if (dictionary is null || !dictionary.Any())
|
if (dictionary is null || !dictionary.Any())
|
||||||
{
|
{
|
||||||
dictionary = GetMetadataCollection(propertyHolder.ImageFileInfo.FullName);
|
dictionary = GetMetadataCollection(propertyHolder.ImageFileHolder.FullName);
|
||||||
json = JsonSerializer.Serialize(dictionary, _WriteIndentedJsonSerializerOptions);
|
json = JsonSerializer.Serialize(dictionary, _WriteIndentedJsonSerializerOptions);
|
||||||
bool updateDateWhenMatches = dateTimes.Any() && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
bool updateDateWhenMatches = dateTimes.Any() && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
||||||
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
||||||
|
@ -148,7 +148,7 @@ public class NotCopyCopy
|
|||||||
Dictionary<string, A_Property> keyValuePairs = new();
|
Dictionary<string, A_Property> keyValuePairs = new();
|
||||||
foreach (Property.Models.DirectoryInfo group in compareSourceGroupCollection)
|
foreach (Property.Models.DirectoryInfo group in compareSourceGroupCollection)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < group.SourceDirectoryFileInfoCollection.Length; i++)
|
for (int i = 0; i < group.SourceDirectoryFileHolderCollection.Length; i++)
|
||||||
{
|
{
|
||||||
property = group.PropertyCollection[i];
|
property = group.PropertyCollection[i];
|
||||||
if (property is null)
|
if (property is null)
|
||||||
@ -159,7 +159,7 @@ public class NotCopyCopy
|
|||||||
}
|
}
|
||||||
foreach (Property.Models.DirectoryInfo group in selectedSourceGroupCollection)
|
foreach (Property.Models.DirectoryInfo group in selectedSourceGroupCollection)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < group.SourceDirectoryFileInfoCollection.Length; i++)
|
for (int i = 0; i < group.SourceDirectoryFileHolderCollection.Length; i++)
|
||||||
{
|
{
|
||||||
destinationCollection = new();
|
destinationCollection = new();
|
||||||
property = group.PropertyCollection[i];
|
property = group.PropertyCollection[i];
|
||||||
|
@ -3,25 +3,25 @@ namespace View_by_Distance.Property.Models;
|
|||||||
public class DirectoryInfo
|
public class DirectoryInfo
|
||||||
{
|
{
|
||||||
|
|
||||||
protected readonly FileInfo[] _SourceDirectoryFileInfoCollection;
|
protected readonly FileHolder[] _SourceDirectoryFileHolderCollection;
|
||||||
protected readonly string[] _FilteredSourceDirectoryFiles;
|
protected readonly string[] _FilteredSourceDirectoryFiles;
|
||||||
protected readonly int _G;
|
protected readonly int _G;
|
||||||
protected readonly bool[] _Moved;
|
protected readonly bool[] _Moved;
|
||||||
protected readonly bool?[] _Changed;
|
protected readonly bool?[] _Changed;
|
||||||
protected readonly A_Property?[] _PropertyCollection;
|
protected readonly A_Property?[] _PropertyCollection;
|
||||||
protected readonly FileInfo?[] _PropertyFileInfoCollection;
|
protected readonly FileInfo?[] _PropertyFileHolderCollection;
|
||||||
protected readonly int _R;
|
protected readonly int _R;
|
||||||
protected readonly string _SourceDirectory;
|
protected readonly string _SourceDirectory;
|
||||||
protected readonly bool[] _ValidImageFormatExtensionCollection;
|
protected readonly bool[] _ValidImageFormatExtensionCollection;
|
||||||
protected readonly bool[] _WrongYear;
|
protected readonly bool[] _WrongYear;
|
||||||
public FileInfo[] SourceDirectoryFileInfoCollection => _SourceDirectoryFileInfoCollection;
|
public FileHolder[] SourceDirectoryFileHolderCollection => _SourceDirectoryFileHolderCollection;
|
||||||
[Obsolete($"Use {nameof(SourceDirectoryFileInfoCollection)}")]
|
[Obsolete($"Use {nameof(SourceDirectoryFileHolderCollection)}")]
|
||||||
public string[] FilteredSourceDirectoryFiles => _FilteredSourceDirectoryFiles;
|
public string[] FilteredSourceDirectoryFiles => _FilteredSourceDirectoryFiles;
|
||||||
public int G => _G;
|
public int G => _G;
|
||||||
public bool[] Moved => _Moved;
|
public bool[] Moved => _Moved;
|
||||||
public bool?[] Changed => _Changed;
|
public bool?[] Changed => _Changed;
|
||||||
public A_Property?[] PropertyCollection => _PropertyCollection;
|
public A_Property?[] PropertyCollection => _PropertyCollection;
|
||||||
public FileInfo?[] PropertyFileInfoCollection => _PropertyFileInfoCollection;
|
public FileInfo?[] PropertyFileHolderCollection => _PropertyFileHolderCollection;
|
||||||
public int R => _R;
|
public int R => _R;
|
||||||
public string SourceDirectory => _SourceDirectory;
|
public string SourceDirectory => _SourceDirectory;
|
||||||
public bool[] ValidImageFormatExtensionCollection => _ValidImageFormatExtensionCollection;
|
public bool[] ValidImageFormatExtensionCollection => _ValidImageFormatExtensionCollection;
|
||||||
@ -39,8 +39,8 @@ public class DirectoryInfo
|
|||||||
_FilteredSourceDirectoryFiles = filteredSourceDirectoryFiles;
|
_FilteredSourceDirectoryFiles = filteredSourceDirectoryFiles;
|
||||||
_PropertyCollection = Enumerable.Repeat<A_Property?>(null, length).ToArray();
|
_PropertyCollection = Enumerable.Repeat<A_Property?>(null, length).ToArray();
|
||||||
_ValidImageFormatExtensionCollection = Enumerable.Repeat(false, length).ToArray();
|
_ValidImageFormatExtensionCollection = Enumerable.Repeat(false, length).ToArray();
|
||||||
_PropertyFileInfoCollection = Enumerable.Repeat<FileInfo?>(null, length).ToArray();
|
_PropertyFileHolderCollection = Enumerable.Repeat<FileInfo?>(null, length).ToArray();
|
||||||
_SourceDirectoryFileInfoCollection = (from l in filteredSourceDirectoryFiles select new FileInfo(l)).ToArray();
|
_SourceDirectoryFileHolderCollection = (from l in filteredSourceDirectoryFiles select new FileHolder(l)).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
70
Property/Models/FileHolder.cs
Normal file
70
Property/Models/FileHolder.cs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
namespace View_by_Distance.Property.Models;
|
||||||
|
|
||||||
|
public class FileHolder
|
||||||
|
{
|
||||||
|
protected readonly DateTime _CreationTime;
|
||||||
|
protected readonly string? _DirectoryName;
|
||||||
|
protected readonly bool _Exists;
|
||||||
|
protected readonly string _Extension;
|
||||||
|
protected readonly string _FullName;
|
||||||
|
protected readonly DateTime _LastWriteTime;
|
||||||
|
protected readonly long? _Length;
|
||||||
|
protected readonly string _Name;
|
||||||
|
protected readonly string _NameWithoutExtension;
|
||||||
|
public DateTime CreationTime => _CreationTime;
|
||||||
|
public string? DirectoryName => _DirectoryName;
|
||||||
|
public bool Exists => _Exists;
|
||||||
|
public string Extension => _Extension;
|
||||||
|
public string FullName => _FullName;
|
||||||
|
public DateTime LastWriteTime => _LastWriteTime;
|
||||||
|
public long? Length => _Length;
|
||||||
|
public string Name => _Name;
|
||||||
|
public string NameWithoutExtension => _NameWithoutExtension;
|
||||||
|
|
||||||
|
public FileHolder(DateTime creationTime, string? directoryName, bool exists, string extension, string fullName, DateTime lastWriteTime, long? length, string name, string nameWithoutExtension)
|
||||||
|
{
|
||||||
|
_CreationTime = creationTime;
|
||||||
|
_DirectoryName = directoryName;
|
||||||
|
_Exists = exists;
|
||||||
|
_Extension = extension;
|
||||||
|
_FullName = fullName;
|
||||||
|
_LastWriteTime = lastWriteTime;
|
||||||
|
_Length = length;
|
||||||
|
_Name = name;
|
||||||
|
_NameWithoutExtension = nameWithoutExtension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileHolder(string fileName)
|
||||||
|
{
|
||||||
|
FileInfo fileInfo = new(fileName);
|
||||||
|
_CreationTime = fileInfo.CreationTime;
|
||||||
|
_CreationTime = fileInfo.CreationTime;
|
||||||
|
_DirectoryName = fileInfo.DirectoryName;
|
||||||
|
_Exists = fileInfo.Exists;
|
||||||
|
_Extension = fileInfo.Extension;
|
||||||
|
_FullName = fileInfo.FullName;
|
||||||
|
_LastWriteTime = fileInfo.LastWriteTime;
|
||||||
|
if (fileInfo.Exists)
|
||||||
|
_Length = fileInfo.Length;
|
||||||
|
_Name = fileInfo.Name;
|
||||||
|
_NameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileHolder(FileInfo fileInfo)
|
||||||
|
{
|
||||||
|
_CreationTime = fileInfo.CreationTime;
|
||||||
|
_CreationTime = fileInfo.CreationTime;
|
||||||
|
_DirectoryName = fileInfo.DirectoryName;
|
||||||
|
_Exists = fileInfo.Exists;
|
||||||
|
_Extension = fileInfo.Extension;
|
||||||
|
_FullName = fileInfo.FullName;
|
||||||
|
_LastWriteTime = fileInfo.LastWriteTime;
|
||||||
|
if (fileInfo.Exists)
|
||||||
|
_Length = fileInfo.Length;
|
||||||
|
_Name = fileInfo.Name;
|
||||||
|
_NameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FileHolder Refresh(FileHolder fileHolder) => new(fileHolder.FullName);
|
||||||
|
|
||||||
|
}
|
@ -10,7 +10,7 @@ public class PropertyHolder
|
|||||||
protected readonly bool? _Abandoned;
|
protected readonly bool? _Abandoned;
|
||||||
protected readonly bool? _Changed;
|
protected readonly bool? _Changed;
|
||||||
protected List<IFace> _Faces;
|
protected List<IFace> _Faces;
|
||||||
protected readonly FileInfo? _ImageFileInfo;
|
protected readonly FileHolder? _ImageFileHolder;
|
||||||
protected readonly string _ImageFileNameWithoutExtension;
|
protected readonly string _ImageFileNameWithoutExtension;
|
||||||
protected readonly int _G;
|
protected readonly int _G;
|
||||||
protected DateTime? _MinimumDateTime;
|
protected DateTime? _MinimumDateTime;
|
||||||
@ -20,14 +20,14 @@ public class PropertyHolder
|
|||||||
protected A_Property? _Property;
|
protected A_Property? _Property;
|
||||||
protected readonly int _R;
|
protected readonly int _R;
|
||||||
protected readonly string _RelativePath;
|
protected readonly string _RelativePath;
|
||||||
protected FileInfo? _ResizedFileInfo;
|
protected FileHolder? _ResizedFileHolder;
|
||||||
protected readonly string _SourceDirectory;
|
protected readonly string _SourceDirectory;
|
||||||
protected readonly string _SourceDirectoryFile;
|
protected readonly string _SourceDirectoryFile;
|
||||||
protected bool? _ValidImageFormatExtension;
|
protected bool? _ValidImageFormatExtension;
|
||||||
public bool? Abandoned => _Abandoned;
|
public bool? Abandoned => _Abandoned;
|
||||||
public bool? Changed => _Changed;
|
public bool? Changed => _Changed;
|
||||||
public List<IFace> Faces => _Faces;
|
public List<IFace> Faces => _Faces;
|
||||||
public FileInfo? ImageFileInfo => _ImageFileInfo;
|
public FileHolder? ImageFileHolder => _ImageFileHolder;
|
||||||
public string ImageFileNameWithoutExtension => _ImageFileNameWithoutExtension;
|
public string ImageFileNameWithoutExtension => _ImageFileNameWithoutExtension;
|
||||||
public int G => _G;
|
public int G => _G;
|
||||||
public DateTime? MinimumDateTime => _MinimumDateTime;
|
public DateTime? MinimumDateTime => _MinimumDateTime;
|
||||||
@ -37,7 +37,7 @@ public class PropertyHolder
|
|||||||
public A_Property? Property => _Property;
|
public A_Property? Property => _Property;
|
||||||
public int R => _R;
|
public int R => _R;
|
||||||
public string RelativePath => _RelativePath;
|
public string RelativePath => _RelativePath;
|
||||||
public FileInfo? ResizedFileInfo => _ResizedFileInfo;
|
public FileHolder? ResizedFileHolder => _ResizedFileHolder;
|
||||||
public string SourceDirectory => _SourceDirectory;
|
public string SourceDirectory => _SourceDirectory;
|
||||||
public string SourceDirectoryFile => _SourceDirectoryFile;
|
public string SourceDirectoryFile => _SourceDirectoryFile;
|
||||||
public bool? ValidImageFormatExtension => _ValidImageFormatExtension;
|
public bool? ValidImageFormatExtension => _ValidImageFormatExtension;
|
||||||
@ -55,7 +55,7 @@ public class PropertyHolder
|
|||||||
}
|
}
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public PropertyHolder(int g, string sourceDirectory, string sourceDirectoryFile, string relativePath, int r, FileInfo? imageFileInfo, A_Property? property, bool? abandoned, bool? changed, bool? moved, bool? validImageFormatExtension)
|
public PropertyHolder(int g, string sourceDirectory, string sourceDirectoryFile, string relativePath, int r, FileHolder? imageFileInfo, A_Property? property, bool? abandoned, bool? changed, bool? moved, bool? validImageFormatExtension)
|
||||||
{
|
{
|
||||||
_G = g;
|
_G = g;
|
||||||
_R = r;
|
_R = r;
|
||||||
@ -67,7 +67,7 @@ public class PropertyHolder
|
|||||||
_Abandoned = abandoned;
|
_Abandoned = abandoned;
|
||||||
_NoJson = abandoned is null;
|
_NoJson = abandoned is null;
|
||||||
_RelativePath = relativePath;
|
_RelativePath = relativePath;
|
||||||
_ImageFileInfo = imageFileInfo;
|
_ImageFileHolder = imageFileInfo;
|
||||||
_SourceDirectory = sourceDirectory;
|
_SourceDirectory = sourceDirectory;
|
||||||
_SourceDirectoryFile = sourceDirectoryFile;
|
_SourceDirectoryFile = sourceDirectoryFile;
|
||||||
_ValidImageFormatExtension = validImageFormatExtension;
|
_ValidImageFormatExtension = validImageFormatExtension;
|
||||||
@ -88,7 +88,7 @@ public class PropertyHolder
|
|||||||
|
|
||||||
public static string GetWrongYearFlag(bool? isWrongYear) => isWrongYear is null ? "#" : isWrongYear.Value ? "~" : "=";
|
public static string GetWrongYearFlag(bool? isWrongYear) => isWrongYear is null ? "#" : isWrongYear.Value ? "~" : "=";
|
||||||
|
|
||||||
public void SetResizedFileInfo(FileInfo fileInfo) => _ResizedFileInfo = fileInfo;
|
public void SetResizedFileHolder(FileHolder fileHolder) => _ResizedFileHolder = fileHolder;
|
||||||
|
|
||||||
public bool Any() => (_Abandoned.HasValue && _Abandoned.Value) || (_Changed.HasValue && _Changed.Value) || (_Moved.HasValue && _Moved.Value) || (_NoJson.HasValue && _NoJson.Value);
|
public bool Any() => (_Abandoned.HasValue && _Abandoned.Value) || (_Changed.HasValue && _Changed.Value) || (_Moved.HasValue && _Moved.Value) || (_NoJson.HasValue && _NoJson.Value);
|
||||||
|
|
||||||
@ -98,6 +98,15 @@ public class PropertyHolder
|
|||||||
_MinimumDateTime = Stateless.A_Property.GetMinimumDateTime(property);
|
_MinimumDateTime = Stateless.A_Property.GetMinimumDateTime(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public (bool?, string[]) IsWrongYear()
|
||||||
|
{
|
||||||
|
(bool?, string[]) result;
|
||||||
|
if (_Property is null || _ImageFileHolder is null)
|
||||||
|
throw new ArgumentNullException();
|
||||||
|
result = _Property.IsWrongYear(_ImageFileHolder.FullName, _MinimumDateTime);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public static void AddToNamed(PropertyLogic propertyLogic, PropertyHolder[] filteredPropertyHolderCollection)
|
public static void AddToNamed(PropertyLogic propertyLogic, PropertyHolder[] filteredPropertyHolderCollection)
|
||||||
{
|
{
|
||||||
bool? isWrongYear;
|
bool? isWrongYear;
|
||||||
@ -110,15 +119,15 @@ public class PropertyHolder
|
|||||||
for (int i = 0; i < filteredPropertyHolderCollection.Length; i++)
|
for (int i = 0; i < filteredPropertyHolderCollection.Length; i++)
|
||||||
{
|
{
|
||||||
propertyHolder = filteredPropertyHolderCollection[i];
|
propertyHolder = filteredPropertyHolderCollection[i];
|
||||||
if (propertyHolder.ImageFileInfo is null)
|
if (propertyHolder.ImageFileHolder is null)
|
||||||
continue;
|
continue;
|
||||||
if (propertyHolder.Property?.Id is null || propertyHolder.MinimumDateTime is null || propertyHolder.ResizedFileInfo is null)
|
if (propertyHolder.Property?.Id is null || propertyHolder.MinimumDateTime is null || propertyHolder.ResizedFileHolder is null)
|
||||||
continue;
|
continue;
|
||||||
if (!propertyLogic.NamedFaceInfoDeterministicHashCodeIndices.ContainsKey(propertyHolder.Property.Id.Value))
|
if (!propertyLogic.NamedFaceInfoDeterministicHashCodeIndices.ContainsKey(propertyHolder.Property.Id.Value))
|
||||||
continue;
|
continue;
|
||||||
minimumDateTime = Stateless.A_Property.GetMinimumDateTime(propertyHolder.Property);
|
minimumDateTime = Stateless.A_Property.GetMinimumDateTime(propertyHolder.Property);
|
||||||
personKeys = propertyLogic.NamedFaceInfoDeterministicHashCodeIndices[propertyHolder.Property.Id.Value];
|
personKeys = propertyLogic.NamedFaceInfoDeterministicHashCodeIndices[propertyHolder.Property.Id.Value];
|
||||||
(isWrongYear, _) = propertyHolder.Property.IsWrongYear(propertyHolder.ImageFileInfo.FullName, minimumDateTime);
|
(isWrongYear, _) = propertyHolder.Property.IsWrongYear(propertyHolder.ImageFileHolder.FullName, minimumDateTime);
|
||||||
for (int j = 0; j < personKeys.Length; j++)
|
for (int j = 0; j < personKeys.Length; j++)
|
||||||
{
|
{
|
||||||
segments = Shared.Models.Stateless.Methods.IPersonBirthday.GetSegments(personKeys[j]);
|
segments = Shared.Models.Stateless.Methods.IPersonBirthday.GetSegments(personKeys[j]);
|
||||||
@ -162,12 +171,12 @@ public class PropertyHolder
|
|||||||
copyFileName = string.Empty;
|
copyFileName = string.Empty;
|
||||||
copyDirectory = string.Empty;
|
copyDirectory = string.Empty;
|
||||||
propertyHolder = filteredPropertyHolderCollection[i];
|
propertyHolder = filteredPropertyHolderCollection[i];
|
||||||
if (propertyHolder.ImageFileInfo is null)
|
if (propertyHolder.ImageFileHolder is null)
|
||||||
continue;
|
continue;
|
||||||
relativePath = Path.GetDirectoryName($"C:{propertyHolder.RelativePath}");
|
relativePath = Path.GetDirectoryName($"C:{propertyHolder.RelativePath}");
|
||||||
if (string.IsNullOrEmpty(relativePath) || relativePath.Length < 3)
|
if (string.IsNullOrEmpty(relativePath) || relativePath.Length < 3)
|
||||||
continue;
|
continue;
|
||||||
if (propertyHolder.Property?.Id is null || propertyHolder.MinimumDateTime is null || propertyHolder.ResizedFileInfo is null)
|
if (propertyHolder.Property?.Id is null || propertyHolder.MinimumDateTime is null || propertyHolder.ResizedFileHolder is null)
|
||||||
continue;
|
continue;
|
||||||
collection = new();
|
collection = new();
|
||||||
if (!propertyLogic.NamedFaceInfoDeterministicHashCodeIndices.ContainsKey(propertyHolder.Property.Id.Value))
|
if (!propertyLogic.NamedFaceInfoDeterministicHashCodeIndices.ContainsKey(propertyHolder.Property.Id.Value))
|
||||||
@ -179,7 +188,7 @@ public class PropertyHolder
|
|||||||
{
|
{
|
||||||
faceCollection = propertyHolder.Faces;
|
faceCollection = propertyHolder.Faces;
|
||||||
keys = propertyLogic.NamedFaceInfoDeterministicHashCodeIndices[propertyHolder.Property.Id.Value];
|
keys = propertyLogic.NamedFaceInfoDeterministicHashCodeIndices[propertyHolder.Property.Id.Value];
|
||||||
(isWrongYear, _) = propertyHolder.Property.IsWrongYear(propertyHolder.ImageFileInfo.FullName, propertyHolder.MinimumDateTime.Value);
|
(isWrongYear, _) = propertyHolder.Property.IsWrongYear(propertyHolder.ImageFileHolder.FullName, propertyHolder.MinimumDateTime.Value);
|
||||||
isWrongYearFlag = GetWrongYearFlag(isWrongYear);
|
isWrongYearFlag = GetWrongYearFlag(isWrongYear);
|
||||||
subDirectoryName = $"{isWrongYearFlag}{propertyHolder.MinimumDateTime.Value:yyyy}";
|
subDirectoryName = $"{isWrongYearFlag}{propertyHolder.MinimumDateTime.Value:yyyy}";
|
||||||
if (!faceCollection.Any())
|
if (!faceCollection.Any())
|
||||||
@ -209,7 +218,7 @@ public class PropertyHolder
|
|||||||
copyDirectory = Path.Combine(dFacesContentDirectory, "Images", personKey, subDirectoryName);
|
copyDirectory = Path.Combine(dFacesContentDirectory, "Images", personKey, subDirectoryName);
|
||||||
else
|
else
|
||||||
copyDirectory = Path.Combine(dFacesContentDirectory, "ImagesBut", personKey, subDirectoryName);
|
copyDirectory = Path.Combine(dFacesContentDirectory, "ImagesBut", personKey, subDirectoryName);
|
||||||
copyFileName = Path.Combine(copyDirectory, $"{propertyHolder.Property.Id.Value}{propertyHolder.ResizedFileInfo.Extension}");
|
copyFileName = Path.Combine(copyDirectory, $"{propertyHolder.Property.Id.Value}{propertyHolder.ResizedFileHolder.Extension}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shortcutFileName = Path.Combine(directory, $"{propertyHolder.Property.Id.Value}.lnk");
|
shortcutFileName = Path.Combine(directory, $"{propertyHolder.Property.Id.Value}.lnk");
|
||||||
@ -225,7 +234,7 @@ public class PropertyHolder
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Dictionary<string, List<(string[], PersonBirthday, IFace)>> GetKeyValuePairs(string argZero, List<PropertyHolder[]> propertyHolderCollections, string eDistanceCollectionDirectory)
|
public static Dictionary<string, List<(string[], PersonBirthday, IFace)>> GetKeyValuePairs(string argZero, List<PropertyHolder[]> propertyHolderCollections)
|
||||||
{
|
{
|
||||||
Dictionary<string, List<(string[], PersonBirthday, IFace)>> results = new();
|
Dictionary<string, List<(string[], PersonBirthday, IFace)>> results = new();
|
||||||
string key;
|
string key;
|
||||||
@ -233,7 +242,7 @@ public class PropertyHolder
|
|||||||
TimeSpan? timeSpan;
|
TimeSpan? timeSpan;
|
||||||
string[] directories;
|
string[] directories;
|
||||||
string isWrongYearFlag;
|
string isWrongYearFlag;
|
||||||
string facePopulatedKey;
|
const string facePopulatedKey = "Images";
|
||||||
foreach (PropertyHolder[] propertyHolderCollection in propertyHolderCollections)
|
foreach (PropertyHolder[] propertyHolderCollection in propertyHolderCollections)
|
||||||
{
|
{
|
||||||
if (!propertyHolderCollection.Any())
|
if (!propertyHolderCollection.Any())
|
||||||
@ -242,24 +251,20 @@ public class PropertyHolder
|
|||||||
continue;
|
continue;
|
||||||
foreach (PropertyHolder propertyHolder in propertyHolderCollection)
|
foreach (PropertyHolder propertyHolder in propertyHolderCollection)
|
||||||
{
|
{
|
||||||
if (propertyHolder.ImageFileInfo is null || propertyHolder.Property is null || !propertyHolder.Named.Any())
|
if (propertyHolder.ImageFileHolder is null || propertyHolder.Property is null || !propertyHolder.Named.Any())
|
||||||
continue;
|
continue;
|
||||||
foreach ((bool? isWrongYear, DateTime minimumDateTime, PersonBirthday personBirthday, double? pixelPercentage) in propertyHolder.Named)
|
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))
|
if (pixelPercentage is null && (propertyHolder.Named.Count != 1 || propertyHolder.Faces.Count != 1))
|
||||||
continue;
|
continue;
|
||||||
foreach (IFace face in propertyHolder.Faces)
|
foreach (IFace face in propertyHolder.Faces)
|
||||||
{
|
{
|
||||||
|
if (!face.Populated)
|
||||||
|
continue;
|
||||||
if (pixelPercentage.HasValue && pixelPercentage.Value != face.Location.PixelPercentage)
|
if (pixelPercentage.HasValue && pixelPercentage.Value != face.Location.PixelPercentage)
|
||||||
continue;
|
continue;
|
||||||
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
personKey = Shared.Models.Stateless.Methods.IPersonBirthday.GetFormatted(personBirthday);
|
||||||
timeSpan = Shared.Models.Stateless.Methods.IPersonBirthday.GetTimeSpan(minimumDateTime, isWrongYear, 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)
|
if (timeSpan.HasValue && timeSpan.Value.Ticks < 0)
|
||||||
directories = new string[] { string.Empty, facePopulatedKey, personKey, "!---" };
|
directories = new string[] { string.Empty, facePopulatedKey, personKey, "!---" };
|
||||||
else if (timeSpan.HasValue)
|
else if (timeSpan.HasValue)
|
||||||
@ -267,12 +272,11 @@ public class PropertyHolder
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
isWrongYearFlag = GetWrongYearFlag(isWrongYear);
|
isWrongYearFlag = GetWrongYearFlag(isWrongYear);
|
||||||
directories = new string[] { string.Empty, facePopulatedKey, personKey, $"{isWrongYearFlag}{propertyHolder.MinimumDateTime.Value:yyyy}" };
|
directories = new string[] { string.Empty, facePopulatedKey, personKey, $"{isWrongYearFlag}{minimumDateTime:yyyy}" };
|
||||||
}
|
}
|
||||||
key = string.Join('\t', directories);
|
key = string.Join('\t', directories);
|
||||||
if (!results.ContainsKey(key))
|
if (!results.ContainsKey(key))
|
||||||
results.Add(key, new());
|
results.Add(key, new());
|
||||||
directories[0] = eDistanceCollectionDirectory;
|
|
||||||
results[key].Add(new(directories, personBirthday, face));
|
results[key].Add(new(directories, personBirthday, face));
|
||||||
if (pixelPercentage is null)
|
if (pixelPercentage is null)
|
||||||
break;
|
break;
|
||||||
@ -283,23 +287,4 @@ public class PropertyHolder
|
|||||||
return results;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -160,15 +160,15 @@ public class PropertyLogic
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<DateTime> GetMetadataDateTimesByPattern(string dateTimeFormat, FileInfo filteredSourceDirectoryFileInfo)
|
public static List<DateTime> GetMetadataDateTimesByPattern(string dateTimeFormat, FileHolder filteredSourceDirectoryFileHolder)
|
||||||
{
|
{
|
||||||
List<DateTime> results = GetMetadataDateTimesByPattern(dateTimeFormat, filteredSourceDirectoryFileInfo.FullName);
|
List<DateTime> results = GetMetadataDateTimesByPattern(dateTimeFormat, filteredSourceDirectoryFileHolder.FullName);
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable CA1416
|
#pragma warning disable CA1416
|
||||||
|
|
||||||
private A_Property GetImageProperty(string angleBracket, FileInfo filteredSourceDirectoryFileInfo, bool populateId, bool isIgnoreExtension, bool isValidImageFormatExtension, bool isValidMetadataExtensions, int? id, List<int> indices)
|
private A_Property GetImageProperty(string angleBracket, FileHolder filteredSourceDirectoryFileHolder, bool populateId, bool isIgnoreExtension, bool isValidImageFormatExtension, bool isValidMetadataExtensions, int? id, List<int> indices)
|
||||||
{
|
{
|
||||||
A_Property result;
|
A_Property result;
|
||||||
if (_Log is null)
|
if (_Log is null)
|
||||||
@ -178,6 +178,7 @@ public class PropertyLogic
|
|||||||
long ticks;
|
long ticks;
|
||||||
byte[] bytes;
|
byte[] bytes;
|
||||||
string value;
|
string value;
|
||||||
|
long fileLength;
|
||||||
int encodingHash;
|
int encodingHash;
|
||||||
int? width = null;
|
int? width = null;
|
||||||
int? height = null;
|
int? height = null;
|
||||||
@ -194,7 +195,7 @@ public class PropertyLogic
|
|||||||
if (!isValidImageFormatExtension && isValidMetadataExtensions)
|
if (!isValidImageFormatExtension && isValidMetadataExtensions)
|
||||||
{
|
{
|
||||||
dateTimeFormat = "ddd MMM dd HH:mm:ss yyyy";
|
dateTimeFormat = "ddd MMM dd HH:mm:ss yyyy";
|
||||||
List<DateTime> dateTimes = GetMetadataDateTimesByPattern(dateTimeFormat, filteredSourceDirectoryFileInfo);
|
List<DateTime> dateTimes = GetMetadataDateTimesByPattern(dateTimeFormat, filteredSourceDirectoryFileHolder);
|
||||||
if (dateTimes.Any())
|
if (dateTimes.Any())
|
||||||
dateTimeOriginal = dateTimes.Min();
|
dateTimeOriginal = dateTimes.Min();
|
||||||
}
|
}
|
||||||
@ -204,7 +205,7 @@ public class PropertyLogic
|
|||||||
throw new Exception("In order to keep six character indices at least one need to have an item!");
|
throw new Exception("In order to keep six character indices at least one need to have an item!");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using Image image = Image.FromFile(filteredSourceDirectoryFileInfo.FullName);
|
using Image image = Image.FromFile(filteredSourceDirectoryFileHolder.FullName);
|
||||||
if (populateId && (id is null || !indices.Any()))
|
if (populateId && (id is null || !indices.Any()))
|
||||||
{
|
{
|
||||||
using Bitmap bitmap = new(image);
|
using Bitmap bitmap = new(image);
|
||||||
@ -224,7 +225,7 @@ public class PropertyLogic
|
|||||||
}
|
}
|
||||||
if (_Configuration.WriteBitmapDataBytes.Value)
|
if (_Configuration.WriteBitmapDataBytes.Value)
|
||||||
{
|
{
|
||||||
FileInfo contentFileInfo = new(Path.Combine(angleBracket.Replace("<>", "()"), filteredSourceDirectoryFileInfo.Name));
|
FileInfo contentFileInfo = new(Path.Combine(angleBracket.Replace("<>", "()"), filteredSourceDirectoryFileHolder.Name));
|
||||||
File.WriteAllBytes(Path.ChangeExtension(contentFileInfo.FullName, string.Empty), bytes);
|
File.WriteAllBytes(Path.ChangeExtension(contentFileInfo.FullName, string.Empty), bytes);
|
||||||
}
|
}
|
||||||
if (_IndicesFromNew.ContainsKey(id.Value) && _IndicesFromNew[id.Value].Any())
|
if (_IndicesFromNew.ContainsKey(id.Value) && _IndicesFromNew[id.Value].Any())
|
||||||
@ -325,12 +326,16 @@ public class PropertyLogic
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
_Log.Info(string.Concat(new StackFrame().GetMethod()?.Name, " <", filteredSourceDirectoryFileInfo.Name, ">"));
|
_Log.Info(string.Concat(new StackFrame().GetMethod()?.Name, " <", filteredSourceDirectoryFileHolder.Name, ">"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
dateTimeOriginal = null;
|
dateTimeOriginal = null;
|
||||||
result = new(filteredSourceDirectoryFileInfo.CreationTime, dateTime, dateTimeDigitized, dateTimeOriginal, filteredSourceDirectoryFileInfo.Length, gpsDateStamp, height, id, indices.ToArray(), filteredSourceDirectoryFileInfo.LastWriteTime, make, model, orientation, width);
|
if (filteredSourceDirectoryFileHolder.Length is null)
|
||||||
|
fileLength = 0;
|
||||||
|
else
|
||||||
|
fileLength = filteredSourceDirectoryFileHolder.Length.Value;
|
||||||
|
result = new(filteredSourceDirectoryFileHolder.CreationTime, dateTime, dateTimeDigitized, dateTimeOriginal, fileLength, gpsDateStamp, height, id, indices.ToArray(), filteredSourceDirectoryFileHolder.LastWriteTime, make, model, orientation, width);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,8 +398,8 @@ public class PropertyLogic
|
|||||||
json = File.ReadAllText(fileInfo.FullName);
|
json = File.ReadAllText(fileInfo.FullName);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (propertyHolder.ImageFileInfo is null)
|
if (propertyHolder.ImageFileHolder is null)
|
||||||
throw new ArgumentException($"{propertyHolder.ImageFileInfo} is null!");
|
throw new ArgumentException($"{propertyHolder.ImageFileHolder} is null!");
|
||||||
bool check = true;
|
bool check = true;
|
||||||
A_Property? property = JsonSerializer.Deserialize<A_Property>(json);
|
A_Property? property = JsonSerializer.Deserialize<A_Property>(json);
|
||||||
if (!isIgnoreExtension && isValidImageFormatExtension && ((populateId && property?.Id is null) || property?.Width is null || property?.Height is null))
|
if (!isIgnoreExtension && isValidImageFormatExtension && ((populateId && property?.Id is null) || property?.Width is null || property?.Height is null))
|
||||||
@ -403,7 +408,7 @@ public class PropertyLogic
|
|||||||
id = property?.Id;
|
id = property?.Id;
|
||||||
if (property is not null && property.Indices.Any())
|
if (property is not null && property.Indices.Any())
|
||||||
indices = property.Indices.ToList();
|
indices = property.Indices.ToList();
|
||||||
property = GetImageProperty(angleBracket, propertyHolder.ImageFileInfo, populateId, isIgnoreExtension, isValidImageFormatExtension, isValidMetadataExtensions, id, indices);
|
property = GetImageProperty(angleBracket, propertyHolder.ImageFileHolder, populateId, isIgnoreExtension, isValidImageFormatExtension, isValidMetadataExtensions, id, indices);
|
||||||
}
|
}
|
||||||
if (!isIgnoreExtension && isValidImageFormatExtension && populateId && property is not null && !property.Indices.Any())
|
if (!isIgnoreExtension && isValidImageFormatExtension && populateId && property is not null && !property.Indices.Any())
|
||||||
{
|
{
|
||||||
@ -411,22 +416,22 @@ public class PropertyLogic
|
|||||||
id = property?.Id;
|
id = property?.Id;
|
||||||
if (property is not null && property.Indices.Any())
|
if (property is not null && property.Indices.Any())
|
||||||
indices = property.Indices.ToList();
|
indices = property.Indices.ToList();
|
||||||
property = GetImageProperty(angleBracket, propertyHolder.ImageFileInfo, populateId, isIgnoreExtension, isValidImageFormatExtension, isValidMetadataExtensions, id, indices);
|
property = GetImageProperty(angleBracket, propertyHolder.ImageFileHolder, populateId, isIgnoreExtension, isValidImageFormatExtension, isValidMetadataExtensions, id, indices);
|
||||||
}
|
}
|
||||||
if (!isIgnoreExtension && isValidImageFormatExtension && populateId && property is not null && property.LastWriteTime != propertyHolder.ImageFileInfo.LastWriteTime)
|
if (!isIgnoreExtension && isValidImageFormatExtension && populateId && property is not null && property.LastWriteTime != propertyHolder.ImageFileHolder.LastWriteTime)
|
||||||
{
|
{
|
||||||
check = false;
|
check = false;
|
||||||
id = null;
|
id = null;
|
||||||
indices.Clear();
|
indices.Clear();
|
||||||
property = GetImageProperty(angleBracket, propertyHolder.ImageFileInfo, populateId, isIgnoreExtension, isValidImageFormatExtension, isValidMetadataExtensions, id, indices);
|
property = GetImageProperty(angleBracket, propertyHolder.ImageFileHolder, populateId, isIgnoreExtension, isValidImageFormatExtension, isValidMetadataExtensions, id, indices);
|
||||||
}
|
}
|
||||||
if (!isIgnoreExtension && isValidImageFormatExtension && property?.Width is not null && property?.Height is not null && property.Width.Value == property.Height.Value && propertyHolder.ImageFileInfo.Exists)
|
if (!isIgnoreExtension && isValidImageFormatExtension && property?.Width is not null && property?.Height is not null && property.Width.Value == property.Height.Value && propertyHolder.ImageFileHolder.Exists)
|
||||||
{
|
{
|
||||||
check = false;
|
check = false;
|
||||||
id = property?.Id;
|
id = property?.Id;
|
||||||
if (property is not null && property.Indices.Any())
|
if (property is not null && property.Indices.Any())
|
||||||
indices = property.Indices.ToList();
|
indices = property.Indices.ToList();
|
||||||
property = GetImageProperty(angleBracket, propertyHolder.ImageFileInfo, populateId, isIgnoreExtension, isValidImageFormatExtension, isValidMetadataExtensions, id, indices);
|
property = GetImageProperty(angleBracket, propertyHolder.ImageFileHolder, populateId, isIgnoreExtension, isValidImageFormatExtension, isValidMetadataExtensions, id, indices);
|
||||||
if (property?.Width is not null && property?.Height is not null && property.Width.Value != property.Height.Value)
|
if (property?.Width is not null && property?.Height is not null && property.Width.Value != property.Height.Value)
|
||||||
throw new Exception("Was square!");
|
throw new Exception("Was square!");
|
||||||
}
|
}
|
||||||
@ -460,9 +465,9 @@ public class PropertyLogic
|
|||||||
}
|
}
|
||||||
if (result is null)
|
if (result is null)
|
||||||
{
|
{
|
||||||
if (propertyHolder.ImageFileInfo is null)
|
if (propertyHolder.ImageFileHolder is null)
|
||||||
throw new ArgumentException($"{propertyHolder.ImageFileInfo} is null!");
|
throw new ArgumentException($"{propertyHolder.ImageFileHolder} is null!");
|
||||||
result = GetImageProperty(angleBracket, propertyHolder.ImageFileInfo, populateId, isIgnoreExtension, isValidImageFormatExtension, isValidMetadataExtensions, id, indices);
|
result = GetImageProperty(angleBracket, propertyHolder.ImageFileHolder, populateId, isIgnoreExtension, isValidImageFormatExtension, isValidMetadataExtensions, id, indices);
|
||||||
json = JsonSerializer.Serialize(result, _WriteIndentedJsonSerializerOptions);
|
json = JsonSerializer.Serialize(result, _WriteIndentedJsonSerializerOptions);
|
||||||
if (populateId && IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
if (populateId && IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
||||||
{
|
{
|
||||||
@ -511,14 +516,14 @@ public class PropertyLogic
|
|||||||
continue;
|
continue;
|
||||||
if (propertyHolder.Property is null)
|
if (propertyHolder.Property is null)
|
||||||
continue;
|
continue;
|
||||||
if (propertyHolder.ImageFileInfo is null)
|
if (propertyHolder.ImageFileHolder is null)
|
||||||
continue;
|
continue;
|
||||||
minimumDateTime = Stateless.A_Property.GetMinimumDateTime(propertyHolder.Property);
|
minimumDateTime = Stateless.A_Property.GetMinimumDateTime(propertyHolder.Property);
|
||||||
if (minimumDateTime > directoryMaximumOfMinimumDateTime)
|
if (minimumDateTime > directoryMaximumOfMinimumDateTime)
|
||||||
directoryMaximumOfMinimumDateTime = minimumDateTime;
|
directoryMaximumOfMinimumDateTime = minimumDateTime;
|
||||||
if (minimumDateTime != propertyHolder.ImageFileInfo.CreationTime)
|
if (minimumDateTime != propertyHolder.ImageFileHolder.CreationTime)
|
||||||
{
|
{
|
||||||
(isWrongYear, matches) = propertyHolder.Property.IsWrongYear(propertyHolder.ImageFileInfo.FullName, minimumDateTime);
|
(isWrongYear, matches) = propertyHolder.Property.IsWrongYear(propertyHolder.ImageFileHolder.FullName, minimumDateTime);
|
||||||
if (isWrongYear is null || !isWrongYear.Value)
|
if (isWrongYear is null || !isWrongYear.Value)
|
||||||
dateTime = minimumDateTime;
|
dateTime = minimumDateTime;
|
||||||
else
|
else
|
||||||
@ -529,18 +534,18 @@ public class PropertyLogic
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{ File.SetCreationTime(propertyHolder.ImageFileInfo.FullName, dateTime); }
|
{ File.SetCreationTime(propertyHolder.ImageFileHolder.FullName, dateTime); }
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
if (!_VerifyToSeason.Contains(sourceDirectory))
|
if (!_VerifyToSeason.Contains(sourceDirectory))
|
||||||
continue;
|
continue;
|
||||||
if (!propertyHolder.ImageFileInfo.FullName.Contains("zzz ") && !propertyHolder.ImageFileInfo.FullName.Contains("Camera ") && propertyHolder.Property.DateTimeOriginal.HasValue)
|
if (!propertyHolder.ImageFileHolder.FullName.Contains("zzz ") && !propertyHolder.ImageFileHolder.FullName.Contains("Camera ") && propertyHolder.Property.DateTimeOriginal.HasValue)
|
||||||
{
|
{
|
||||||
TimeSpan timeSpan = new(propertyHolder.Property.DateTimeOriginal.Value.Ticks - propertyHolder.Property.LastWriteTime.Ticks);
|
TimeSpan timeSpan = new(propertyHolder.Property.DateTimeOriginal.Value.Ticks - propertyHolder.Property.LastWriteTime.Ticks);
|
||||||
if (timeSpan.TotalHours > 6)
|
if (timeSpan.TotalHours > 6)
|
||||||
{
|
{
|
||||||
_Log.Warning($"*** propertyHolder.FileInfo.FullName <{propertyHolder.ImageFileInfo.FullName}>");
|
_Log.Warning($"*** propertyHolder.FileInfo.FullName <{propertyHolder.ImageFileHolder.FullName}>");
|
||||||
_Log.Warning($"*** DateTimeOriginal <{propertyHolder.Property.DateTimeOriginal.Value}>");
|
_Log.Warning($"*** DateTimeOriginal <{propertyHolder.Property.DateTimeOriginal.Value}>");
|
||||||
_Log.Warning($"*** LastWriteTime <{propertyHolder.Property.LastWriteTime}>");
|
_Log.Warning($"*** LastWriteTime <{propertyHolder.Property.LastWriteTime}>");
|
||||||
_Log.Warning($"*** TotalHours <{timeSpan.TotalHours}>");
|
_Log.Warning($"*** TotalHours <{timeSpan.TotalHours}>");
|
||||||
@ -562,35 +567,35 @@ public class PropertyLogic
|
|||||||
result = true;
|
result = true;
|
||||||
if (!Directory.Exists(destinationDirectory))
|
if (!Directory.Exists(destinationDirectory))
|
||||||
_ = Directory.CreateDirectory(destinationDirectory);
|
_ = Directory.CreateDirectory(destinationDirectory);
|
||||||
destinationFile = Path.Combine(destinationDirectory, propertyHolder.ImageFileInfo.Name);
|
destinationFile = Path.Combine(destinationDirectory, propertyHolder.ImageFileHolder.Name);
|
||||||
if (File.Exists(destinationFile))
|
if (File.Exists(destinationFile))
|
||||||
{
|
{
|
||||||
if (destinationFile.EndsWith(".jpg", ignoreCase: true, CultureInfo.CurrentCulture))
|
if (destinationFile.EndsWith(".jpg", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||||
destinationFile = Path.Combine(destinationDirectory, Path.ChangeExtension(propertyHolder.ImageFileInfo.Name, ".jpeg"));
|
destinationFile = Path.Combine(destinationDirectory, Path.ChangeExtension(propertyHolder.ImageFileHolder.Name, ".jpeg"));
|
||||||
else if (destinationFile.EndsWith(".jpeg", ignoreCase: true, CultureInfo.CurrentCulture))
|
else if (destinationFile.EndsWith(".jpeg", ignoreCase: true, CultureInfo.CurrentCulture))
|
||||||
destinationFile = Path.Combine(destinationDirectory, Path.ChangeExtension(propertyHolder.ImageFileInfo.Name, ".jpg"));
|
destinationFile = Path.Combine(destinationDirectory, Path.ChangeExtension(propertyHolder.ImageFileHolder.Name, ".jpg"));
|
||||||
}
|
}
|
||||||
if (File.Exists(destinationFile))
|
if (File.Exists(destinationFile))
|
||||||
{
|
{
|
||||||
_Log.Information($"*** source <{propertyHolder.ImageFileInfo.FullName}>");
|
_Log.Information($"*** source <{propertyHolder.ImageFileHolder.FullName}>");
|
||||||
_Log.Information($"*** destination <{destinationFile}>");
|
_Log.Information($"*** destination <{destinationFile}>");
|
||||||
if (propertyHolder.ImageFileInfo.Exists)
|
if (propertyHolder.ImageFileHolder.Exists)
|
||||||
{
|
{
|
||||||
deleteFile = Path.ChangeExtension(propertyHolder.ImageFileInfo.FullName, ".delete");
|
deleteFile = Path.ChangeExtension(propertyHolder.ImageFileHolder.FullName, ".delete");
|
||||||
if (File.Exists(deleteFile))
|
if (File.Exists(deleteFile))
|
||||||
File.Delete(deleteFile);
|
File.Delete(deleteFile);
|
||||||
File.Move(propertyHolder.ImageFileInfo.FullName, deleteFile);
|
File.Move(propertyHolder.ImageFileHolder.FullName, deleteFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
File.Move(propertyHolder.ImageFileInfo.FullName, destinationFile);
|
File.Move(propertyHolder.ImageFileHolder.FullName, destinationFile);
|
||||||
if (propertyHolder.ImageFileInfo.Exists)
|
if (propertyHolder.ImageFileHolder.Exists)
|
||||||
{
|
{
|
||||||
deleteFile = Path.ChangeExtension(propertyHolder.ImageFileInfo.FullName, ".delete");
|
deleteFile = Path.ChangeExtension(propertyHolder.ImageFileHolder.FullName, ".delete");
|
||||||
if (File.Exists(deleteFile))
|
if (File.Exists(deleteFile))
|
||||||
File.Delete(deleteFile);
|
File.Delete(deleteFile);
|
||||||
File.Move(propertyHolder.ImageFileInfo.FullName, deleteFile);
|
File.Move(propertyHolder.ImageFileHolder.FullName, deleteFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -603,24 +608,26 @@ public class PropertyLogic
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ParallelForWork(bool firstPass, string angleBracket, string sourceDirectory, List<Tuple<string, DateTime>> filteredSourceDirectoryFileTuples, PropertyHolder propertyHolder)
|
private void ParallelForWork(bool firstPass, string angleBracket, string sourceDirectory, List<Tuple<string, DateTime>> filteredSourceDirectoryFileTuples, List<Tuple<string, DateTime>> sourceDirectoryChanges, PropertyHolder propertyHolder)
|
||||||
{
|
{
|
||||||
if (propertyHolder.ImageFileInfo is null)
|
if (propertyHolder.ImageFileHolder is null)
|
||||||
throw new ArgumentNullException(nameof(propertyHolder.ImageFileInfo));
|
throw new ArgumentNullException(nameof(propertyHolder.ImageFileHolder));
|
||||||
A_Property property;
|
A_Property property;
|
||||||
List<string> parseExceptions = new();
|
List<string> parseExceptions = new();
|
||||||
string extensionLowered = propertyHolder.ImageFileInfo.Extension.ToLower();
|
string extensionLowered = propertyHolder.ImageFileHolder.Extension.ToLower();
|
||||||
bool isValidMetadataExtensions = _Configuration.ValidMetadataExtensions.Contains(extensionLowered);
|
bool isValidMetadataExtensions = _Configuration.ValidMetadataExtensions.Contains(extensionLowered);
|
||||||
bool isValidImageFormatExtension = _Configuration.ValidImageFormatExtensions.Contains(extensionLowered);
|
bool isValidImageFormatExtension = _Configuration.ValidImageFormatExtensions.Contains(extensionLowered);
|
||||||
lock (propertyHolder)
|
lock (propertyHolder)
|
||||||
propertyHolder.SetValidImageFormatExtension(isValidImageFormatExtension);
|
propertyHolder.SetValidImageFormatExtension(isValidImageFormatExtension);
|
||||||
bool isIgnoreExtension = isValidImageFormatExtension && _Configuration.IgnoreExtensions.Contains(extensionLowered);
|
bool isIgnoreExtension = isValidImageFormatExtension && _Configuration.IgnoreExtensions.Contains(extensionLowered);
|
||||||
string filteredSourceDirectoryFileExtensionLowered = Path.Combine(sourceDirectory, $"{propertyHolder.ImageFileNameWithoutExtension}{extensionLowered}");
|
string filteredSourceDirectoryFileExtensionLowered = Path.Combine(sourceDirectory, $"{propertyHolder.ImageFileNameWithoutExtension}{extensionLowered}");
|
||||||
if (isValidImageFormatExtension && propertyHolder.ImageFileInfo.FullName.Length == filteredSourceDirectoryFileExtensionLowered.Length && propertyHolder.ImageFileInfo.FullName != filteredSourceDirectoryFileExtensionLowered)
|
if (isValidImageFormatExtension && propertyHolder.ImageFileHolder.FullName.Length == filteredSourceDirectoryFileExtensionLowered.Length && propertyHolder.ImageFileHolder.FullName != filteredSourceDirectoryFileExtensionLowered)
|
||||||
File.Move(propertyHolder.ImageFileInfo.FullName, filteredSourceDirectoryFileExtensionLowered);
|
File.Move(propertyHolder.ImageFileHolder.FullName, filteredSourceDirectoryFileExtensionLowered);
|
||||||
if (propertyHolder.Changed is null || propertyHolder.Changed.Value || propertyHolder.Property is null)
|
if (propertyHolder.Changed is null || propertyHolder.Changed.Value || propertyHolder.Property is null)
|
||||||
{
|
{
|
||||||
property = GetPropertyOfPrivate(angleBracket, propertyHolder, firstPass, filteredSourceDirectoryFileTuples, parseExceptions, isIgnoreExtension, isValidImageFormatExtension, isValidMetadataExtensions, extensionLowered);
|
property = GetPropertyOfPrivate(angleBracket, propertyHolder, firstPass, filteredSourceDirectoryFileTuples, parseExceptions, isIgnoreExtension, isValidImageFormatExtension, isValidMetadataExtensions, extensionLowered);
|
||||||
|
lock (sourceDirectoryChanges)
|
||||||
|
sourceDirectoryChanges.Add(new Tuple<string, DateTime>(nameof(A_Property), DateTime.Now));
|
||||||
lock (propertyHolder)
|
lock (propertyHolder)
|
||||||
propertyHolder.Update(property);
|
propertyHolder.Update(property);
|
||||||
}
|
}
|
||||||
@ -631,7 +638,8 @@ public class PropertyLogic
|
|||||||
List<Tuple<string, DateTime>> filteredSourceDirectoryFileTuples = new();
|
List<Tuple<string, DateTime>> filteredSourceDirectoryFileTuples = new();
|
||||||
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = _MaxDegreeOfParallelism };
|
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = _MaxDegreeOfParallelism };
|
||||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||||
using ProgressBar progressBar = new(filteredPropertyHolderCollection.Length, $"{r + 1:000}.{g} / {propertyHolderCollectionsCount:000}) {filteredPropertyHolderCollection.Length:000} file(s) - {totalSeconds} total second(s) - {sourceDirectory}", options);
|
string message = $"{r + 1:000}.{g} / {propertyHolderCollectionsCount:000}) {filteredPropertyHolderCollection.Length:000} file(s) - {totalSeconds} total second(s) - {sourceDirectory}";
|
||||||
|
using ProgressBar progressBar = new(filteredPropertyHolderCollection.Length, message, options);
|
||||||
_ = Parallel.For(0, filteredPropertyHolderCollection.Length, parallelOptions, i =>
|
_ = Parallel.For(0, filteredPropertyHolderCollection.Length, parallelOptions, i =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -639,8 +647,9 @@ public class PropertyLogic
|
|||||||
long ticks = DateTime.Now.Ticks;
|
long ticks = DateTime.Now.Ticks;
|
||||||
DateTime dateTime = DateTime.Now;
|
DateTime dateTime = DateTime.Now;
|
||||||
List<Tuple<string, DateTime>> collection;
|
List<Tuple<string, DateTime>> collection;
|
||||||
ParallelForWork(firstPass, angleBracket, sourceDirectory, filteredSourceDirectoryFileTuples, filteredPropertyHolderCollection[i]);
|
ParallelForWork(firstPass, angleBracket, sourceDirectory, sourceDirectoryChanges, filteredSourceDirectoryFileTuples, filteredPropertyHolderCollection[i]);
|
||||||
progressBar.Tick();
|
if (i == 0 || sourceDirectoryChanges.Any())
|
||||||
|
progressBar.Tick();
|
||||||
lock (filteredSourceDirectoryFileTuples)
|
lock (filteredSourceDirectoryFileTuples)
|
||||||
collection = (from l in filteredSourceDirectoryFileTuples where l.Item2 > dateTime select l).ToList();
|
collection = (from l in filteredSourceDirectoryFileTuples where l.Item2 > dateTime select l).ToList();
|
||||||
lock (sourceDirectoryChanges)
|
lock (sourceDirectoryChanges)
|
||||||
@ -699,7 +708,7 @@ public class PropertyLogic
|
|||||||
if (firstPass)
|
if (firstPass)
|
||||||
filteredPropertyHolderCollection = (from l in propertyHolderCollection where l.NoJson is null || !l.NoJson.Value && (l.Changed is null || l.Changed.Value) select l).ToArray();
|
filteredPropertyHolderCollection = (from l in propertyHolderCollection where l.NoJson is null || !l.NoJson.Value && (l.Changed is null || l.Changed.Value) select l).ToArray();
|
||||||
else
|
else
|
||||||
filteredPropertyHolderCollection = (from l in propertyHolderCollection where l.ImageFileInfo is not null && !_Configuration.IgnoreExtensions.Contains(l.ImageFileInfo.Extension) select l).ToArray();
|
filteredPropertyHolderCollection = (from l in propertyHolderCollection where l.ImageFileHolder is not null && !_Configuration.IgnoreExtensions.Contains(l.ImageFileHolder.Extension) select l).ToArray();
|
||||||
if (!filteredPropertyHolderCollection.Any())
|
if (!filteredPropertyHolderCollection.Any())
|
||||||
continue;
|
continue;
|
||||||
g = filteredPropertyHolderCollection[0].G;
|
g = filteredPropertyHolderCollection[0].G;
|
||||||
@ -734,10 +743,10 @@ public class PropertyLogic
|
|||||||
public A_Property GetProperty(string angleBracket, PropertyHolder propertyHolder, List<Tuple<string, DateTime>> filteredSourceDirectoryFileTuples, List<string> parseExceptions)
|
public A_Property GetProperty(string angleBracket, PropertyHolder propertyHolder, List<Tuple<string, DateTime>> filteredSourceDirectoryFileTuples, List<string> parseExceptions)
|
||||||
{
|
{
|
||||||
A_Property result;
|
A_Property result;
|
||||||
if (propertyHolder.ImageFileInfo is null)
|
if (propertyHolder.ImageFileHolder is null)
|
||||||
throw new ArgumentException($"{propertyHolder.ImageFileInfo} is null!");
|
throw new ArgumentException($"{propertyHolder.ImageFileHolder} is null!");
|
||||||
bool firstPass = false;
|
bool firstPass = false;
|
||||||
string extensionLowered = propertyHolder.ImageFileInfo.Extension.ToLower();
|
string extensionLowered = propertyHolder.ImageFileHolder.Extension.ToLower();
|
||||||
bool isValidMetadataExtensions = _Configuration.ValidMetadataExtensions.Contains(extensionLowered);
|
bool isValidMetadataExtensions = _Configuration.ValidMetadataExtensions.Contains(extensionLowered);
|
||||||
bool isValidImageFormatExtension = _Configuration.ValidImageFormatExtensions.Contains(extensionLowered);
|
bool isValidImageFormatExtension = _Configuration.ValidImageFormatExtensions.Contains(extensionLowered);
|
||||||
bool isIgnoreExtension = isValidImageFormatExtension && _Configuration.IgnoreExtensions.Contains(extensionLowered);
|
bool isIgnoreExtension = isValidImageFormatExtension && _Configuration.IgnoreExtensions.Contains(extensionLowered);
|
||||||
@ -769,7 +778,7 @@ public class PropertyLogic
|
|||||||
}
|
}
|
||||||
if (!Directory.Exists(propertyDirectory))
|
if (!Directory.Exists(propertyDirectory))
|
||||||
_ = Directory.CreateDirectory(propertyDirectory);
|
_ = Directory.CreateDirectory(propertyDirectory);
|
||||||
for (int i = 0; i < group.SourceDirectoryFileInfoCollection.Length; i++)
|
for (int i = 0; i < group.SourceDirectoryFileHolderCollection.Length; i++)
|
||||||
{
|
{
|
||||||
property = group.PropertyCollection[i];
|
property = group.PropertyCollection[i];
|
||||||
if (property?.Id is null)
|
if (property?.Id is null)
|
||||||
|
@ -116,14 +116,14 @@ public static class A_Property
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<(int g, string sourceDirectory, FileInfo[] sourceDirectoryFiles, int r)> GetFileInfoGroupCollection(Models.Configuration configuration, bool reverse, string searchPattern, List<string> topDirectories)
|
public static List<(int g, string sourceDirectory, FileHolder[] sourceDirectoryFiles, int r)> GetFileHolderGroupCollection(Models.Configuration configuration, bool reverse, string searchPattern, List<string> topDirectories)
|
||||||
{
|
{
|
||||||
if (configuration.MaxImagesInDirectoryForTopLevelFirstPass is null)
|
if (configuration.MaxImagesInDirectoryForTopLevelFirstPass is null)
|
||||||
throw new ArgumentNullException(nameof(configuration.MaxImagesInDirectoryForTopLevelFirstPass));
|
throw new ArgumentNullException(nameof(configuration.MaxImagesInDirectoryForTopLevelFirstPass));
|
||||||
List<(int g, string sourceDirectory, FileInfo[] sourceDirectoryFiles, int r)> results = new();
|
List<(int g, string sourceDirectory, FileHolder[] sourceDirectoryFiles, int r)> results = new();
|
||||||
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)>? collection = GetGroupCollection(configuration.RootDirectory, searchPattern, topDirectories, configuration.MaxImagesInDirectoryForTopLevelFirstPass.Value, reverse);
|
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)
|
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles, int r) in collection)
|
||||||
results.Add(new(g, sourceDirectory, (from l in sourceDirectoryFiles select new FileInfo(l)).ToArray(), r));
|
results.Add(new(g, sourceDirectory, (from l in sourceDirectoryFiles select new FileHolder(l)).ToArray(), r));
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ public static class A_Property
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<PropertyHolder[]> Populate(Models.Configuration configuration, string aPropertySingletonDirectory, List<(int, string, FileInfo[], int)> fileInfoGroupCollection, List<(int, string, List<(string, Models.A_Property?)>, int)> collectionFromJson)
|
private static List<PropertyHolder[]> Populate(Models.Configuration configuration, string aPropertySingletonDirectory, List<(int, string, FileHolder[], int)> fileHolderGroupCollection, List<(int, string, List<(string, Models.A_Property?)>, int)> collectionFromJson)
|
||||||
{
|
{
|
||||||
List<PropertyHolder[]> results = new();
|
List<PropertyHolder[]> results = new();
|
||||||
if (configuration.PropertiesChangedForProperty is null)
|
if (configuration.PropertiesChangedForProperty is null)
|
||||||
@ -144,17 +144,17 @@ public static class A_Property
|
|||||||
int length;
|
int length;
|
||||||
string inferred;
|
string inferred;
|
||||||
string relativePath;
|
string relativePath;
|
||||||
FileInfo keyFileInfo;
|
FileHolder keyFileHolder;
|
||||||
string keySourceDirectory;
|
string keySourceDirectory;
|
||||||
List<PropertyHolder> propertyHolderCollection;
|
List<PropertyHolder> propertyHolderCollection;
|
||||||
Dictionary<string, (string SourceDirectory, FileInfo FileInfo)> fileInfoKeyValuePairs = new();
|
Dictionary<string, (string SourceDirectory, FileHolder FileHolder)> fileHolderKeyValuePairs = new();
|
||||||
length = configuration.RootDirectory.Length;
|
length = configuration.RootDirectory.Length;
|
||||||
foreach ((int g, string sourceDirectory, FileInfo[] sourceDirectoryFileInfoCollection, int r) in fileInfoGroupCollection)
|
foreach ((int g, string sourceDirectory, FileHolder[] sourceDirectoryFileHolderCollection, int r) in fileHolderGroupCollection)
|
||||||
{
|
{
|
||||||
foreach (FileInfo sourceDirectoryFileInfo in sourceDirectoryFileInfoCollection)
|
foreach (FileHolder sourceDirectoryFileHolder in sourceDirectoryFileHolderCollection)
|
||||||
{
|
{
|
||||||
relativePath = $"{XPath.GetRelativePath(sourceDirectoryFileInfo.FullName, length)}.json";
|
relativePath = $"{XPath.GetRelativePath(sourceDirectoryFileHolder.FullName, length)}.json";
|
||||||
fileInfoKeyValuePairs.Add(relativePath, new(sourceDirectory, sourceDirectoryFileInfo));
|
fileHolderKeyValuePairs.Add(relativePath, new(sourceDirectory, sourceDirectoryFileHolder));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
length = aPropertySingletonDirectory.Length;
|
length = aPropertySingletonDirectory.Length;
|
||||||
@ -166,53 +166,53 @@ public static class A_Property
|
|||||||
foreach ((string sourceDirectoryFile, Models.A_Property? property) in collection)
|
foreach ((string sourceDirectoryFile, Models.A_Property? property) in collection)
|
||||||
{
|
{
|
||||||
relativePath = XPath.GetRelativePath(sourceDirectoryFile, length);
|
relativePath = XPath.GetRelativePath(sourceDirectoryFile, length);
|
||||||
if (!fileInfoKeyValuePairs.ContainsKey(relativePath))
|
if (!fileHolderKeyValuePairs.ContainsKey(relativePath))
|
||||||
{
|
{
|
||||||
inferred = string.Concat(configuration.RootDirectory, relativePath);
|
inferred = string.Concat(configuration.RootDirectory, relativePath);
|
||||||
keyFileInfo = new(inferred[..^5]);
|
keyFileHolder = new(inferred[..^5]);
|
||||||
if (keyFileInfo.Extension is ".json")
|
if (keyFileHolder.Extension is ".json")
|
||||||
continue;
|
continue;
|
||||||
keySourceDirectory = string.Concat(keyFileInfo.DirectoryName);
|
keySourceDirectory = string.Concat(keyFileHolder.DirectoryName);
|
||||||
propertyHolderCollection.Add(new(g, keySourceDirectory, sourceDirectoryFile, relativePath, r, keyFileInfo, property, true, null, null, null));
|
propertyHolderCollection.Add(new(g, keySourceDirectory, sourceDirectoryFile, relativePath, r, keyFileHolder, property, true, null, null, null));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
keyFileInfo = fileInfoKeyValuePairs[relativePath].FileInfo;
|
keyFileHolder = fileHolderKeyValuePairs[relativePath].FileHolder;
|
||||||
keySourceDirectory = fileInfoKeyValuePairs[relativePath].SourceDirectory;
|
keySourceDirectory = fileHolderKeyValuePairs[relativePath].SourceDirectory;
|
||||||
if (!fileInfoKeyValuePairs.Remove(relativePath))
|
if (!fileHolderKeyValuePairs.Remove(relativePath))
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
if (keyFileInfo.Extension is ".json")
|
if (keyFileHolder.Extension is ".json")
|
||||||
continue;
|
continue;
|
||||||
if (property?.Id is null || property?.Width is null || property?.Height is null)
|
if (property?.Id is null || property?.Width is null || property?.Height is null)
|
||||||
propertyHolderCollection.Add(new(g, keySourceDirectory, sourceDirectoryFile, relativePath, r, keyFileInfo, property, false, null, null, null));
|
propertyHolderCollection.Add(new(g, keySourceDirectory, sourceDirectoryFile, relativePath, r, keyFileHolder, property, false, null, null, null));
|
||||||
else if (configuration.PropertiesChangedForProperty.Value || property.LastWriteTime != keyFileInfo.LastWriteTime || property.FileSize != keyFileInfo.Length)
|
else if (configuration.PropertiesChangedForProperty.Value || property.LastWriteTime != keyFileHolder.LastWriteTime || property.FileSize != keyFileHolder.Length)
|
||||||
propertyHolderCollection.Add(new(g, keySourceDirectory, sourceDirectoryFile, relativePath, r, keyFileInfo, property, false, true, null, null));
|
propertyHolderCollection.Add(new(g, keySourceDirectory, sourceDirectoryFile, relativePath, r, keyFileHolder, property, false, true, null, null));
|
||||||
else
|
else
|
||||||
propertyHolderCollection.Add(new(g, keySourceDirectory, sourceDirectoryFile, relativePath, r, keyFileInfo, property, false, false, null, null));
|
propertyHolderCollection.Add(new(g, keySourceDirectory, sourceDirectoryFile, relativePath, r, keyFileHolder, property, false, false, null, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (propertyHolderCollection.Any())
|
if (propertyHolderCollection.Any())
|
||||||
results.Add(propertyHolderCollection.ToArray());
|
results.Add(propertyHolderCollection.ToArray());
|
||||||
}
|
}
|
||||||
length = configuration.RootDirectory.Length;
|
length = configuration.RootDirectory.Length;
|
||||||
foreach ((int g, string sourceDirectory, FileInfo[] sourceDirectoryFileInfoCollection, int r) in fileInfoGroupCollection)
|
foreach ((int g, string sourceDirectory, FileHolder[] sourceDirectoryFileHolderCollection, int r) in fileHolderGroupCollection)
|
||||||
{
|
{
|
||||||
propertyHolderCollection = new();
|
propertyHolderCollection = new();
|
||||||
foreach (FileInfo sourceDirectoryFileInfo in sourceDirectoryFileInfoCollection)
|
foreach (FileHolder sourceDirectoryFileHolder in sourceDirectoryFileHolderCollection)
|
||||||
{
|
{
|
||||||
relativePath = $"{XPath.GetRelativePath(sourceDirectoryFileInfo.FullName, length)}.json";
|
relativePath = $"{XPath.GetRelativePath(sourceDirectoryFileHolder.FullName, length)}.json";
|
||||||
if (!fileInfoKeyValuePairs.ContainsKey(relativePath))
|
if (!fileHolderKeyValuePairs.ContainsKey(relativePath))
|
||||||
continue;
|
continue;
|
||||||
if (!fileInfoKeyValuePairs.Remove(relativePath))
|
if (!fileHolderKeyValuePairs.Remove(relativePath))
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
if (sourceDirectoryFileInfo.Extension is ".json")
|
if (sourceDirectoryFileHolder.Extension is ".json")
|
||||||
continue;
|
continue;
|
||||||
propertyHolderCollection.Add(new(g, sourceDirectory, relativePath, sourceDirectoryFileInfo.FullName, r, sourceDirectoryFileInfo, null, null, null, null, null));
|
propertyHolderCollection.Add(new(g, sourceDirectory, relativePath, sourceDirectoryFileHolder.FullName, r, sourceDirectoryFileHolder, null, null, null, null, null));
|
||||||
}
|
}
|
||||||
if (propertyHolderCollection.Any())
|
if (propertyHolderCollection.Any())
|
||||||
results.Add(propertyHolderCollection.ToArray());
|
results.Add(propertyHolderCollection.ToArray());
|
||||||
}
|
}
|
||||||
if (fileInfoKeyValuePairs.Any())
|
if (fileHolderKeyValuePairs.Any())
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
results = (from l in results orderby l[0].G, l[0].R select l).ToList();
|
results = (from l in results orderby l[0].G, l[0].R select l).ToList();
|
||||||
return results;
|
return results;
|
||||||
@ -243,13 +243,13 @@ public static class A_Property
|
|||||||
long ticks = DateTime.Now.Ticks;
|
long ticks = DateTime.Now.Ticks;
|
||||||
List<string> topDirectories = new();
|
List<string> topDirectories = new();
|
||||||
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> jsonCollection;
|
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> jsonCollection;
|
||||||
List<(int g, string sourceDirectory, FileInfo[] sourceDirectoryFiles, int r)> fileInfoGroupCollection;
|
List<(int g, string sourceDirectory, FileHolder[] sourceDirectoryFiles, int r)> fileHolderGroupCollection;
|
||||||
string aPropertySingletonDirectory = IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
|
string aPropertySingletonDirectory = IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
|
||||||
List<(int g, string sourceDirectory, List<(string sourceDirectoryFile, Models.A_Property? property)> collection, int r)> collectionFromJson;
|
List<(int g, string sourceDirectory, List<(string sourceDirectoryFile, Models.A_Property? property)> collection, int r)> collectionFromJson;
|
||||||
jsonCollection = GetJsonGroupCollection(aPropertySingletonDirectory);
|
jsonCollection = GetJsonGroupCollection(aPropertySingletonDirectory);
|
||||||
fileInfoGroupCollection = GetFileInfoGroupCollection(configuration, reverse, searchPattern, topDirectories);
|
fileHolderGroupCollection = GetFileHolderGroupCollection(configuration, reverse, searchPattern, topDirectories);
|
||||||
collectionFromJson = GetCollection(aPropertySingletonDirectory, jsonCollection);
|
collectionFromJson = GetCollection(aPropertySingletonDirectory, jsonCollection);
|
||||||
results = Populate(configuration, aPropertySingletonDirectory, fileInfoGroupCollection, collectionFromJson);
|
results = Populate(configuration, aPropertySingletonDirectory, fileHolderGroupCollection, collectionFromJson);
|
||||||
propertyLogic.ParallelWork(configuration, model, predictorModel, ticks, results, firstPass: false);
|
propertyLogic.ParallelWork(configuration, model, predictorModel, ticks, results, firstPass: false);
|
||||||
if (propertyLogic.ExceptionsDirectories.Any())
|
if (propertyLogic.ExceptionsDirectories.Any())
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
|
@ -129,7 +129,7 @@ public class C_Resize
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] SaveResizedSubfile3(string subFile, int[] resize, byte[] bytes, FileInfo? fileInfo)
|
private byte[] SaveResizedSubfile3(string subFile, int[] resize, byte[] bytes, FileHolder? fileHolder)
|
||||||
{
|
{
|
||||||
byte[] results;
|
byte[] results;
|
||||||
Bitmap bitmap;
|
Bitmap bitmap;
|
||||||
@ -169,19 +169,19 @@ public class C_Resize
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (fileInfo is null)
|
if (fileHolder is null)
|
||||||
results = GetBitmapData(bitmap);
|
results = GetBitmapData(bitmap);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
results = Array.Empty<byte>();
|
results = Array.Empty<byte>();
|
||||||
CopyPropertyItems(bytes, propertyItems, bitmap);
|
CopyPropertyItems(bytes, propertyItems, bitmap);
|
||||||
bitmap.Save(fileInfo.FullName, _ImageCodecInfo, _EncoderParameters);
|
bitmap.Save(fileHolder.FullName, _ImageCodecInfo, _EncoderParameters);
|
||||||
}
|
}
|
||||||
bitmap.Dispose();
|
bitmap.Dispose();
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] SaveResizedSubfile5(string subFile, int[] resize, byte[] bytes, FileInfo? fileInfo)
|
private byte[] SaveResizedSubfile5(string subFile, int[] resize, byte[] bytes, FileHolder? fileHolder)
|
||||||
{
|
{
|
||||||
byte[] results;
|
byte[] results;
|
||||||
Bitmap bitmap;
|
Bitmap bitmap;
|
||||||
@ -233,13 +233,13 @@ public class C_Resize
|
|||||||
{
|
{
|
||||||
using (Graphics graphics = Graphics.FromImage(preRotated))
|
using (Graphics graphics = Graphics.FromImage(preRotated))
|
||||||
graphics.DrawImage(bitmap, new Rectangle(0, 0, outputResolutionWidth, outputResolutionHeight), rectangle, GraphicsUnit.Pixel);
|
graphics.DrawImage(bitmap, new Rectangle(0, 0, outputResolutionWidth, outputResolutionHeight), rectangle, GraphicsUnit.Pixel);
|
||||||
if (fileInfo is null)
|
if (fileHolder is null)
|
||||||
results = GetBitmapData(bitmap);
|
results = GetBitmapData(bitmap);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
results = Array.Empty<byte>();
|
results = Array.Empty<byte>();
|
||||||
CopyPropertyItems(bytes, propertyItems, bitmap);
|
CopyPropertyItems(bytes, propertyItems, bitmap);
|
||||||
bitmap.Save(fileInfo.FullName, _ImageCodecInfo, _EncoderParameters);
|
bitmap.Save(fileHolder.FullName, _ImageCodecInfo, _EncoderParameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bitmap.Dispose();
|
bitmap.Dispose();
|
||||||
@ -248,7 +248,7 @@ public class C_Resize
|
|||||||
|
|
||||||
#pragma warning restore CA1416
|
#pragma warning restore CA1416
|
||||||
|
|
||||||
private byte[] SaveResizedSubfile(string subFile, A_Property property, int[] resize, FileInfo? fileInfo)
|
private byte[] SaveResizedSubfile(string subFile, A_Property property, int[] resize, FileHolder? fileHolder)
|
||||||
{
|
{
|
||||||
byte[] results;
|
byte[] results;
|
||||||
string dateTimeFormat = Property.Models.Stateless.A_Property.DateTimeFormat();
|
string dateTimeFormat = Property.Models.Stateless.A_Property.DateTimeFormat();
|
||||||
@ -258,15 +258,15 @@ public class C_Resize
|
|||||||
if (_ASCIIEncoding.GetString(bytes, 0, bytes.Length) != dateTimeValue)
|
if (_ASCIIEncoding.GetString(bytes, 0, bytes.Length) != dateTimeValue)
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
if (resize.Length == 3)
|
if (resize.Length == 3)
|
||||||
results = SaveResizedSubfile3(subFile, resize, bytes, fileInfo);
|
results = SaveResizedSubfile3(subFile, resize, bytes, fileHolder);
|
||||||
else if (resize.Length == 5)
|
else if (resize.Length == 5)
|
||||||
results = SaveResizedSubfile5(subFile, resize, bytes, fileInfo);
|
results = SaveResizedSubfile5(subFile, resize, bytes, fileHolder);
|
||||||
else
|
else
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
if (fileInfo is not null && false)
|
if (fileHolder is not null && false)
|
||||||
{
|
{
|
||||||
#pragma warning disable CA1416
|
#pragma warning disable CA1416
|
||||||
using Image image = Image.FromFile(fileInfo.FullName);
|
using Image image = Image.FromFile(fileHolder.FullName);
|
||||||
if (image.PropertyIdList.Contains((int)IExif.Tags.DateTimeDigitized))
|
if (image.PropertyIdList.Contains((int)IExif.Tags.DateTimeDigitized))
|
||||||
{
|
{
|
||||||
string value;
|
string value;
|
||||||
@ -287,37 +287,38 @@ public class C_Resize
|
|||||||
public byte[] GetResizedBytes(string outputResolution, List<Tuple<string, DateTime>> subFileTuples, PropertyHolder propertyHolder, A_Property property, Dictionary<string, int[]> imageResizes)
|
public byte[] GetResizedBytes(string outputResolution, List<Tuple<string, DateTime>> subFileTuples, PropertyHolder propertyHolder, A_Property property, Dictionary<string, int[]> imageResizes)
|
||||||
{
|
{
|
||||||
byte[] results;
|
byte[] results;
|
||||||
if (propertyHolder.ImageFileInfo is null)
|
if (propertyHolder.ImageFileHolder is null)
|
||||||
throw new Exception($"{propertyHolder.ImageFileInfo} is null!");
|
throw new Exception($"{propertyHolder.ImageFileHolder} is null!");
|
||||||
if (!imageResizes.ContainsKey(outputResolution))
|
if (!imageResizes.ContainsKey(outputResolution))
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
int[] resize = imageResizes[outputResolution];
|
int[] resize = imageResizes[outputResolution];
|
||||||
int outputResolutionWidth = resize[_OutputResolutionWidthIndex];
|
int outputResolutionWidth = resize[_OutputResolutionWidthIndex];
|
||||||
int outputResolutionHeight = resize[_OutputResolutionHeightIndex];
|
int outputResolutionHeight = resize[_OutputResolutionHeightIndex];
|
||||||
int outputResolutionOrientation = resize[_OutputResolutionOrientationIndex];
|
int outputResolutionOrientation = resize[_OutputResolutionOrientationIndex];
|
||||||
results = SaveResizedSubfile(propertyHolder.ImageFileInfo.FullName, property, resize, fileInfo: null);
|
results = SaveResizedSubfile(propertyHolder.ImageFileHolder.FullName, property, resize, fileHolder: null);
|
||||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
|
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveResizedSubfile(string outputResolution, List<Tuple<string, DateTime>> subFileTuples, PropertyHolder propertyHolder, string original, A_Property property, Dictionary<string, int[]> imageResizes)
|
public void SaveResizedSubfile(string outputResolution, List<Tuple<string, DateTime>> subFileTuples, PropertyHolder propertyHolder, string original, A_Property property, Dictionary<string, int[]> imageResizes)
|
||||||
{
|
{
|
||||||
if (propertyHolder.ImageFileInfo is null)
|
if (propertyHolder.ImageFileHolder is null)
|
||||||
throw new Exception($"{propertyHolder.ImageFileInfo} is null!");
|
throw new Exception($"{propertyHolder.ImageFileHolder} is null!");
|
||||||
if (propertyHolder.ResizedFileInfo is null)
|
if (propertyHolder.ResizedFileHolder is null)
|
||||||
throw new Exception($"{propertyHolder.ResizedFileInfo} is null!");
|
throw new Exception($"{propertyHolder.ResizedFileHolder} is null!");
|
||||||
FileInfo fileInfo = propertyHolder.ResizedFileInfo;
|
FileHolder fileHolder = propertyHolder.ResizedFileHolder;
|
||||||
if (!imageResizes.ContainsKey(outputResolution))
|
if (!imageResizes.ContainsKey(outputResolution))
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
if (!fileInfo.Exists)
|
if (!fileHolder.Exists)
|
||||||
{
|
{
|
||||||
|
FileInfo fileInfo = new(fileHolder.FullName);
|
||||||
if (fileInfo.Directory?.Parent is null)
|
if (fileInfo.Directory?.Parent is null)
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
string parentCheck = Path.Combine(fileInfo.Directory.Parent.FullName, fileInfo.Name);
|
string parentCheck = Path.Combine(fileInfo.Directory.Parent.FullName, fileInfo.Name);
|
||||||
if (File.Exists(parentCheck))
|
if (File.Exists(parentCheck))
|
||||||
{
|
{
|
||||||
File.Move(parentCheck, fileInfo.FullName);
|
File.Move(parentCheck, fileInfo.FullName);
|
||||||
fileInfo.Refresh();
|
propertyHolder.SetResizedFileHolder(FileHolder.Refresh(fileHolder));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int[] resize = imageResizes[outputResolution];
|
int[] resize = imageResizes[outputResolution];
|
||||||
@ -327,9 +328,9 @@ public class C_Resize
|
|||||||
int[] originalCollection = imageResizes[original];
|
int[] originalCollection = imageResizes[original];
|
||||||
if (outputResolutionWidth == originalCollection[_OutputResolutionWidthIndex] && outputResolutionHeight == originalCollection[_OutputResolutionHeightIndex] && outputResolutionOrientation == originalCollection[_OutputResolutionOrientationIndex])
|
if (outputResolutionWidth == originalCollection[_OutputResolutionWidthIndex] && outputResolutionHeight == originalCollection[_OutputResolutionHeightIndex] && outputResolutionOrientation == originalCollection[_OutputResolutionOrientationIndex])
|
||||||
{
|
{
|
||||||
if (!fileInfo.Exists)
|
if (!fileHolder.Exists)
|
||||||
{
|
{
|
||||||
File.Copy(propertyHolder.ImageFileInfo.FullName, fileInfo.FullName);
|
File.Copy(propertyHolder.ImageFileHolder.FullName, fileHolder.FullName);
|
||||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
|
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -340,13 +341,13 @@ public class C_Resize
|
|||||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||||
if (_OverrideForResizeImages)
|
if (_OverrideForResizeImages)
|
||||||
check = true;
|
check = true;
|
||||||
else if (!fileInfo.Exists)
|
else if (!fileHolder.Exists)
|
||||||
check = true;
|
check = true;
|
||||||
else if (dateTimes.Any() && dateTimes.Max() > fileInfo.LastWriteTime)
|
else if (dateTimes.Any() && dateTimes.Max() > fileHolder.LastWriteTime)
|
||||||
check = true;
|
check = true;
|
||||||
if (check)
|
if (check)
|
||||||
{
|
{
|
||||||
_ = SaveResizedSubfile(propertyHolder.ImageFileInfo.FullName, property, resize, fileInfo);
|
_ = SaveResizedSubfile(propertyHolder.ImageFileHolder.FullName, property, resize, fileHolder);
|
||||||
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
|
subFileTuples.Add(new Tuple<string, DateTime>(nameof(C_Resize), DateTime.Now));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,18 +158,18 @@ public class UnitTestResize
|
|||||||
singletonDescription: "Resize dimensions for each resolution",
|
singletonDescription: "Resize dimensions for each resolution",
|
||||||
collectionDescription: string.Empty));
|
collectionDescription: string.Empty));
|
||||||
string sourceDirectoryFile = ".json";
|
string sourceDirectoryFile = ".json";
|
||||||
FileInfo fileInfo = new(Path.Combine(sourceDirectory, sourceFileName));
|
Property.Models.FileHolder fileHolder = new(Path.Combine(sourceDirectory, sourceFileName));
|
||||||
string relativePath = Property.Models.Stateless.IPath.GetRelativePath(fileInfo.FullName, length);
|
string relativePath = Property.Models.Stateless.IPath.GetRelativePath(fileHolder.FullName, length);
|
||||||
sourceDirectory = Path.Combine(aPropertySingletonDirectory, sourceDirectoryName);
|
sourceDirectory = Path.Combine(aPropertySingletonDirectory, sourceDirectoryName);
|
||||||
propertyHolder = new(g, sourceDirectory, sourceDirectoryFile, relativePath, r, fileInfo, property, false, false, null, null);
|
propertyHolder = new(g, sourceDirectory, sourceDirectoryFile, relativePath, r, fileHolder, property, false, false, null, null);
|
||||||
Assert.IsNotNull(propertyHolder.ImageFileInfo);
|
Assert.IsNotNull(propertyHolder.ImageFileHolder);
|
||||||
property = propertyLogic.GetProperty(propertyLogic.AngleBracketCollection[0], propertyHolder, subFileTuples, parseExceptions);
|
property = propertyLogic.GetProperty(propertyLogic.AngleBracketCollection[0], propertyHolder, subFileTuples, parseExceptions);
|
||||||
(int _, metadataCollection) = metadata.GetMetadataCollection(subFileTuples, parseExceptions, propertyHolder);
|
(int _, metadataCollection) = metadata.GetMetadataCollection(subFileTuples, parseExceptions, propertyHolder);
|
||||||
imageResizeKeyValuePairs = resize.GetResizeKeyValuePairs(subFileTuples, parseExceptions, original, metadataCollection, property, propertyHolder);
|
imageResizeKeyValuePairs = resize.GetResizeKeyValuePairs(subFileTuples, parseExceptions, original, metadataCollection, property, propertyHolder);
|
||||||
FileInfo resizedFileInfo = new(Path.Combine(resize.AngleBracketCollection[0].Replace("<>", "()"), Path.GetFileName(propertyHolder.ImageFileInfo.FullName)));
|
Property.Models.FileHolder resizedFileHolder = new(Path.Combine(resize.AngleBracketCollection[0].Replace("<>", "()"), Path.GetFileName(propertyHolder.ImageFileHolder.FullName)));
|
||||||
propertyHolder.SetResizedFileInfo(resizedFileInfo);
|
propertyHolder.SetResizedFileHolder(resizedFileHolder);
|
||||||
resize.SaveResizedSubfile(outputResolution, subFileTuples, propertyHolder, original, property, imageResizeKeyValuePairs);
|
resize.SaveResizedSubfile(outputResolution, subFileTuples, propertyHolder, original, property, imageResizeKeyValuePairs);
|
||||||
resizedFileInfo.Refresh();
|
propertyHolder.SetResizedFileHolder(Property.Models.FileHolder.Refresh(resizedFileHolder));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -221,20 +221,20 @@ public class UnitTestFace
|
|||||||
singletonDescription: "Resize dimensions for each resolution",
|
singletonDescription: "Resize dimensions for each resolution",
|
||||||
collectionDescription: string.Empty));
|
collectionDescription: string.Empty));
|
||||||
string sourceDirectoryFile = ".json";
|
string sourceDirectoryFile = ".json";
|
||||||
FileInfo fileInfo = new(Path.Combine(sourceDirectory, sourceFileName));
|
Property.Models.FileHolder fileHolder = new(Path.Combine(sourceDirectory, sourceFileName));
|
||||||
string relativePath = Property.Models.Stateless.IPath.GetRelativePath(fileInfo.FullName, length);
|
string relativePath = Property.Models.Stateless.IPath.GetRelativePath(fileHolder.FullName, length);
|
||||||
sourceDirectory = Path.Combine(aPropertySingletonDirectory, sourceDirectoryName);
|
sourceDirectory = Path.Combine(aPropertySingletonDirectory, sourceDirectoryName);
|
||||||
propertyHolder = new(g, sourceDirectory, sourceDirectoryFile, relativePath, r, fileInfo, property, false, false, null, null);
|
propertyHolder = new(g, sourceDirectory, sourceDirectoryFile, relativePath, r, fileHolder, property, false, false, null, null);
|
||||||
Assert.IsNotNull(propertyHolder.ImageFileInfo);
|
Assert.IsNotNull(propertyHolder.ImageFileHolder);
|
||||||
property = propertyLogic.GetProperty(propertyLogic.AngleBracketCollection[0], propertyHolder, subFileTuples, parseExceptions);
|
property = propertyLogic.GetProperty(propertyLogic.AngleBracketCollection[0], propertyHolder, subFileTuples, parseExceptions);
|
||||||
(int _, metadataCollection) = metadata.GetMetadataCollection(subFileTuples, parseExceptions, propertyHolder);
|
(int _, metadataCollection) = metadata.GetMetadataCollection(subFileTuples, parseExceptions, propertyHolder);
|
||||||
imageResizeKeyValuePairs = resize.GetResizeKeyValuePairs(subFileTuples, parseExceptions, original, metadataCollection, property, propertyHolder);
|
imageResizeKeyValuePairs = resize.GetResizeKeyValuePairs(subFileTuples, parseExceptions, original, metadataCollection, property, propertyHolder);
|
||||||
FileInfo resizedFileInfo = new(Path.Combine(resize.AngleBracketCollection[0].Replace("<>", "()"), Path.GetFileName(propertyHolder.ImageFileInfo.FullName)));
|
Property.Models.FileHolder resizedFileHolder = new(Path.Combine(resize.AngleBracketCollection[0].Replace("<>", "()"), Path.GetFileName(propertyHolder.ImageFileHolder.FullName)));
|
||||||
propertyHolder.SetResizedFileInfo(resizedFileInfo);
|
propertyHolder.SetResizedFileHolder(resizedFileHolder);
|
||||||
resize.SaveResizedSubfile(outputResolution, subFileTuples, propertyHolder, original, property, imageResizeKeyValuePairs);
|
resize.SaveResizedSubfile(outputResolution, subFileTuples, propertyHolder, original, property, imageResizeKeyValuePairs);
|
||||||
resizedFileInfo.Refresh();
|
propertyHolder.SetResizedFileHolder(Property.Models.FileHolder.Refresh(resizedFileHolder));
|
||||||
Assert.IsNotNull(propertyHolder.ResizedFileInfo);
|
Assert.IsNotNull(propertyHolder.ResizedFileHolder);
|
||||||
Image? image = FaceRecognition.LoadImageFile(propertyHolder.ResizedFileInfo.FullName);
|
Image? image = FaceRecognition.LoadImageFile(propertyHolder.ResizedFileHolder.FullName);
|
||||||
Assert.IsNotNull(image);
|
Assert.IsNotNull(image);
|
||||||
FaceRecognition faceRecognition = FaceRecognition.Create(modelParameter);
|
FaceRecognition faceRecognition = FaceRecognition.Create(modelParameter);
|
||||||
List<Location> locations = faceRecognition.FaceLocations(model, image, _Configuration.NumberOfTimesToUpsample.Value, sortByPixelPercentage: true);
|
List<Location> locations = faceRecognition.FaceLocations(model, image, _Configuration.NumberOfTimesToUpsample.Value, sortByPixelPercentage: true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user