Deleted Method Get

This commit is contained in:
Mike Phares 2022-11-03 20:43:32 -07:00
parent 569ee26c55
commit 6610565ce3
11 changed files with 207 additions and 213 deletions

View File

@ -162,7 +162,17 @@ public class Compare
}
if (_IsEnvironment.Development && propertyConfiguration.PopulatePropertyId)
throw new Exception("Copy keyValuePairs-####.json file");
(int j, int f, int t, Shared.Models.Container[] containers) = A_Property.Get(propertyConfiguration, propertyLogic);
(int j, int f, int t, Shared.Models.Container[] containers) = Property.Models.Stateless.Container.GetContainers(propertyConfiguration, propertyLogic);
if (propertyLogic.ExceptionsDirectories.Any())
throw new Exception();
if (propertyConfiguration.PopulatePropertyId && Shared.Models.Stateless.Methods.IProperty.Any(containers))
{
propertyLogic.SavePropertyParallelWork(ticks, containers);
if (appSettings.MaxDegreeOfParallelism < 2)
ticks = LogDelta(ticks, nameof(A_Property.SavePropertyParallelWork));
if (propertyLogic.ExceptionsDirectories.Any())
throw new Exception();
}
if (!isSilent)
{
_Log.Information("First pass completed");
@ -762,7 +772,7 @@ public class Compare
List<string> distinctDirectories = new();
List<KeyValuePair<int, int[]>> valueCollection = new();
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
propertyLogic.ParallelWork(ticks, containers, firstPass: false);
propertyLogic.SavePropertyParallelWork(ticks, containers);
if (propertyLogic.ExceptionsDirectories.Any())
throw new Exception();
foreach (Property.Models.DirectoryInfo group in directoryInfoCollection)
@ -834,7 +844,7 @@ public class Compare
List<KeyValuePair<int, int[]>> valueCollection = new();
(long Ticks, string FilteredSourceDirectoryFile, string PropertyDirectory, int PropertyId)[] collection;
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
propertyLogic.ParallelWork(ticks, containers, firstPass: false);
propertyLogic.SavePropertyParallelWork(ticks, containers);
if (propertyLogic.ExceptionsDirectories.Any())
throw new Exception();
foreach (Property.Models.DirectoryInfo group in directoryInfoCollection)

View File

@ -58,31 +58,21 @@ public class DateGroup
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
if (true || appSettings.MaxDegreeOfParallelism < 2)
ticks = LogDelta(ticks, nameof(Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories));
(int j, int f, int t, Shared.Models.Container[] containers) = A_Property.Get(propertyConfiguration, propertyLogic);
(int j, int f, int t, Shared.Models.Container[] containers) = Property.Models.Stateless.Container.GetContainers(propertyConfiguration, propertyLogic);
if (propertyLogic.ExceptionsDirectories.Any())
throw new Exception();
if (propertyConfiguration.PopulatePropertyId && (configuration.ByCreateDateShortcut.Value || configuration.ByHash.Value) && Shared.Models.Stateless.Methods.IProperty.Any(containers))
{
propertyLogic.SavePropertyParallelWork(ticks, containers);
if (appSettings.MaxDegreeOfParallelism < 2)
ticks = LogDelta(ticks, nameof(A_Property.SavePropertyParallelWork));
if (propertyLogic.ExceptionsDirectories.Any())
throw new Exception();
}
if (configuration.ByCreateDateShortcut.HasValue && configuration.ByCreateDateShortcut.Value)
CreateDateShortcut(propertyConfiguration, containers);
else
{
List<string> topDirectories = new();
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
propertyLogic.ParallelWork(ticks, containers, firstPass: true);
if (appSettings.MaxDegreeOfParallelism < 2)
ticks = LogDelta(ticks, nameof(A_Property.ParallelWork));
if (propertyLogic.ExceptionsDirectories.Any())
throw new Exception();
if (propertyConfiguration.PopulatePropertyId && (configuration.ByCreateDateShortcut.Value || configuration.ByHash.Value))
{
if (Shared.Models.Stateless.Methods.IProperty.Any(containers))
propertyLogic.ParallelWork(ticks, containers, firstPass: false);
if (appSettings.MaxDegreeOfParallelism < 2)
ticks = LogDelta(ticks, nameof(A_Property.ParallelWork));
if (propertyLogic.ExceptionsDirectories.Any())
throw new Exception();
}
if ((from l in directoryInfoCollection where l.Moved.Any(a => a) select true).Any())
throw new Exception();
MoveFiles(topDirectories, directoryInfoCollection);
}
MoveFiles(propertyConfiguration, containers);
}
private static void Verify(Models.Configuration configuration)
@ -154,9 +144,9 @@ public class DateGroup
return result;
}
private List<(string Source, string[] Destination)> GetMoveFileCollection(string destinationDirectory, string topDirectory, Property.Models.DirectoryInfo group)
private List<(long MinimumDateTimeTicks, string Source, string[] Destination)> GetMoveFileCollection(string destinationDirectory, string topDirectory, Shared.Models.Item[] filteredItems)
{
List<(string Source, string[] Destination)> results = new();
List<(long MinimumDateTimeTicks, string Source, string[] Destination)> results = new();
if (_Configuration.ByCreateDateShortcut is null)
throw new NullReferenceException(nameof(_Configuration.ByCreateDateShortcut));
if (_Configuration.ByDay is null)
@ -179,21 +169,18 @@ public class DateGroup
string? pathRoot;
string seasonName;
string weekOfYear;
string? directory;
bool? isWrongYear;
string seasonValue;
string directoryName;
bool? propertyWrongYear;
string topDirectoryName;
string[]? matches = null;
string[] directorySegments;
Shared.Models.Property? property;
DateTime? minimumDateTime = null;
List<string> destinationCollection;
List<string> directoryNames = new();
List<string> topDirectorySegments = new();
StringBuilder destinationDirectoryName = new();
Calendar calendar = new CultureInfo("en-US").Calendar;
Shared.Models.FileHolder filteredSourceDirectoryFileHolder;
for (int z = 1; z < 3; z++)
{
if (z == 1)
@ -227,31 +214,26 @@ public class DateGroup
}
if (matches is null)
matches = Array.Empty<string>();
for (int i = 0; i < group.SourceDirectoryFileHolderCollection.Length; i++)
foreach (Shared.Models.Item item in filteredItems)
{
destinationCollection = new();
if (item.Property?.Id is null || item.ImageFileHolder is null)
continue;
directoryNames.Clear();
destinationCollection = new();
_ = destinationDirectoryName.Clear();
property = group.PropertyCollection[i];
if (property is null)
continue;
filteredSourceDirectoryFileHolder = group.SourceDirectoryFileHolderCollection[i];
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(property);
directory = filteredSourceDirectoryFileHolder.DirectoryName;
if (string.IsNullOrEmpty(directory))
continue;
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
day = minimumDateTime.Value.ToString("MM-dd");
month = minimumDateTime.Value.ToString("MMMM");
(propertyWrongYear, _) = property.IsWrongYear(filteredSourceDirectoryFileHolder.FullName, minimumDateTime);
if (propertyWrongYear is null)
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder, minimumDateTime);
if (isWrongYear is null)
flag = '#';
else
{
if (propertyWrongYear.Value)
if (isWrongYear.Value)
flag = '~';
else
{
if (property.DateTimeOriginal.HasValue && minimumDateTime.Value.DayOfYear != property.DateTimeOriginal.Value.DayOfYear && Math.Abs(new TimeSpan(minimumDateTime.Value.Ticks - property.DateTimeOriginal.Value.Ticks).TotalHours) > 8)
if (item.Property.DateTimeOriginal.HasValue && minimumDateTime.Value.DayOfYear != item.Property.DateTimeOriginal.Value.DayOfYear && Math.Abs(new TimeSpan(minimumDateTime.Value.Ticks - item.Property.DateTimeOriginal.Value.Ticks).TotalHours) > 8)
flag = '^';
else
flag = '=';
@ -262,7 +244,7 @@ public class DateGroup
seasonValue = string.Empty;
else
seasonValue = $".{season}";
if (propertyWrongYear is null || !propertyWrongYear.Value)
if (isWrongYear is null || !isWrongYear.Value)
year = $"{flag}{minimumDateTime.Value:yyyy}{seasonValue}";
else
{
@ -310,14 +292,14 @@ public class DateGroup
throw new Exception();
}
}
if (!_Configuration.ByHash.Value || property.Id is null)
fileName = filteredSourceDirectoryFileHolder.Name;
if (!_Configuration.ByHash.Value || item.Property.Id is null)
fileName = item.ImageFileHolder.Name;
else
fileName = $"{property.Id.Value}{filteredSourceDirectoryFileHolder.ExtensionLowered}";
fileName = $"{item.Property.Id.Value}{item.ImageFileHolder.ExtensionLowered}";
destinationCollection.Add(destinationDirectory);
destinationCollection.AddRange(directoryNames);
destinationCollection.Add(fileName);
results.Add(new(filteredSourceDirectoryFileHolder.FullName, destinationCollection.ToArray()));
results.Add(new(minimumDateTime.Value.Ticks, item.ImageFileHolder.FullName, destinationCollection.ToArray()));
}
return results;
}
@ -331,30 +313,42 @@ public class DateGroup
return result;
}
private List<(string Source, string[] Destination)> GetFileMoveCollectionAll(List<string> topDirectories, List<Property.Models.DirectoryInfo> groupCollection)
private static Shared.Models.Item[] GetFilterItems(Shared.Models.Container container)
{
List<(string Source, string[] Destination)> results = new();
List<Shared.Models.Item> results = new();
foreach (Shared.Models.Item item in container.Items)
{
if (item.ImageFileHolder is not null
&& (item.Abandoned is null || !item.Abandoned.Value)
&& item.ValidImageFormatExtension)
results.Add(item);
}
return results.ToArray();
}
private (long MinimumDateTimeTicks, string Source, string[] Destination)[] GetFileMoveCollectionAll(Property.Models.Configuration configuration, Shared.Models.Container[] containers, string destinationRoot)
{
(long MinimumDateTimeTicks, string Source, string[] Destination)[] results;
if (_Configuration.KeepFullPath is null)
throw new NullReferenceException(nameof(_Configuration.KeepFullPath));
if (_Configuration?.PropertyConfiguration is null)
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
string? topDirectory;
string? checkDirectory;
string sourceDirectory;
string destinationDirectory;
string destinationRoot = Property.Models.Stateless.IResult.GetResultsGroupDirectory(_Configuration.PropertyConfiguration, "Z) Moved");
List<(string Source, string[] Destination)> fileMoveCollectionDirectory;
foreach (Property.Models.DirectoryInfo group in groupCollection)
Shared.Models.Item[] filteredItems;
List<(long MinimumDateTimeTicks, string Source, string[] Destination)> fileMoveCollection = new();
List<(long MinimumDateTimeTicks, string Source, string[] Destination)> fileMoveCollectionDirectory;
foreach (Shared.Models.Container container in containers)
{
sourceDirectory = group.SourceDirectory;
if (!container.Items.Any())
continue;
if (!_Configuration.KeepFullPath.Value)
destinationDirectory = destinationRoot;
else
destinationDirectory = string.Concat(destinationRoot, sourceDirectory[_Configuration.PropertyConfiguration.RootDirectory.Length..]);
checkDirectory = Path.GetFullPath(sourceDirectory);
destinationDirectory = string.Concat(destinationRoot, container.SourceDirectory[configuration.RootDirectory.Length..]);
checkDirectory = Path.GetFullPath(container.SourceDirectory);
for (int z = 0; z < int.MaxValue; z++)
{
if (checkDirectory == _Configuration.PropertyConfiguration.RootDirectory || topDirectories.Contains(checkDirectory))
if (checkDirectory == configuration.RootDirectory)
break;
checkDirectory = Path.GetDirectoryName(checkDirectory);
if (string.IsNullOrEmpty(checkDirectory))
@ -363,22 +357,28 @@ public class DateGroup
if (string.IsNullOrEmpty(checkDirectory))
continue;
topDirectory = checkDirectory;
fileMoveCollectionDirectory = GetMoveFileCollection(destinationDirectory, topDirectory, group);
results.AddRange(fileMoveCollectionDirectory);
filteredItems = GetFilterItems(container);
if (!filteredItems.Any())
continue;
fileMoveCollectionDirectory = GetMoveFileCollection(destinationDirectory, topDirectory, filteredItems);
fileMoveCollection.AddRange(fileMoveCollectionDirectory);
}
results = (from l in fileMoveCollection orderby l.MinimumDateTimeTicks descending select l).ToArray();
return results;
}
private void MoveFiles(List<string> topDirectories, List<Property.Models.DirectoryInfo> groupCollection)
private void MoveFiles(Property.Models.Configuration configuration, Shared.Models.Container[] containers)
{
if (_Log is null)
throw new NullReferenceException(nameof(_Log));
if (_Configuration?.PropertyConfiguration is null)
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
if (_Configuration.ByHash is null)
throw new NullReferenceException(nameof(_Configuration.ByHash));
string directoryName;
List<string> distinct = new();
List<(string Source, string[] Destination)> fileMoveCollectionAll = GetFileMoveCollectionAll(topDirectories, groupCollection);
foreach ((string source, string[] destination) in fileMoveCollectionAll)
string duplicate = "-Duplicate";
string destinationRoot = Property.Models.Stateless.IResult.GetResultsGroupDirectory(configuration, "Z) Moved");
(long MinimumDateTimeTicks, string Source, string[] Destination)[] fileMoveCollectionAll = GetFileMoveCollectionAll(configuration, containers, destinationRoot);
foreach ((long _, string source, string[] destination) in fileMoveCollectionAll)
{
directoryName = Path.Combine(destination.Take(destination.Length - 1).ToArray());
if (distinct.Contains(directoryName))
@ -386,44 +386,63 @@ public class DateGroup
distinct.Add(directoryName);
if (!Directory.Exists(directoryName))
_ = Directory.CreateDirectory(directoryName);
if (_Configuration.ByHash.Value)
{
if (!Directory.Exists(string.Concat(directoryName, duplicate)))
_ = Directory.CreateDirectory(string.Concat(directoryName, duplicate));
}
}
_Log.Information("Ready to move files?");
for (int y = 0; y < int.MaxValue; y++)
{
_Log.Information("Press \"Y\" key to move files back or close console to not move files");
_Log.Information("Press \"Y\" key to move file(s) or close console to not move files");
if (Console.ReadKey().Key == ConsoleKey.Y)
break;
}
_Log.Information(". . .");
int moved = 0;
string fullFileName;
foreach ((string source, string[] destination) in fileMoveCollectionAll)
foreach ((long _, string source, string[] destination) in fileMoveCollectionAll)
{
fullFileName = Path.Combine(destination);
if (File.Exists(fullFileName))
{
if (!_Configuration.ByHash.Value)
continue;
else
{
destination[1] = string.Concat(destination[1], duplicate);
fullFileName = Path.Combine(destination);
if (File.Exists(fullFileName))
continue;
}
}
File.Move(source, fullFileName);
moved += 1;
}
if (_Configuration.ByHash.Value)
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(destinationRoot);
_Log.Information($"{moved} file(s) moved");
for (int y = 0; y < int.MaxValue; y++)
{
_Log.Information("Press \"Y\" key to move files back or close console to leave them moved");
_Log.Information("Press \"Y\" key to move file(s) back or close console to leave them moved");
if (Console.ReadKey().Key == ConsoleKey.Y)
break;
}
_Log.Information(". . .");
foreach ((string source, string[] destination) in fileMoveCollectionAll)
foreach ((long _, string source, string[] destination) in fileMoveCollectionAll)
{
fullFileName = Path.Combine(destination);
if (File.Exists(source))
continue;
if (!File.Exists(fullFileName))
continue;
File.Move(fullFileName, source);
moved += 1;
}
_Log.Information($"Done moving back {moved} file(s)");
for (int i = 1; i < 10; i++)
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(_Configuration.PropertyConfiguration.RootDirectory);
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(configuration.RootDirectory);
}
private static void CreateDateShortcut(Property.Models.Configuration configuration, Shared.Models.Container[] containers)
@ -433,13 +452,13 @@ public class DateGroup
string directory;
int selectedTotal;
const int minimum = 3;
List<Shared.Models.Item> selectedItems;
List<DateTime> dateTimes;
DateTime? minimumDateTime;
const int maximumHours = 24;
string? relativePathDirectory;
WindowsShortcut windowsShortcut;
TimeSpan threeStandardDeviationHigh;
List<Shared.Models.Item> selectedItems;
string aPropertyContentDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "()");
foreach (Shared.Models.Container container in containers)
{

View File

@ -74,12 +74,11 @@ public partial class Form : System.Windows.Forms.Form
int f;
int t;
AllowDrop = true;
bool firstRun = false;
Container[] containers;
DragDrop += new DragEventHandler(Form1_DragDrop);
DragEnter += new DragEventHandler(Form1_DragEnter);
Property.Models.A_Property propertyLogic = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, _ResizeFileNameExtension, _Configuration.Reverse);
(j, f, t, containers) = Property.Models.Stateless.Container.GetContainers(_Configuration.PropertyConfiguration, firstRun, propertyLogic);
(j, f, t, containers) = Property.Models.Stateless.Container.GetContainers(_Configuration.PropertyConfiguration, propertyLogic);
List<MappingFromItem> collection = Program.GetMappingFromItemCollection(_Configuration, containers);
foreach (MappingFromItem mappingFromItem in collection)
{

View File

@ -68,7 +68,7 @@ static class Program
if (item.Property?.Id is null || item.ImageFileHolder is null)
continue;
minimumDateTime = IProperty.GetMinimumDateTime(item.Property);
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder.FullName, minimumDateTime);
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder, minimumDateTime);
mappingFromItem = new(item.Property.Id.Value, item.ImageFileHolder, isWrongYear, minimumDateTime, item.RelativePath, item.ImageFileHolder);
results.Add(mappingFromItem);
}

