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