View File

@ -20,7 +20,6 @@ public partial class DlibDotNet
{
private readonly D_Face _Faces;
private readonly bool _FirstRun;
private readonly G_Index _Index;
private readonly C_Resize _Resize;
private readonly F_Random _Random;
@ -33,6 +32,7 @@ public partial class DlibDotNet
private readonly AppSettings _AppSettings;
private readonly List<string> _Exceptions;
private readonly IsEnvironment _IsEnvironment;
private readonly bool _PropertyRootExistedBefore;
private readonly Models.Configuration _Configuration;
private readonly bool _ArgZeroIsConfigurationRootDirectory;
private readonly Map.Models.Configuration _MapConfiguration;
@ -68,7 +68,7 @@ public partial class DlibDotNet
if (configuration.IgnoreExtensions is null)
throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
string propertyRoot = Property.Models.Stateless.IResult.GetResultsGroupDirectory(propertyConfiguration, nameof(A_Property), create: false);
_FirstRun = !Directory.Exists(propertyRoot);
_PropertyRootExistedBefore = !Directory.Exists(propertyRoot);
argZero = args.Count > 0 ? Path.GetFullPath(args[0]) : Path.GetFullPath(propertyConfiguration.RootDirectory);
_ArgZeroIsConfigurationRootDirectory = propertyConfiguration.RootDirectory == argZero;
_Log.Information(configuration.ModelDirectory);
@ -103,7 +103,7 @@ public partial class DlibDotNet
_Metadata = new(configuration.ForceMetadataLastWriteTimeToCreationTime, configuration.PropertiesChangedForMetadata);
_MapConfiguration = Get(configuration, _Faces.FileNameExtension, _Faces.HiddenFileNameExtension, _FaceParts.FileNameExtension);
_Distance = new(configuration.DistanceMoveUnableToMatch, configuration.DistancePixelDistanceTolerance, configuration.DistanceRenameToMatch, _Configuration.FaceConfidencePercent, configuration.RangeDistanceTolerance, configuration.RangeFaceConfidence);
if (_FirstRun || !_ArgZeroIsConfigurationRootDirectory)
if (_PropertyRootExistedBefore || !_ArgZeroIsConfigurationRootDirectory)
personContainers = Array.Empty<PersonContainer>();
else
{
@ -141,7 +141,7 @@ public partial class DlibDotNet
}
if (!configuration.SkipSearch)
Search(ticks, argZero, propertyRoot, personContainers);
if (!_FirstRun && !_IsEnvironment.Development && _Exceptions.Count == 0 && _ArgZeroIsConfigurationRootDirectory)
if (!_PropertyRootExistedBefore && !_IsEnvironment.Development && _Exceptions.Count == 0 && _ArgZeroIsConfigurationRootDirectory)
{
List<string[]> directoryCollections = _Rename.GetDirectoryRenameCollections(
propertyConfiguration,
@ -163,7 +163,7 @@ public partial class DlibDotNet
_Log.Information(message);
if (_Exceptions.Count != 0)
throw new Exception(message);
if (_FirstRun)
if (_PropertyRootExistedBefore)
_Log.Information("First run completed. Run again if wanted");
}
@ -288,7 +288,7 @@ public partial class DlibDotNet
if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null)
throw new NotSupportedException();
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder.FullName, minimumDateTime);
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder, minimumDateTime);
result = new(item.Property.Id.Value, item.ImageFileHolder, isWrongYear, minimumDateTime, item.RelativePath, item.ResizedFileHolder);
return result;
}
@ -811,7 +811,7 @@ public partial class DlibDotNet
continue;
}
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder.FullName, minimumDateTime);
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder, minimumDateTime);
mappingFromItem = new(item.Property.Id.Value, item.ImageFileHolder, isWrongYear, minimumDateTime, item.RelativePath, item.ResizedFileHolder);
foreach (Shared.Models.Face face in item.Faces)
{
@ -976,7 +976,7 @@ public partial class DlibDotNet
if (item.Property?.Id is null || item.ImageFileHolder is null)
continue;
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder.FullName, minimumDateTime);
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder, minimumDateTime);
mappingFromItem = new(item.Property.Id.Value, item.ImageFileHolder, isWrongYear, minimumDateTime, item.RelativePath, item.ImageFileHolder);
results.Add(mappingFromItem);
}
@ -1005,7 +1005,7 @@ public partial class DlibDotNet
using (ProgressBar progressBar = new(1, message, options))
{
progressBar.Tick();
(j, f, t, containers) = Property.Models.Stateless.Container.GetContainers(_Configuration.PropertyConfiguration, _FirstRun, propertyLogic);
(j, f, t, containers) = Property.Models.Stateless.Container.GetContainers(_Configuration.PropertyConfiguration, propertyLogic);
}
Container? container = AreAllSameEndsWith(argZero, containers);
if (!_ArgZeroIsConfigurationRootDirectory || container is null)
@ -1030,7 +1030,7 @@ public partial class DlibDotNet
_Distance.Clear();
foreach (string outputResolution in _Configuration.OutputResolutions)
{
if (_FirstRun || container is not null)
if (_PropertyRootExistedBefore || container is not null)
break;
(aResultsFullGroupDirectory, bResultsFullGroupDirectory, cResultsFullGroupDirectory, dResultsFullGroupDirectory) = GetResultsFullGroupDirectories(outputResolution);
if (_ArgZeroIsConfigurationRootDirectory

View File

@ -36,9 +36,9 @@ public class NotCopyCopy
throw new Exception("This program only allows development environments!");
A_Property propertyLogic = GetPropertyLogic(reverse, outputExtension);
propertyConfiguration.ChangeRootDirectory(configuration.CompareSource);
(_, _, _, Shared.Models.Container[] compareContainers) = A_Property.Get(propertyConfiguration, propertyLogic);
(_, _, _, Shared.Models.Container[] compareContainers) = Property.Models.Stateless.Container.GetContainers(propertyConfiguration, propertyLogic);
propertyConfiguration.ChangeRootDirectory(configuration.SelectedSource);
(_, _, _, Shared.Models.Container[] selectedContainers) = A_Property.Get(propertyConfiguration, propertyLogic);
(_, _, _, Shared.Models.Container[] selectedContainers) = Property.Models.Stateless.Container.GetContainers(propertyConfiguration, propertyLogic);
if (compareContainers.Length == selectedContainers.Length)
throw new Exception();
string directoryName;

View File

@ -97,15 +97,11 @@ public class A_Property
#pragma warning disable CA1416
private Shared.Models.Property GetImageProperty(IFileHolder filteredSourceDirectoryFileHolder, bool populateId, bool isIgnoreExtension, bool isValidImageFormatExtension, bool isValidMetadataExtensions, int? id, List<int> indices)
private Shared.Models.Property GetImageProperty(IFileHolder fileHolder, Shared.Models.Property? property, bool populateId, bool isIgnoreExtension, bool isValidImageFormatExtension, bool isValidMetadataExtensions, int? id, List<int> indices)
{
Shared.Models.Property result;
if (_Log is null)
throw new NullReferenceException(nameof(_Log));
if (filteredSourceDirectoryFileHolder.CreationTime is null)
throw new NullReferenceException(nameof(filteredSourceDirectoryFileHolder.CreationTime));
if (filteredSourceDirectoryFileHolder.LastWriteTime is null)
throw new NullReferenceException(nameof(filteredSourceDirectoryFileHolder.LastWriteTime));
long ticks;
byte[] bytes;
string value;
@ -123,18 +119,18 @@ public class A_Property
DateTime? dateTimeOriginal = null;
string orientation = string.Empty;
DateTime? dateTimeDigitized = null;
if (!isValidImageFormatExtension && isValidMetadataExtensions)
if (!isValidImageFormatExtension && isValidMetadataExtensions && fileHolder.Exists)
{
dateTimeFormat = "ddd MMM dd HH:mm:ss yyyy";
List<DateTime> dateTimes = GetMetadataDateTimesByPattern(dateTimeFormat, filteredSourceDirectoryFileHolder);
List<DateTime> dateTimes = GetMetadataDateTimesByPattern(dateTimeFormat, fileHolder);
if (dateTimes.Any())
dateTimeOriginal = dateTimes.Min();
}
else if (!isIgnoreExtension && isValidImageFormatExtension)
else if (!isIgnoreExtension && isValidImageFormatExtension && fileHolder.Exists)
{
try
{
using Image image = Image.FromFile(filteredSourceDirectoryFileHolder.FullName);
using Image image = Image.FromFile(fileHolder.FullName);
if (populateId && (id is null || !indices.Any()))
{
using Bitmap bitmap = new(image);
@ -155,7 +151,7 @@ public class A_Property
}
if (_Configuration.WriteBitmapDataBytes)
{
FileInfo contentFileInfo = new(Path.Combine(angleBracket.Replace("<>", "()"), filteredSourceDirectoryFileHolder.Name));
FileInfo contentFileInfo = new(Path.Combine(angleBracket.Replace("<>", "()"), fileHolder.Name));
File.WriteAllBytes(Path.ChangeExtension(contentFileInfo.FullName, string.Empty), bytes);
}
ticks = DateTime.Now.Ticks;
@ -247,22 +243,31 @@ public class A_Property
}
catch (Exception)
{
_Log.Info(string.Concat(new StackFrame().GetMethod()?.Name, " <", filteredSourceDirectoryFileHolder.Name, ">"));
_Log.Info(string.Concat(new StackFrame().GetMethod()?.Name, " <", fileHolder.Name, ">"));
}
}
else
dateTimeOriginal = null;
if (filteredSourceDirectoryFileHolder.Length is null)
if (fileHolder.Length is null)
fileLength = 0;
else
fileLength = filteredSourceDirectoryFileHolder.Length.Value;
result = new(filteredSourceDirectoryFileHolder.CreationTime.Value, dateTime, dateTimeDigitized, dateTimeOriginal, fileLength, gpsDateStamp, height, id, indices.ToArray(), filteredSourceDirectoryFileHolder.LastWriteTime.Value, make, model, orientation, width);
fileLength = fileHolder.Length.Value;
if (fileHolder.CreationTime is null && property?.CreationTime is null)
throw new NullReferenceException(nameof(fileHolder.CreationTime));
if (fileHolder.LastWriteTime is null && property?.LastWriteTime is null)
throw new NullReferenceException(nameof(fileHolder.LastWriteTime));
if (fileHolder.CreationTime is not null && fileHolder.LastWriteTime is not null)
result = new(fileHolder.CreationTime.Value, dateTime, dateTimeDigitized, dateTimeOriginal, fileLength, gpsDateStamp, height, id, indices.ToArray(), fileHolder.LastWriteTime.Value, make, model, orientation, width);
else if (property is not null)
result = new(property.CreationTime, dateTime, dateTimeDigitized, dateTimeOriginal, fileLength, gpsDateStamp, height, id, indices.ToArray(), property.LastWriteTime, make, model, orientation, width);
else
throw new NullReferenceException(nameof(property));
return result;
}
#pragma warning restore CA1416
private Shared.Models.Property GetPropertyOfPrivate(Item item, bool firstPass, List<Tuple<string, DateTime>> filteredSourceDirectoryFileTuples, List<string> parseExceptions, bool isIgnoreExtension, bool isValidMetadataExtensions)
private Shared.Models.Property GetPropertyOfPrivate(Item item, List<Tuple<string, DateTime>> sourceDirectoryFileTuples, List<string> parseExceptions, bool isIgnoreExtension, bool isValidMetadataExtensions)
{
Shared.Models.Property? result;
if (item.ImageFileHolder is null)
@ -271,9 +276,10 @@ public class A_Property
int? id = null;
List<int> indices = new();
bool hasWrongYearProperty = false;
Shared.Models.Property? property = null;
string[] changesFrom = Array.Empty<string>();
string angleBracket = AngleBracketCollection[0];
bool populateId = !firstPass && _Configuration.PopulatePropertyId;
bool populateId = _Configuration.PopulatePropertyId;
string without = Path.Combine(angleBracket.Replace("<>", "{}"), $"{item.ImageFileHolder.NameWithoutExtension}.json");
FileInfo fileInfo = new(Path.Combine(angleBracket.Replace("<>", "{}"), $"{item.ImageFileHolder.NameWithoutExtension}{item.ImageFileHolder.ExtensionLowered}.json"));
if (item.ValidImageFormatExtension && File.Exists(without))
@ -281,7 +287,7 @@ public class A_Property
File.Move(without, fileInfo.FullName);
fileInfo.Refresh();
}
List<DateTime> dateTimes = (from l in filteredSourceDirectoryFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
List<DateTime> dateTimes = (from l in sourceDirectoryFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
if (!fileInfo.Exists)
{
if (fileInfo.Directory?.Parent is null)
@ -319,14 +325,14 @@ public class A_Property
if (item.ImageFileHolder is null)
throw new NullReferenceException(nameof(item.ImageFileHolder));
bool check = true;
Shared.Models.Property? property = JsonSerializer.Deserialize<Shared.Models.Property>(json);
property = JsonSerializer.Deserialize<Shared.Models.Property>(json);
if (!isIgnoreExtension && item.ValidImageFormatExtension && ((populateId && property?.Id is null) || property?.Width is null || property?.Height is null))
{
check = false;
id = property?.Id;
if (property is not null && property.Indices.Any())
indices = property.Indices.ToList();
property = GetImageProperty(item.ImageFileHolder, populateId, isIgnoreExtension, item.ValidImageFormatExtension, isValidMetadataExtensions, id, indices);
property = GetImageProperty(item.ImageFileHolder, property, populateId, isIgnoreExtension, item.ValidImageFormatExtension, isValidMetadataExtensions, id, indices);
}
if (!isIgnoreExtension && item.ValidImageFormatExtension && populateId && property is not null && !property.Indices.Any())
{
@ -334,14 +340,14 @@ public class A_Property
id = property?.Id;
if (property is not null && property.Indices.Any())
indices = property.Indices.ToList();
property = GetImageProperty(item.ImageFileHolder, populateId, isIgnoreExtension, item.ValidImageFormatExtension, isValidMetadataExtensions, id, indices);
property = GetImageProperty(item.ImageFileHolder, property, populateId, isIgnoreExtension, item.ValidImageFormatExtension, isValidMetadataExtensions, id, indices);
}
if (!isIgnoreExtension && item.ValidImageFormatExtension && populateId && property is not null && property.LastWriteTime != item.ImageFileHolder.LastWriteTime)
{
check = false;
id = null;
indices.Clear();
property = GetImageProperty(item.ImageFileHolder, populateId, isIgnoreExtension, item.ValidImageFormatExtension, isValidMetadataExtensions, id, indices);
property = GetImageProperty(item.ImageFileHolder, property, populateId, isIgnoreExtension, item.ValidImageFormatExtension, isValidMetadataExtensions, id, indices);
}
if (!isIgnoreExtension && item.ValidImageFormatExtension && property?.Width is not null && property?.Height is not null && property.Width.Value == property.Height.Value && item.ImageFileHolder.Exists)
{
@ -349,7 +355,7 @@ public class A_Property
id = property?.Id;
if (property is not null && property.Indices.Any())
indices = property.Indices.ToList();
property = GetImageProperty(item.ImageFileHolder, populateId, isIgnoreExtension, item.ValidImageFormatExtension, isValidMetadataExtensions, id, indices);
property = GetImageProperty(item.ImageFileHolder, property, populateId, isIgnoreExtension, item.ValidImageFormatExtension, 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!");
}
@ -372,7 +378,7 @@ public class A_Property
else
{
result = property;
filteredSourceDirectoryFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), fileInfo.LastWriteTime));
sourceDirectoryFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), fileInfo.LastWriteTime));
}
}
catch (Exception)
@ -385,17 +391,17 @@ public class A_Property
{
if (item.ImageFileHolder is null)
throw new NullReferenceException(nameof(item.ImageFileHolder));
result = GetImageProperty(item.ImageFileHolder, populateId, isIgnoreExtension, item.ValidImageFormatExtension, isValidMetadataExtensions, id, indices);
result = GetImageProperty(item.ImageFileHolder, property, populateId, isIgnoreExtension, item.ValidImageFormatExtension, isValidMetadataExtensions, id, indices);
json = JsonSerializer.Serialize(result, _WriteIndentedJsonSerializerOptions);
if (populateId && Shared.Models.Stateless.Methods.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches: true, compareBeforeWrite: true))
{
if (!_Configuration.ForcePropertyLastWriteTimeToCreationTime && (!fileInfo.Exists || fileInfo.LastWriteTime == fileInfo.CreationTime))
filteredSourceDirectoryFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), DateTime.Now));
sourceDirectoryFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), DateTime.Now));
else
{
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
fileInfo.Refresh();
filteredSourceDirectoryFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), fileInfo.CreationTime));
sourceDirectoryFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), fileInfo.CreationTime));
}
}
}
@ -406,13 +412,13 @@ public class A_Property
{
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
fileInfo.Refresh();
filteredSourceDirectoryFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), fileInfo.CreationTime));
sourceDirectoryFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), fileInfo.CreationTime));
}
}
return result;
}
private bool AnyFilesMoved(string sourceDirectory, Item[] filteredItems)
private bool AnyFilesMoved(string sourceDirectory, List<Item> items)
{
bool result = false;
if (_Log is null)
@ -428,16 +434,16 @@ public class A_Property
string destinationDirectory;
string[] sourceDirectorySegments;
DateTime directoryMaximumOfMinimumDateTime = DateTime.MinValue;
foreach (Item filteredItem in filteredItems)
foreach (Item item in items)
{
if (!filteredItem.ValidImageFormatExtension || filteredItem.Property is null || filteredItem.ImageFileHolder is null)
if (!item.ValidImageFormatExtension || item.Property is null || item.ImageFileHolder is null || !item.ImageFileHolder.Exists)
continue;
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(filteredItem.Property);
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
if (minimumDateTime > directoryMaximumOfMinimumDateTime)
directoryMaximumOfMinimumDateTime = minimumDateTime;
if (minimumDateTime != filteredItem.ImageFileHolder.CreationTime)
if (minimumDateTime != item.ImageFileHolder.CreationTime)
{
(isWrongYear, matches) = Shared.Models.Stateless.Methods.IProperty.IsWrongYear(filteredItem.ImageFileHolder.FullName, minimumDateTime);
(isWrongYear, matches) = item.Property.IsWrongYear(item.ImageFileHolder, minimumDateTime);
if (isWrongYear is null || !isWrongYear.Value)
dateTime = minimumDateTime;
else
@ -448,20 +454,20 @@ public class A_Property
continue;
}
try
{ File.SetCreationTime(filteredItem.ImageFileHolder.FullName, dateTime); }
{ File.SetCreationTime(item.ImageFileHolder.FullName, dateTime); }
catch (Exception)
{ }
}
if (!_VerifyToSeason.Contains(sourceDirectory))
continue;
if (!filteredItem.ImageFileHolder.FullName.Contains("zzz ") && !filteredItem.ImageFileHolder.FullName.Contains("Camera ") && filteredItem.Property.DateTimeOriginal.HasValue)
if (!item.ImageFileHolder.FullName.Contains("zzz ") && !item.ImageFileHolder.FullName.Contains("Camera ") && item.Property.DateTimeOriginal.HasValue)
{
TimeSpan timeSpan = new(filteredItem.Property.DateTimeOriginal.Value.Ticks - filteredItem.Property.LastWriteTime.Ticks);
if (timeSpan.TotalHours > 6)
TimeSpan timeSpan = new(item.Property.DateTimeOriginal.Value.Ticks - item.Property.LastWriteTime.Ticks);
if (timeSpan.TotalHours > 7.2f)
{
_Log.Warning($"*** propertyHolder.FileInfo.FullName <{filteredItem.ImageFileHolder.FullName}>");
_Log.Warning($"*** DateTimeOriginal <{filteredItem.Property.DateTimeOriginal.Value}>");
_Log.Warning($"*** LastWriteTime <{filteredItem.Property.LastWriteTime}>");
_Log.Warning($"*** propertyHolder.FileInfo.FullName <{item.ImageFileHolder.FullName}>");
_Log.Warning($"*** DateTimeOriginal <{item.Property.DateTimeOriginal.Value}>");
_Log.Warning($"*** LastWriteTime <{item.Property.LastWriteTime}>");
_Log.Warning($"*** TotalHours <{timeSpan.TotalHours}>");
}
}
@ -475,44 +481,32 @@ public class A_Property
destinationDirectory = Path.Combine(_Configuration.RootDirectory, $"={minimumDateTime:yyyy}.{season} {seasonName}");
if (destinationDirectory == sourceDirectory)
continue;
lock (filteredItem)
filteredItem.SetMoved(true);
lock (item)
item.SetMoved(true);
if (!result)
result = true;
if (!Directory.Exists(destinationDirectory))
_ = Directory.CreateDirectory(destinationDirectory);
destinationFile = Path.Combine(destinationDirectory, filteredItem.ImageFileHolder.Name);
destinationFile = Path.Combine(destinationDirectory, item.ImageFileHolder.Name);
if (File.Exists(destinationFile))
{
if (_OutputExtension is not ".jpg" and not ".jpeg")
throw new Exception();
if (destinationFile.EndsWith(".jpg", ignoreCase: true, CultureInfo.CurrentCulture))
destinationFile = Path.Combine(destinationDirectory, Path.ChangeExtension(filteredItem.ImageFileHolder.Name, ".jpeg"));
destinationFile = Path.Combine(destinationDirectory, Path.ChangeExtension(item.ImageFileHolder.Name, ".jpeg"));
else if (destinationFile.EndsWith(".jpeg", ignoreCase: true, CultureInfo.CurrentCulture))
destinationFile = Path.Combine(destinationDirectory, Path.ChangeExtension(filteredItem.ImageFileHolder.Name, ".jpg"));
destinationFile = Path.Combine(destinationDirectory, Path.ChangeExtension(item.ImageFileHolder.Name, ".jpg"));
}
if (File.Exists(destinationFile))
{
_Log.Information($"*** source <{filteredItem.ImageFileHolder.FullName}>");
_Log.Information($"*** source <{item.ImageFileHolder.FullName}>");
_Log.Information($"*** destination <{destinationFile}>");
if (filteredItem.ImageFileHolder.Exists)
{
deleteFile = Path.ChangeExtension(filteredItem.ImageFileHolder.FullName, ".delete");
if (File.Exists(deleteFile))
File.Delete(deleteFile);
File.Move(filteredItem.ImageFileHolder.FullName, deleteFile);
}
}
if (!File.Exists(destinationFile))
File.Move(item.ImageFileHolder.FullName, destinationFile);
else
{
File.Move(filteredItem.ImageFileHolder.FullName, destinationFile);
if (filteredItem.ImageFileHolder.Exists)
{
deleteFile = Path.ChangeExtension(filteredItem.ImageFileHolder.FullName, ".delete");
deleteFile = Path.ChangeExtension(item.ImageFileHolder.FullName, ".delete");
if (File.Exists(deleteFile))
File.Delete(deleteFile);
File.Move(filteredItem.ImageFileHolder.FullName, deleteFile);
}
File.Move(item.ImageFileHolder.FullName, destinationFile);
}
}
if (directoryMaximumOfMinimumDateTime != DateTime.MinValue)
@ -524,7 +518,7 @@ public class A_Property
return result;
}
private void ParallelForWork(bool firstPass, string sourceDirectory, List<Tuple<string, DateTime>> filteredSourceDirectoryFileTuples, List<Tuple<string, DateTime>> sourceDirectoryChanges, Item item)
private void SavePropertyParallelForWork(string sourceDirectory, List<Tuple<string, DateTime>> sourceDirectoryFileTuples, List<Tuple<string, DateTime>> sourceDirectoryChanges, Item item)
{
if (item.ImageFileHolder is null)
throw new NullReferenceException(nameof(item.ImageFileHolder));
@ -537,7 +531,7 @@ public class A_Property
File.Move(item.ImageFileHolder.FullName, filteredSourceDirectoryFileExtensionLowered);
if (item.Changed is null || item.Changed.Value || item.Property is null)
{
property = GetPropertyOfPrivate(item, firstPass, filteredSourceDirectoryFileTuples, parseExceptions, isIgnoreExtension, isValidMetadataExtensions);
property = GetPropertyOfPrivate(item, sourceDirectoryFileTuples, parseExceptions, isIgnoreExtension, isValidMetadataExtensions);
lock (sourceDirectoryChanges)
sourceDirectoryChanges.Add(new Tuple<string, DateTime>(nameof(A_Property), DateTime.Now));
lock (item)
@ -545,24 +539,24 @@ public class A_Property
}
}
private void ParallelWork(bool firstPass, List<Exception> exceptions, List<Tuple<string, DateTime>> sourceDirectoryChanges, Shared.Models.Container container, Item[] filteredItems, string message)
private void SavePropertyParallelWork(List<Exception> exceptions, List<Tuple<string, DateTime>> sourceDirectoryChanges, Shared.Models.Container container, List<Item> items, string message)
{
List<Tuple<string, DateTime>> filteredSourceDirectoryFileTuples = new();
List<Tuple<string, DateTime>> sourceDirectoryFileTuples = new();
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = _MaxDegreeOfParallelism };
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
using ProgressBar progressBar = new(filteredItems.Length, message, options);
_ = Parallel.For(0, filteredItems.Length, parallelOptions, (i, state) =>
using ProgressBar progressBar = new(items.Count, message, options);
_ = Parallel.For(0, items.Count, parallelOptions, (i, state) =>
{
try
{
long ticks = DateTime.Now.Ticks;
DateTime dateTime = DateTime.Now;
List<Tuple<string, DateTime>> collection;
ParallelForWork(firstPass, container.SourceDirectory, sourceDirectoryChanges, filteredSourceDirectoryFileTuples, filteredItems[i]);
SavePropertyParallelForWork(container.SourceDirectory, sourceDirectoryChanges, sourceDirectoryFileTuples, items[i]);
if (i == 0 || sourceDirectoryChanges.Any())
progressBar.Tick();
lock (filteredSourceDirectoryFileTuples)
collection = (from l in filteredSourceDirectoryFileTuples where l.Item2 > dateTime select l).ToList();
lock (sourceDirectoryFileTuples)
collection = (from l in sourceDirectoryFileTuples where l.Item2 > dateTime select l).ToList();
lock (sourceDirectoryChanges)
sourceDirectoryChanges.AddRange(collection);
}
@ -589,14 +583,13 @@ public class A_Property
collectionDescription: string.Empty));
}
public void ParallelWork(long ticks, Shared.Models.Container[] containers, bool firstPass)
public void SavePropertyParallelWork(long ticks, Shared.Models.Container[] containers)
{
if (_Log is null)
throw new NullReferenceException(nameof(_Log));
string message;
int totalSeconds;
bool? anyFilesMoved;
Item[] filteredItems;
Shared.Models.Container container;
List<Exception> exceptions = new();
int containersCount = containers.Length;
@ -608,26 +601,22 @@ public class A_Property
if (!container.Items.Any())
continue;
sourceDirectoryChanges.Clear();
if (firstPass)
filteredItems = (from l in container.Items where l.NoJson is null || !l.NoJson.Value && (l.Changed is null || l.Changed.Value) select l).ToArray();
else
filteredItems = (from l in container.Items where l.ImageFileHolder is not null && !_Configuration.IgnoreExtensions.Contains(l.ImageFileHolder.ExtensionLowered) select l).ToArray();
if (!filteredItems.Any())
if (!container.Items.Any())
continue;
SetAngleBracketCollection(container.SourceDirectory);
totalSeconds = (int)Math.Truncate(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
message = $"{i + 1:000}.{container.G} / {containersCount:000}) {filteredItems.Length:000} file(s) - {totalSeconds} total second(s) - {container.SourceDirectory}";
ParallelWork(firstPass, exceptions, sourceDirectoryChanges, container, filteredItems, message);
message = $"{i + 1:000}.{container.G} / {containersCount:000}) {container.Items.Count:000} file(s) - {totalSeconds} total second(s) - {container.SourceDirectory}";
SavePropertyParallelWork(exceptions, sourceDirectoryChanges, container, container.Items, message);
foreach (Exception exception in exceptions)
_Log.Error(string.Concat(container.SourceDirectory, Environment.NewLine, exception.Message, Environment.NewLine, exception.StackTrace), exception);
if (exceptions.Count == filteredItems.Length)
if (exceptions.Count == container.Items.Count)
throw new Exception(string.Concat("All in [", container.SourceDirectory, "]failed!"));
if (exceptions.Count != 0)
_ExceptionsDirectories.Add(container.SourceDirectory);
if (!firstPass || exceptions.Count != 0)
if (exceptions.Count != 0)
anyFilesMoved = null;
else
anyFilesMoved = AnyFilesMoved(container.SourceDirectory, filteredItems);
anyFilesMoved = AnyFilesMoved(container.SourceDirectory, container.Items);
if (Directory.GetFiles(propertyRoot, "*.txt", SearchOption.TopDirectoryOnly).Any())
{
for (int y = 0; y < int.MaxValue; y++)
@ -641,15 +630,14 @@ public class A_Property
}
}
public Shared.Models.Property GetProperty(Item item, List<Tuple<string, DateTime>> filteredSourceDirectoryFileTuples, List<string> parseExceptions)
public Shared.Models.Property GetProperty(Item item, List<Tuple<string, DateTime>> sourceDirectoryFileTuples, List<string> parseExceptions)
{
Shared.Models.Property result;
if (item.ImageFileHolder is null)
throw new NullReferenceException(nameof(item.ImageFileHolder));
bool firstPass = false;
bool isValidMetadataExtensions = _Configuration.ValidMetadataExtensions.Contains(item.ImageFileHolder.ExtensionLowered);
bool isIgnoreExtension = item.ValidImageFormatExtension && _Configuration.IgnoreExtensions.Contains(item.ImageFileHolder.ExtensionLowered);
result = GetPropertyOfPrivate(item, firstPass, filteredSourceDirectoryFileTuples, parseExceptions, isIgnoreExtension, isValidMetadataExtensions);
result = GetPropertyOfPrivate(item, sourceDirectoryFileTuples, parseExceptions, isIgnoreExtension, isValidMetadataExtensions);
return result;
}
@ -688,17 +676,4 @@ public class A_Property
return results.OrderBy(l => l.Ticks).ToArray();
}
public static (int, int, int, Shared.Models.Container[]) Get(Configuration configuration, A_Property propertyLogic)
{
Shared.Models.Container[] results;
bool firstRun = false;
long ticks = DateTime.Now.Ticks;
List<string> exceptionsDirectories = new();
(int j, int f, int t, results) = Stateless.Container.GetContainers(configuration, firstRun, propertyLogic);
propertyLogic.ParallelWork(ticks, results, firstPass: false);
if (exceptionsDirectories.Any())
throw new Exception();
return new(j, f, t, results);
}
}

View File

@ -147,7 +147,7 @@ public class Container
return results;
}
private static (int, Shared.Models.Container[]) GetContainers(Configuration configuration, bool firstRun, string aPropertySingletonDirectory, List<(int, string, FileHolder[])> fileHolderGroupCollection, List<(int, string, List<(string, Shared.Models.Property?)>)> collectionFromJson)
private static (int, Shared.Models.Container[]) GetContainers(Configuration configuration, string aPropertySingletonDirectory, List<(int, string, FileHolder[])> fileHolderGroupCollection, List<(int, string, List<(string, Shared.Models.Property?)>)> collectionFromJson)
{
int result = 0;
Shared.Models.Container[] results;
@ -236,11 +236,6 @@ public class Container
if (sourceDirectoryFileHolder.ExtensionLowered is ".json")
continue;
isValidImageFormatExtension = configuration.ValidImageFormatExtensions.Contains(sourceDirectoryFileHolder.ExtensionLowered);
if (firstRun)
item = new(sourceDirectoryFileHolder.FullName, relativePath, sourceDirectoryFileHolder, isValidImageFormatExtension, null, null, null);
else if (!isValidImageFormatExtension)
item = new(sourceDirectoryFileHolder.FullName, relativePath, sourceDirectoryFileHolder, isValidImageFormatExtension, null, null, null);
else
item = new(sourceDirectoryFileHolder.FullName, relativePath, sourceDirectoryFileHolder, isValidImageFormatExtension, null, null, null);
items.Add(item);
}
@ -262,13 +257,13 @@ public class Container
}
}
}
if (!firstRun && fileHolderKeyValuePairs.Any())
throw new Exception();
if (fileHolderKeyValuePairs.Any())
throw new NotSupportedException("Unmapped left!");
results = (from l in keyValuePairs orderby l.Value.G, l.Value.Items.Count select l.Value).ToArray();
return new(result, results);
}
public static (int, int, int, Shared.Models.Container[]) GetContainers(Configuration configuration, bool firstRun, A_Property propertyLogic)
public static (int, int, int, Shared.Models.Container[]) GetContainers(Configuration configuration, A_Property propertyLogic)
{
Shared.Models.Container[] results;
string searchPattern = "*";
@ -280,7 +275,7 @@ public class Container
(int j, jsonCollection) = GetJsonGroupCollection(configuration, propertyLogic, aPropertySingletonDirectory);
(int f, fileHolderGroupCollection) = GetFileHolderGroupCollection(configuration, propertyLogic, searchPattern, topDirectories);
collectionFromJson = GetCollection(aPropertySingletonDirectory, jsonCollection);
(int t, results) = GetContainers(configuration, firstRun, aPropertySingletonDirectory, fileHolderGroupCollection, collectionFromJson);
(int t, results) = GetContainers(configuration, aPropertySingletonDirectory, fileHolderGroupCollection, collectionFromJson);
return (j, f, t, results);
}

View File

@ -62,15 +62,15 @@ public class Property : Properties.IProperty
public List<DateTime> GetDateTimes() => Stateless.Methods.Property.GetDateTimes(_CreationTime, _LastWriteTime, _DateTime, _DateTimeDigitized, _DateTimeOriginal, _GPSDateStamp);
public (bool?, string[]) IsWrongYear(string filteredSourceDirectoryFile, DateTime? minimumDateTime)
public (bool?, string[]) IsWrongYear(FileHolder fileHolder, DateTime? minimumDateTime)
{
string[] results = Array.Empty<string>();
bool? result = null;
string year;
string directoryName;
string[] directorySegments;
string? check = Path.GetFullPath(filteredSourceDirectoryFile);
string? pathRoot = Path.GetPathRoot(filteredSourceDirectoryFile);
string? check = Path.GetFullPath(fileHolder.FullName);
string? pathRoot = Path.GetPathRoot(fileHolder.FullName);
if (string.IsNullOrEmpty(pathRoot))
throw new Exception();
if (minimumDateTime.HasValue)

View File

@ -38,10 +38,6 @@ public interface IProperty
static (bool?, string[]) IsWrongYear(string[] segments, string year) =>
Property.IsWrongYear(segments, year);
(bool?, string[]) TestStatic_IsWrongYear(string fileName, DateTime minimumDateTime);
static (bool?, string[]) IsWrongYear(string fileName, DateTime minimumDateTime) =>
throw new NotImplementedException(); //Property.IsWrongYear(fileName, minimumDateTime);
List<DateTime> TestStatic_GetDateTimes(Models.Property property);
static List<DateTime> GetDateTimes(Models.Property property) =>
Property.GetDateTimes(property.CreationTime, property.LastWriteTime, property.DateTime, property.DateTimeDigitized, property.DateTimeOriginal, property.GPSDateStamp);

View File

@ -253,10 +253,10 @@ internal abstract class Property
return new(j, dateTimes, results);
}
internal static bool Any(Models.Container[] propertyHolderCollections)
internal static bool Any(Models.Container[] containers)
{
bool result = false;
foreach (Models.Container container in propertyHolderCollections)
foreach (Models.Container container in containers)
{
if (!container.Items.Any())
continue;