Deleted Method Get
This commit is contained in:
parent
569ee26c55
commit
6610565ce3
@ -162,7 +162,17 @@ public class Compare
|
|||||||
}
|
}
|
||||||
if (_IsEnvironment.Development && propertyConfiguration.PopulatePropertyId)
|
if (_IsEnvironment.Development && propertyConfiguration.PopulatePropertyId)
|
||||||
throw new Exception("Copy keyValuePairs-####.json file");
|
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)
|
if (!isSilent)
|
||||||
{
|
{
|
||||||
_Log.Information("First pass completed");
|
_Log.Information("First pass completed");
|
||||||
@ -762,7 +772,7 @@ public class Compare
|
|||||||
List<string> distinctDirectories = new();
|
List<string> distinctDirectories = new();
|
||||||
List<KeyValuePair<int, int[]>> valueCollection = new();
|
List<KeyValuePair<int, int[]>> valueCollection = new();
|
||||||
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
|
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
|
||||||
propertyLogic.ParallelWork(ticks, containers, firstPass: false);
|
propertyLogic.SavePropertyParallelWork(ticks, containers);
|
||||||
if (propertyLogic.ExceptionsDirectories.Any())
|
if (propertyLogic.ExceptionsDirectories.Any())
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
foreach (Property.Models.DirectoryInfo group in directoryInfoCollection)
|
foreach (Property.Models.DirectoryInfo group in directoryInfoCollection)
|
||||||
@ -834,7 +844,7 @@ public class Compare
|
|||||||
List<KeyValuePair<int, int[]>> valueCollection = new();
|
List<KeyValuePair<int, int[]>> valueCollection = new();
|
||||||
(long Ticks, string FilteredSourceDirectoryFile, string PropertyDirectory, int PropertyId)[] collection;
|
(long Ticks, string FilteredSourceDirectoryFile, string PropertyDirectory, int PropertyId)[] collection;
|
||||||
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
|
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
|
||||||
propertyLogic.ParallelWork(ticks, containers, firstPass: false);
|
propertyLogic.SavePropertyParallelWork(ticks, containers);
|
||||||
if (propertyLogic.ExceptionsDirectories.Any())
|
if (propertyLogic.ExceptionsDirectories.Any())
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
foreach (Property.Models.DirectoryInfo group in directoryInfoCollection)
|
foreach (Property.Models.DirectoryInfo group in directoryInfoCollection)
|
||||||
|
@ -58,31 +58,21 @@ public class DateGroup
|
|||||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||||
if (true || appSettings.MaxDegreeOfParallelism < 2)
|
if (true || appSettings.MaxDegreeOfParallelism < 2)
|
||||||
ticks = LogDelta(ticks, nameof(Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories));
|
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)
|
if (configuration.ByCreateDateShortcut.HasValue && configuration.ByCreateDateShortcut.Value)
|
||||||
CreateDateShortcut(propertyConfiguration, containers);
|
CreateDateShortcut(propertyConfiguration, containers);
|
||||||
else
|
else
|
||||||
{
|
MoveFiles(propertyConfiguration, containers);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Verify(Models.Configuration configuration)
|
private static void Verify(Models.Configuration configuration)
|
||||||
@ -154,9 +144,9 @@ public class DateGroup
|
|||||||
return result;
|
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)
|
if (_Configuration.ByCreateDateShortcut is null)
|
||||||
throw new NullReferenceException(nameof(_Configuration.ByCreateDateShortcut));
|
throw new NullReferenceException(nameof(_Configuration.ByCreateDateShortcut));
|
||||||
if (_Configuration.ByDay is null)
|
if (_Configuration.ByDay is null)
|
||||||
@ -179,21 +169,18 @@ public class DateGroup
|
|||||||
string? pathRoot;
|
string? pathRoot;
|
||||||
string seasonName;
|
string seasonName;
|
||||||
string weekOfYear;
|
string weekOfYear;
|
||||||
string? directory;
|
bool? isWrongYear;
|
||||||
string seasonValue;
|
string seasonValue;
|
||||||
string directoryName;
|
string directoryName;
|
||||||
bool? propertyWrongYear;
|
|
||||||
string topDirectoryName;
|
string topDirectoryName;
|
||||||
string[]? matches = null;
|
string[]? matches = null;
|
||||||
string[] directorySegments;
|
string[] directorySegments;
|
||||||
Shared.Models.Property? property;
|
|
||||||
DateTime? minimumDateTime = null;
|
DateTime? minimumDateTime = null;
|
||||||
List<string> destinationCollection;
|
List<string> destinationCollection;
|
||||||
List<string> directoryNames = new();
|
List<string> directoryNames = new();
|
||||||
List<string> topDirectorySegments = new();
|
List<string> topDirectorySegments = new();
|
||||||
StringBuilder destinationDirectoryName = new();
|
StringBuilder destinationDirectoryName = new();
|
||||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||||
Shared.Models.FileHolder filteredSourceDirectoryFileHolder;
|
|
||||||
for (int z = 1; z < 3; z++)
|
for (int z = 1; z < 3; z++)
|
||||||
{
|
{
|
||||||
if (z == 1)
|
if (z == 1)
|
||||||
@ -227,31 +214,26 @@ public class DateGroup
|
|||||||
}
|
}
|
||||||
if (matches is null)
|
if (matches is null)
|
||||||
matches = Array.Empty<string>();
|
matches = Array.Empty<string>();
|
||||||
for (int i = 0; i < group.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();
|
directoryNames.Clear();
|
||||||
|
destinationCollection = new();
|
||||||
_ = destinationDirectoryName.Clear();
|
_ = destinationDirectoryName.Clear();
|
||||||
property = group.PropertyCollection[i];
|
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
||||||
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;
|
|
||||||
day = minimumDateTime.Value.ToString("MM-dd");
|
day = minimumDateTime.Value.ToString("MM-dd");
|
||||||
month = minimumDateTime.Value.ToString("MMMM");
|
month = minimumDateTime.Value.ToString("MMMM");
|
||||||
(propertyWrongYear, _) = property.IsWrongYear(filteredSourceDirectoryFileHolder.FullName, minimumDateTime);
|
(isWrongYear, _) = item.Property.IsWrongYear(item.ImageFileHolder, minimumDateTime);
|
||||||
if (propertyWrongYear is null)
|
if (isWrongYear is null)
|
||||||
flag = '#';
|
flag = '#';
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (propertyWrongYear.Value)
|
if (isWrongYear.Value)
|
||||||
flag = '~';
|
flag = '~';
|
||||||
else
|
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 = '^';
|
flag = '^';
|
||||||
else
|
else
|
||||||
flag = '=';
|
flag = '=';
|
||||||
@ -262,7 +244,7 @@ public class DateGroup
|
|||||||
seasonValue = string.Empty;
|
seasonValue = string.Empty;
|
||||||
else
|
else
|
||||||
seasonValue = $".{season}";
|
seasonValue = $".{season}";
|
||||||
if (propertyWrongYear is null || !propertyWrongYear.Value)
|
if (isWrongYear is null || !isWrongYear.Value)
|
||||||
year = $"{flag}{minimumDateTime.Value:yyyy}{seasonValue}";
|
year = $"{flag}{minimumDateTime.Value:yyyy}{seasonValue}";
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -310,14 +292,14 @@ public class DateGroup
|
|||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!_Configuration.ByHash.Value || property.Id is null)
|
if (!_Configuration.ByHash.Value || item.Property.Id is null)
|
||||||
fileName = filteredSourceDirectoryFileHolder.Name;
|
fileName = item.ImageFileHolder.Name;
|
||||||
else
|
else
|
||||||
fileName = $"{property.Id.Value}{filteredSourceDirectoryFileHolder.ExtensionLowered}";
|
fileName = $"{item.Property.Id.Value}{item.ImageFileHolder.ExtensionLowered}";
|
||||||
destinationCollection.Add(destinationDirectory);
|
destinationCollection.Add(destinationDirectory);
|
||||||
destinationCollection.AddRange(directoryNames);
|
destinationCollection.AddRange(directoryNames);
|
||||||
destinationCollection.Add(fileName);
|
destinationCollection.Add(fileName);
|
||||||
results.Add(new(filteredSourceDirectoryFileHolder.FullName, destinationCollection.ToArray()));
|
results.Add(new(minimumDateTime.Value.Ticks, item.ImageFileHolder.FullName, destinationCollection.ToArray()));
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
@ -331,30 +313,42 @@ public class DateGroup
|
|||||||
return result;
|
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)
|
if (_Configuration.KeepFullPath is null)
|
||||||
throw new NullReferenceException(nameof(_Configuration.KeepFullPath));
|
throw new NullReferenceException(nameof(_Configuration.KeepFullPath));
|
||||||
if (_Configuration?.PropertyConfiguration is null)
|
|
||||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
|
||||||
string? topDirectory;
|
string? topDirectory;
|
||||||
string? checkDirectory;
|
string? checkDirectory;
|
||||||
string sourceDirectory;
|
|
||||||
string destinationDirectory;
|
string destinationDirectory;
|
||||||
string destinationRoot = Property.Models.Stateless.IResult.GetResultsGroupDirectory(_Configuration.PropertyConfiguration, "Z) Moved");
|
Shared.Models.Item[] filteredItems;
|
||||||
List<(string Source, string[] Destination)> fileMoveCollectionDirectory;
|
List<(long MinimumDateTimeTicks, string Source, string[] Destination)> fileMoveCollection = new();
|
||||||
foreach (Property.Models.DirectoryInfo group in groupCollection)
|
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)
|
if (!_Configuration.KeepFullPath.Value)
|
||||||
destinationDirectory = destinationRoot;
|
destinationDirectory = destinationRoot;
|
||||||
else
|
else
|
||||||
destinationDirectory = string.Concat(destinationRoot, sourceDirectory[_Configuration.PropertyConfiguration.RootDirectory.Length..]);
|
destinationDirectory = string.Concat(destinationRoot, container.SourceDirectory[configuration.RootDirectory.Length..]);
|
||||||
checkDirectory = Path.GetFullPath(sourceDirectory);
|
checkDirectory = Path.GetFullPath(container.SourceDirectory);
|
||||||
for (int z = 0; z < int.MaxValue; z++)
|
for (int z = 0; z < int.MaxValue; z++)
|
||||||
{
|
{
|
||||||
if (checkDirectory == _Configuration.PropertyConfiguration.RootDirectory || topDirectories.Contains(checkDirectory))
|
if (checkDirectory == configuration.RootDirectory)
|
||||||
break;
|
break;
|
||||||
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
checkDirectory = Path.GetDirectoryName(checkDirectory);
|
||||||
if (string.IsNullOrEmpty(checkDirectory))
|
if (string.IsNullOrEmpty(checkDirectory))
|
||||||
@ -363,22 +357,28 @@ public class DateGroup
|
|||||||
if (string.IsNullOrEmpty(checkDirectory))
|
if (string.IsNullOrEmpty(checkDirectory))
|
||||||
continue;
|
continue;
|
||||||
topDirectory = checkDirectory;
|
topDirectory = checkDirectory;
|
||||||
fileMoveCollectionDirectory = GetMoveFileCollection(destinationDirectory, topDirectory, group);
|
filteredItems = GetFilterItems(container);
|
||||||
results.AddRange(fileMoveCollectionDirectory);
|
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;
|
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)
|
if (_Log is null)
|
||||||
throw new NullReferenceException(nameof(_Log));
|
throw new NullReferenceException(nameof(_Log));
|
||||||
if (_Configuration?.PropertyConfiguration is null)
|
if (_Configuration.ByHash is null)
|
||||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
throw new NullReferenceException(nameof(_Configuration.ByHash));
|
||||||
string directoryName;
|
string directoryName;
|
||||||
List<string> distinct = new();
|
List<string> distinct = new();
|
||||||
List<(string Source, string[] Destination)> fileMoveCollectionAll = GetFileMoveCollectionAll(topDirectories, groupCollection);
|
string duplicate = "-Duplicate";
|
||||||
foreach ((string source, string[] destination) in fileMoveCollectionAll)
|
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());
|
directoryName = Path.Combine(destination.Take(destination.Length - 1).ToArray());
|
||||||
if (distinct.Contains(directoryName))
|
if (distinct.Contains(directoryName))
|
||||||
@ -386,44 +386,63 @@ public class DateGroup
|
|||||||
distinct.Add(directoryName);
|
distinct.Add(directoryName);
|
||||||
if (!Directory.Exists(directoryName))
|
if (!Directory.Exists(directoryName))
|
||||||
_ = Directory.CreateDirectory(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?");
|
_Log.Information("Ready to move files?");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
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)
|
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Log.Information(". . .");
|
||||||
int moved = 0;
|
int moved = 0;
|
||||||
string fullFileName;
|
string fullFileName;
|
||||||
foreach ((string source, string[] destination) in fileMoveCollectionAll)
|
foreach ((long _, string source, string[] destination) in fileMoveCollectionAll)
|
||||||
{
|
{
|
||||||
fullFileName = Path.Combine(destination);
|
fullFileName = Path.Combine(destination);
|
||||||
if (File.Exists(fullFileName))
|
if (File.Exists(fullFileName))
|
||||||
continue;
|
{
|
||||||
|
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);
|
File.Move(source, fullFileName);
|
||||||
moved += 1;
|
moved += 1;
|
||||||
}
|
}
|
||||||
|
if (_Configuration.ByHash.Value)
|
||||||
|
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(destinationRoot);
|
||||||
_Log.Information($"{moved} file(s) moved");
|
_Log.Information($"{moved} file(s) moved");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
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)
|
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Log.Information(". . .");
|
||||||
foreach ((string source, string[] destination) in fileMoveCollectionAll)
|
foreach ((long _, string source, string[] destination) in fileMoveCollectionAll)
|
||||||
{
|
{
|
||||||
fullFileName = Path.Combine(destination);
|
fullFileName = Path.Combine(destination);
|
||||||
if (File.Exists(source))
|
if (File.Exists(source))
|
||||||
continue;
|
continue;
|
||||||
|
if (!File.Exists(fullFileName))
|
||||||
|
continue;
|
||||||
File.Move(fullFileName, source);
|
File.Move(fullFileName, source);
|
||||||
moved += 1;
|
moved += 1;
|
||||||
}
|
}
|
||||||
_Log.Information($"Done moving back {moved} file(s)");
|
_Log.Information($"Done moving back {moved} file(s)");
|
||||||
for (int i = 1; i < 10; i++)
|
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)
|
private static void CreateDateShortcut(Property.Models.Configuration configuration, Shared.Models.Container[] containers)
|
||||||
@ -433,13 +452,13 @@ public class DateGroup
|
|||||||
string directory;
|
string directory;
|
||||||
int selectedTotal;
|
int selectedTotal;
|
||||||
const int minimum = 3;
|
const int minimum = 3;
|
||||||
List<Shared.Models.Item> selectedItems;
|
|
||||||
List<DateTime> dateTimes;
|
List<DateTime> dateTimes;
|
||||||
DateTime? minimumDateTime;
|
DateTime? minimumDateTime;
|
||||||
const int maximumHours = 24;
|
const int maximumHours = 24;
|
||||||
string? relativePathDirectory;
|
string? relativePathDirectory;
|
||||||
WindowsShortcut windowsShortcut;
|
WindowsShortcut windowsShortcut;
|
||||||
TimeSpan threeStandardDeviationHigh;
|
TimeSpan threeStandardDeviationHigh;
|
||||||
|
List<Shared.Models.Item> selectedItems;
|
||||||
string aPropertyContentDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "()");
|
string aPropertyContentDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "()");
|
||||||
foreach (Shared.Models.Container container in containers)
|
foreach (Shared.Models.Container container in containers)
|
||||||
{
|
{
|
||||||
|
@ -74,12 +74,11 @@ public partial class Form : System.Windows.Forms.Form
|
|||||||
int f;
|
int f;
|
||||||
int t;
|
int t;
|
||||||
AllowDrop = true;
|
AllowDrop = true;
|
||||||
bool firstRun = false;
|
|
||||||
Container[] containers;
|
Container[] containers;
|
||||||
DragDrop += new DragEventHandler(Form1_DragDrop);
|
DragDrop += new DragEventHandler(Form1_DragDrop);
|
||||||
DragEnter += new DragEventHandler(Form1_DragEnter);
|
DragEnter += new DragEventHandler(Form1_DragEnter);
|
||||||
Property.Models.A_Property propertyLogic = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, _ResizeFileNameExtension, _Configuration.Reverse);
|
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);
|
List<MappingFromItem> collection = Program.GetMappingFromItemCollection(_Configuration, containers);
|
||||||
foreach (MappingFromItem mappingFromItem in collection)
|
foreach (MappingFromItem mappingFromItem in collection)
|
||||||
{
|
{
|
||||||
|
@ -68,7 +68,7 @@ static class Program
|
|||||||
if (item.Property?.Id is null || item.ImageFileHolder is null)
|
if (item.Property?.Id is null || item.ImageFileHolder is null)
|
||||||
continue;
|
continue;
|
||||||
minimumDateTime = IProperty.GetMinimumDateTime(item.Property);
|
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);
|
mappingFromItem = new(item.Property.Id.Value, item.ImageFileHolder, isWrongYear, minimumDateTime, item.RelativePath, item.ImageFileHolder);
|
||||||
results.Add(mappingFromItem);
|
results.Add(mappingFromItem);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ public partial class DlibDotNet
|
|||||||
{
|
{
|
||||||
|
|
||||||
private readonly D_Face _Faces;
|
private readonly D_Face _Faces;
|
||||||
private readonly bool _FirstRun;
|
|
||||||
private readonly G_Index _Index;
|
private readonly G_Index _Index;
|
||||||
private readonly C_Resize _Resize;
|
private readonly C_Resize _Resize;
|
||||||
private readonly F_Random _Random;
|
private readonly F_Random _Random;
|
||||||
@ -33,6 +32,7 @@ public partial class DlibDotNet
|
|||||||
private readonly AppSettings _AppSettings;
|
private readonly AppSettings _AppSettings;
|
||||||
private readonly List<string> _Exceptions;
|
private readonly List<string> _Exceptions;
|
||||||
private readonly IsEnvironment _IsEnvironment;
|
private readonly IsEnvironment _IsEnvironment;
|
||||||
|
private readonly bool _PropertyRootExistedBefore;
|
||||||
private readonly Models.Configuration _Configuration;
|
private readonly Models.Configuration _Configuration;
|
||||||
private readonly bool _ArgZeroIsConfigurationRootDirectory;
|
private readonly bool _ArgZeroIsConfigurationRootDirectory;
|
||||||
private readonly Map.Models.Configuration _MapConfiguration;
|
private readonly Map.Models.Configuration _MapConfiguration;
|
||||||
@ -68,7 +68,7 @@ public partial class DlibDotNet
|
|||||||
if (configuration.IgnoreExtensions is null)
|
if (configuration.IgnoreExtensions is null)
|
||||||
throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
throw new NullReferenceException(nameof(configuration.IgnoreExtensions));
|
||||||
string propertyRoot = Property.Models.Stateless.IResult.GetResultsGroupDirectory(propertyConfiguration, nameof(A_Property), create: false);
|
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);
|
argZero = args.Count > 0 ? Path.GetFullPath(args[0]) : Path.GetFullPath(propertyConfiguration.RootDirectory);
|
||||||
_ArgZeroIsConfigurationRootDirectory = propertyConfiguration.RootDirectory == argZero;
|
_ArgZeroIsConfigurationRootDirectory = propertyConfiguration.RootDirectory == argZero;
|
||||||
_Log.Information(configuration.ModelDirectory);
|
_Log.Information(configuration.ModelDirectory);
|
||||||
@ -103,7 +103,7 @@ public partial class DlibDotNet
|
|||||||
_Metadata = new(configuration.ForceMetadataLastWriteTimeToCreationTime, configuration.PropertiesChangedForMetadata);
|
_Metadata = new(configuration.ForceMetadataLastWriteTimeToCreationTime, configuration.PropertiesChangedForMetadata);
|
||||||
_MapConfiguration = Get(configuration, _Faces.FileNameExtension, _Faces.HiddenFileNameExtension, _FaceParts.FileNameExtension);
|
_MapConfiguration = Get(configuration, _Faces.FileNameExtension, _Faces.HiddenFileNameExtension, _FaceParts.FileNameExtension);
|
||||||
_Distance = new(configuration.DistanceMoveUnableToMatch, configuration.DistancePixelDistanceTolerance, configuration.DistanceRenameToMatch, _Configuration.FaceConfidencePercent, configuration.RangeDistanceTolerance, configuration.RangeFaceConfidence);
|
_Distance = new(configuration.DistanceMoveUnableToMatch, configuration.DistancePixelDistanceTolerance, configuration.DistanceRenameToMatch, _Configuration.FaceConfidencePercent, configuration.RangeDistanceTolerance, configuration.RangeFaceConfidence);
|
||||||
if (_FirstRun || !_ArgZeroIsConfigurationRootDirectory)
|
if (_PropertyRootExistedBefore || !_ArgZeroIsConfigurationRootDirectory)
|
||||||
personContainers = Array.Empty<PersonContainer>();
|
personContainers = Array.Empty<PersonContainer>();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -141,7 +141,7 @@ public partial class DlibDotNet
|
|||||||
}
|
}
|
||||||
if (!configuration.SkipSearch)
|
if (!configuration.SkipSearch)
|
||||||
Search(ticks, argZero, propertyRoot, personContainers);
|
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(
|
List<string[]> directoryCollections = _Rename.GetDirectoryRenameCollections(
|
||||||
propertyConfiguration,
|
propertyConfiguration,
|
||||||
@ -163,7 +163,7 @@ public partial class DlibDotNet
|
|||||||
_Log.Information(message);
|
_Log.Information(message);
|
||||||
if (_Exceptions.Count != 0)
|
if (_Exceptions.Count != 0)
|
||||||
throw new Exception(message);
|
throw new Exception(message);
|
||||||
if (_FirstRun)
|
if (_PropertyRootExistedBefore)
|
||||||
_Log.Information("First run completed. Run again if wanted");
|
_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)
|
if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null)
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
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);
|
result = new(item.Property.Id.Value, item.ImageFileHolder, isWrongYear, minimumDateTime, item.RelativePath, item.ResizedFileHolder);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -811,7 +811,7 @@ public partial class DlibDotNet
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
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);
|
mappingFromItem = new(item.Property.Id.Value, item.ImageFileHolder, isWrongYear, minimumDateTime, item.RelativePath, item.ResizedFileHolder);
|
||||||
foreach (Shared.Models.Face face in item.Faces)
|
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)
|
if (item.Property?.Id is null || item.ImageFileHolder is null)
|
||||||
continue;
|
continue;
|
||||||
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
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);
|
mappingFromItem = new(item.Property.Id.Value, item.ImageFileHolder, isWrongYear, minimumDateTime, item.RelativePath, item.ImageFileHolder);
|
||||||
results.Add(mappingFromItem);
|
results.Add(mappingFromItem);
|
||||||
}
|
}
|
||||||
@ -1005,7 +1005,7 @@ public partial class DlibDotNet
|
|||||||
using (ProgressBar progressBar = new(1, message, options))
|
using (ProgressBar progressBar = new(1, message, options))
|
||||||
{
|
{
|
||||||
progressBar.Tick();
|
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);
|
Container? container = AreAllSameEndsWith(argZero, containers);
|
||||||
if (!_ArgZeroIsConfigurationRootDirectory || container is null)
|
if (!_ArgZeroIsConfigurationRootDirectory || container is null)
|
||||||
@ -1030,7 +1030,7 @@ public partial class DlibDotNet
|
|||||||
_Distance.Clear();
|
_Distance.Clear();
|
||||||
foreach (string outputResolution in _Configuration.OutputResolutions)
|
foreach (string outputResolution in _Configuration.OutputResolutions)
|
||||||
{
|
{
|
||||||
if (_FirstRun || container is not null)
|
if (_PropertyRootExistedBefore || container is not null)
|
||||||
break;
|
break;
|
||||||
(aResultsFullGroupDirectory, bResultsFullGroupDirectory, cResultsFullGroupDirectory, dResultsFullGroupDirectory) = GetResultsFullGroupDirectories(outputResolution);
|
(aResultsFullGroupDirectory, bResultsFullGroupDirectory, cResultsFullGroupDirectory, dResultsFullGroupDirectory) = GetResultsFullGroupDirectories(outputResolution);
|
||||||
if (_ArgZeroIsConfigurationRootDirectory
|
if (_ArgZeroIsConfigurationRootDirectory
|
||||||
|
@ -36,9 +36,9 @@ public class NotCopyCopy
|
|||||||
throw new Exception("This program only allows development environments!");
|
throw new Exception("This program only allows development environments!");
|
||||||
A_Property propertyLogic = GetPropertyLogic(reverse, outputExtension);
|
A_Property propertyLogic = GetPropertyLogic(reverse, outputExtension);
|
||||||
propertyConfiguration.ChangeRootDirectory(configuration.CompareSource);
|
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);
|
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)
|
if (compareContainers.Length == selectedContainers.Length)
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
string directoryName;
|
string directoryName;
|
||||||
|
@ -97,15 +97,11 @@ public class A_Property
|
|||||||
|
|
||||||
#pragma warning disable CA1416
|
#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;
|
Shared.Models.Property result;
|
||||||
if (_Log is null)
|
if (_Log is null)
|
||||||
throw new NullReferenceException(nameof(_Log));
|
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;
|
long ticks;
|
||||||
byte[] bytes;
|
byte[] bytes;
|
||||||
string value;
|
string value;
|
||||||
@ -123,18 +119,18 @@ public class A_Property
|
|||||||
DateTime? dateTimeOriginal = null;
|
DateTime? dateTimeOriginal = null;
|
||||||
string orientation = string.Empty;
|
string orientation = string.Empty;
|
||||||
DateTime? dateTimeDigitized = null;
|
DateTime? dateTimeDigitized = null;
|
||||||
if (!isValidImageFormatExtension && isValidMetadataExtensions)
|
if (!isValidImageFormatExtension && isValidMetadataExtensions && fileHolder.Exists)
|
||||||
{
|
{
|
||||||
dateTimeFormat = "ddd MMM dd HH:mm:ss yyyy";
|
dateTimeFormat = "ddd MMM dd HH:mm:ss yyyy";
|
||||||
List<DateTime> dateTimes = GetMetadataDateTimesByPattern(dateTimeFormat, filteredSourceDirectoryFileHolder);
|
List<DateTime> dateTimes = GetMetadataDateTimesByPattern(dateTimeFormat, fileHolder);
|
||||||
if (dateTimes.Any())
|
if (dateTimes.Any())
|
||||||
dateTimeOriginal = dateTimes.Min();
|
dateTimeOriginal = dateTimes.Min();
|
||||||
}
|
}
|
||||||
else if (!isIgnoreExtension && isValidImageFormatExtension)
|
else if (!isIgnoreExtension && isValidImageFormatExtension && fileHolder.Exists)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using Image image = Image.FromFile(filteredSourceDirectoryFileHolder.FullName);
|
using Image image = Image.FromFile(fileHolder.FullName);
|
||||||
if (populateId && (id is null || !indices.Any()))
|
if (populateId && (id is null || !indices.Any()))
|
||||||
{
|
{
|
||||||
using Bitmap bitmap = new(image);
|
using Bitmap bitmap = new(image);
|
||||||
@ -155,7 +151,7 @@ public class A_Property
|
|||||||
}
|
}
|
||||||
if (_Configuration.WriteBitmapDataBytes)
|
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);
|
File.WriteAllBytes(Path.ChangeExtension(contentFileInfo.FullName, string.Empty), bytes);
|
||||||
}
|
}
|
||||||
ticks = DateTime.Now.Ticks;
|
ticks = DateTime.Now.Ticks;
|
||||||
@ -247,22 +243,31 @@ public class A_Property
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
_Log.Info(string.Concat(new StackFrame().GetMethod()?.Name, " <", filteredSourceDirectoryFileHolder.Name, ">"));
|
_Log.Info(string.Concat(new StackFrame().GetMethod()?.Name, " <", fileHolder.Name, ">"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
dateTimeOriginal = null;
|
dateTimeOriginal = null;
|
||||||
if (filteredSourceDirectoryFileHolder.Length is null)
|
if (fileHolder.Length is null)
|
||||||
fileLength = 0;
|
fileLength = 0;
|
||||||
else
|
else
|
||||||
fileLength = filteredSourceDirectoryFileHolder.Length.Value;
|
fileLength = fileHolder.Length.Value;
|
||||||
result = new(filteredSourceDirectoryFileHolder.CreationTime.Value, dateTime, dateTimeDigitized, dateTimeOriginal, fileLength, gpsDateStamp, height, id, indices.ToArray(), filteredSourceDirectoryFileHolder.LastWriteTime.Value, make, model, orientation, width);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning restore CA1416
|
#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;
|
Shared.Models.Property? result;
|
||||||
if (item.ImageFileHolder is null)
|
if (item.ImageFileHolder is null)
|
||||||
@ -271,9 +276,10 @@ public class A_Property
|
|||||||
int? id = null;
|
int? id = null;
|
||||||
List<int> indices = new();
|
List<int> indices = new();
|
||||||
bool hasWrongYearProperty = false;
|
bool hasWrongYearProperty = false;
|
||||||
|
Shared.Models.Property? property = null;
|
||||||
string[] changesFrom = Array.Empty<string>();
|
string[] changesFrom = Array.Empty<string>();
|
||||||
string angleBracket = AngleBracketCollection[0];
|
string angleBracket = AngleBracketCollection[0];
|
||||||
bool populateId = !firstPass && _Configuration.PopulatePropertyId;
|
bool populateId = _Configuration.PopulatePropertyId;
|
||||||
string without = Path.Combine(angleBracket.Replace("<>", "{}"), $"{item.ImageFileHolder.NameWithoutExtension}.json");
|
string without = Path.Combine(angleBracket.Replace("<>", "{}"), $"{item.ImageFileHolder.NameWithoutExtension}.json");
|
||||||
FileInfo fileInfo = new(Path.Combine(angleBracket.Replace("<>", "{}"), $"{item.ImageFileHolder.NameWithoutExtension}{item.ImageFileHolder.ExtensionLowered}.json"));
|
FileInfo fileInfo = new(Path.Combine(angleBracket.Replace("<>", "{}"), $"{item.ImageFileHolder.NameWithoutExtension}{item.ImageFileHolder.ExtensionLowered}.json"));
|
||||||
if (item.ValidImageFormatExtension && File.Exists(without))
|
if (item.ValidImageFormatExtension && File.Exists(without))
|
||||||
@ -281,7 +287,7 @@ public class A_Property
|
|||||||
File.Move(without, fileInfo.FullName);
|
File.Move(without, fileInfo.FullName);
|
||||||
fileInfo.Refresh();
|
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.Exists)
|
||||||
{
|
{
|
||||||
if (fileInfo.Directory?.Parent is null)
|
if (fileInfo.Directory?.Parent is null)
|
||||||
@ -319,14 +325,14 @@ public class A_Property
|
|||||||
if (item.ImageFileHolder is null)
|
if (item.ImageFileHolder is null)
|
||||||
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
||||||
bool check = true;
|
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))
|
if (!isIgnoreExtension && item.ValidImageFormatExtension && ((populateId && property?.Id is null) || property?.Width is null || property?.Height is null))
|
||||||
{
|
{
|
||||||
check = false;
|
check = false;
|
||||||
id = property?.Id;
|
id = property?.Id;
|
||||||
if (property is not null && property.Indices.Any())
|
if (property is not null && property.Indices.Any())
|
||||||
indices = property.Indices.ToList();
|
indices = property.Indices.ToList();
|
||||||
property = GetImageProperty(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())
|
if (!isIgnoreExtension && item.ValidImageFormatExtension && populateId && property is not null && !property.Indices.Any())
|
||||||
{
|
{
|
||||||
@ -334,14 +340,14 @@ public class A_Property
|
|||||||
id = property?.Id;
|
id = property?.Id;
|
||||||
if (property is not null && property.Indices.Any())
|
if (property is not null && property.Indices.Any())
|
||||||
indices = property.Indices.ToList();
|
indices = property.Indices.ToList();
|
||||||
property = GetImageProperty(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)
|
if (!isIgnoreExtension && item.ValidImageFormatExtension && populateId && property is not null && property.LastWriteTime != item.ImageFileHolder.LastWriteTime)
|
||||||
{
|
{
|
||||||
check = false;
|
check = false;
|
||||||
id = null;
|
id = null;
|
||||||
indices.Clear();
|
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)
|
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;
|
id = property?.Id;
|
||||||
if (property is not null && property.Indices.Any())
|
if (property is not null && property.Indices.Any())
|
||||||
indices = property.Indices.ToList();
|
indices = property.Indices.ToList();
|
||||||
property = GetImageProperty(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)
|
if (property?.Width is not null && property?.Height is not null && property.Width.Value != property.Height.Value)
|
||||||
throw new Exception("Was square!");
|
throw new Exception("Was square!");
|
||||||
}
|
}
|
||||||
@ -372,7 +378,7 @@ public class A_Property
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = property;
|
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)
|
catch (Exception)
|
||||||
@ -385,17 +391,17 @@ public class A_Property
|
|||||||
{
|
{
|
||||||
if (item.ImageFileHolder is null)
|
if (item.ImageFileHolder is null)
|
||||||
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
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);
|
json = JsonSerializer.Serialize(result, _WriteIndentedJsonSerializerOptions);
|
||||||
if (populateId && Shared.Models.Stateless.Methods.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
if (populateId && Shared.Models.Stateless.Methods.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches: true, compareBeforeWrite: true))
|
||||||
{
|
{
|
||||||
if (!_Configuration.ForcePropertyLastWriteTimeToCreationTime && (!fileInfo.Exists || fileInfo.LastWriteTime == fileInfo.CreationTime))
|
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
|
else
|
||||||
{
|
{
|
||||||
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
|
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
|
||||||
fileInfo.Refresh();
|
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);
|
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
|
||||||
fileInfo.Refresh();
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool AnyFilesMoved(string sourceDirectory, Item[] filteredItems)
|
private bool AnyFilesMoved(string sourceDirectory, List<Item> items)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
if (_Log is null)
|
if (_Log is null)
|
||||||
@ -428,16 +434,16 @@ public class A_Property
|
|||||||
string destinationDirectory;
|
string destinationDirectory;
|
||||||
string[] sourceDirectorySegments;
|
string[] sourceDirectorySegments;
|
||||||
DateTime directoryMaximumOfMinimumDateTime = DateTime.MinValue;
|
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;
|
continue;
|
||||||
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(filteredItem.Property);
|
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
|
||||||
if (minimumDateTime > directoryMaximumOfMinimumDateTime)
|
if (minimumDateTime > directoryMaximumOfMinimumDateTime)
|
||||||
directoryMaximumOfMinimumDateTime = minimumDateTime;
|
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)
|
if (isWrongYear is null || !isWrongYear.Value)
|
||||||
dateTime = minimumDateTime;
|
dateTime = minimumDateTime;
|
||||||
else
|
else
|
||||||
@ -448,20 +454,20 @@ public class A_Property
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{ File.SetCreationTime(filteredItem.ImageFileHolder.FullName, dateTime); }
|
{ File.SetCreationTime(item.ImageFileHolder.FullName, dateTime); }
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
if (!_VerifyToSeason.Contains(sourceDirectory))
|
if (!_VerifyToSeason.Contains(sourceDirectory))
|
||||||
continue;
|
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);
|
TimeSpan timeSpan = new(item.Property.DateTimeOriginal.Value.Ticks - item.Property.LastWriteTime.Ticks);
|
||||||
if (timeSpan.TotalHours > 6)
|
if (timeSpan.TotalHours > 7.2f)
|
||||||
{
|
{
|
||||||
_Log.Warning($"*** propertyHolder.FileInfo.FullName <{filteredItem.ImageFileHolder.FullName}>");
|
_Log.Warning($"*** propertyHolder.FileInfo.FullName <{item.ImageFileHolder.FullName}>");
|
||||||
_Log.Warning($"*** DateTimeOriginal <{filteredItem.Property.DateTimeOriginal.Value}>");
|
_Log.Warning($"*** DateTimeOriginal <{item.Property.DateTimeOriginal.Value}>");
|
||||||
_Log.Warning($"*** LastWriteTime <{filteredItem.Property.LastWriteTime}>");
|
_Log.Warning($"*** LastWriteTime <{item.Property.LastWriteTime}>");
|
||||||
_Log.Warning($"*** TotalHours <{timeSpan.TotalHours}>");
|
_Log.Warning($"*** TotalHours <{timeSpan.TotalHours}>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -475,44 +481,32 @@ public class A_Property
|
|||||||
destinationDirectory = Path.Combine(_Configuration.RootDirectory, $"={minimumDateTime:yyyy}.{season} {seasonName}");
|
destinationDirectory = Path.Combine(_Configuration.RootDirectory, $"={minimumDateTime:yyyy}.{season} {seasonName}");
|
||||||
if (destinationDirectory == sourceDirectory)
|
if (destinationDirectory == sourceDirectory)
|
||||||
continue;
|
continue;
|
||||||
lock (filteredItem)
|
lock (item)
|
||||||
filteredItem.SetMoved(true);
|
item.SetMoved(true);
|
||||||
if (!result)
|
if (!result)
|
||||||
result = true;
|
result = true;
|
||||||
if (!Directory.Exists(destinationDirectory))
|
if (!Directory.Exists(destinationDirectory))
|
||||||
_ = Directory.CreateDirectory(destinationDirectory);
|
_ = Directory.CreateDirectory(destinationDirectory);
|
||||||
destinationFile = Path.Combine(destinationDirectory, filteredItem.ImageFileHolder.Name);
|
destinationFile = Path.Combine(destinationDirectory, item.ImageFileHolder.Name);
|
||||||
if (File.Exists(destinationFile))
|
if (File.Exists(destinationFile))
|
||||||
{
|
{
|
||||||
if (_OutputExtension is not ".jpg" and not ".jpeg")
|
if (_OutputExtension is not ".jpg" and not ".jpeg")
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
if (destinationFile.EndsWith(".jpg", ignoreCase: true, CultureInfo.CurrentCulture))
|
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))
|
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($"*** 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
_Log.Information($"*** source <{item.ImageFileHolder.FullName}>");
|
||||||
|
_Log.Information($"*** destination <{destinationFile}>");
|
||||||
|
if (!File.Exists(destinationFile))
|
||||||
|
File.Move(item.ImageFileHolder.FullName, destinationFile);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
File.Move(filteredItem.ImageFileHolder.FullName, destinationFile);
|
deleteFile = Path.ChangeExtension(item.ImageFileHolder.FullName, ".delete");
|
||||||
if (filteredItem.ImageFileHolder.Exists)
|
if (File.Exists(deleteFile))
|
||||||
{
|
File.Delete(deleteFile);
|
||||||
deleteFile = Path.ChangeExtension(filteredItem.ImageFileHolder.FullName, ".delete");
|
File.Move(item.ImageFileHolder.FullName, destinationFile);
|
||||||
if (File.Exists(deleteFile))
|
|
||||||
File.Delete(deleteFile);
|
|
||||||
File.Move(filteredItem.ImageFileHolder.FullName, deleteFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (directoryMaximumOfMinimumDateTime != DateTime.MinValue)
|
if (directoryMaximumOfMinimumDateTime != DateTime.MinValue)
|
||||||
@ -524,7 +518,7 @@ public class A_Property
|
|||||||
return result;
|
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)
|
if (item.ImageFileHolder is null)
|
||||||
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
||||||
@ -537,7 +531,7 @@ public class A_Property
|
|||||||
File.Move(item.ImageFileHolder.FullName, filteredSourceDirectoryFileExtensionLowered);
|
File.Move(item.ImageFileHolder.FullName, filteredSourceDirectoryFileExtensionLowered);
|
||||||
if (item.Changed is null || item.Changed.Value || item.Property is null)
|
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)
|
lock (sourceDirectoryChanges)
|
||||||
sourceDirectoryChanges.Add(new Tuple<string, DateTime>(nameof(A_Property), DateTime.Now));
|
sourceDirectoryChanges.Add(new Tuple<string, DateTime>(nameof(A_Property), DateTime.Now));
|
||||||
lock (item)
|
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 };
|
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = _MaxDegreeOfParallelism };
|
||||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||||
using ProgressBar progressBar = new(filteredItems.Length, message, options);
|
using ProgressBar progressBar = new(items.Count, message, options);
|
||||||
_ = Parallel.For(0, filteredItems.Length, parallelOptions, (i, state) =>
|
_ = Parallel.For(0, items.Count, parallelOptions, (i, state) =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
long ticks = DateTime.Now.Ticks;
|
long ticks = DateTime.Now.Ticks;
|
||||||
DateTime dateTime = DateTime.Now;
|
DateTime dateTime = DateTime.Now;
|
||||||
List<Tuple<string, DateTime>> collection;
|
List<Tuple<string, DateTime>> collection;
|
||||||
ParallelForWork(firstPass, container.SourceDirectory, sourceDirectoryChanges, filteredSourceDirectoryFileTuples, filteredItems[i]);
|
SavePropertyParallelForWork(container.SourceDirectory, sourceDirectoryChanges, sourceDirectoryFileTuples, items[i]);
|
||||||
if (i == 0 || sourceDirectoryChanges.Any())
|
if (i == 0 || sourceDirectoryChanges.Any())
|
||||||
progressBar.Tick();
|
progressBar.Tick();
|
||||||
lock (filteredSourceDirectoryFileTuples)
|
lock (sourceDirectoryFileTuples)
|
||||||
collection = (from l in filteredSourceDirectoryFileTuples where l.Item2 > dateTime select l).ToList();
|
collection = (from l in sourceDirectoryFileTuples where l.Item2 > dateTime select l).ToList();
|
||||||
lock (sourceDirectoryChanges)
|
lock (sourceDirectoryChanges)
|
||||||
sourceDirectoryChanges.AddRange(collection);
|
sourceDirectoryChanges.AddRange(collection);
|
||||||
}
|
}
|
||||||
@ -589,14 +583,13 @@ public class A_Property
|
|||||||
collectionDescription: string.Empty));
|
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)
|
if (_Log is null)
|
||||||
throw new NullReferenceException(nameof(_Log));
|
throw new NullReferenceException(nameof(_Log));
|
||||||
string message;
|
string message;
|
||||||
int totalSeconds;
|
int totalSeconds;
|
||||||
bool? anyFilesMoved;
|
bool? anyFilesMoved;
|
||||||
Item[] filteredItems;
|
|
||||||
Shared.Models.Container container;
|
Shared.Models.Container container;
|
||||||
List<Exception> exceptions = new();
|
List<Exception> exceptions = new();
|
||||||
int containersCount = containers.Length;
|
int containersCount = containers.Length;
|
||||||
@ -608,26 +601,22 @@ public class A_Property
|
|||||||
if (!container.Items.Any())
|
if (!container.Items.Any())
|
||||||
continue;
|
continue;
|
||||||
sourceDirectoryChanges.Clear();
|
sourceDirectoryChanges.Clear();
|
||||||
if (firstPass)
|
if (!container.Items.Any())
|
||||||
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())
|
|
||||||
continue;
|
continue;
|
||||||
SetAngleBracketCollection(container.SourceDirectory);
|
SetAngleBracketCollection(container.SourceDirectory);
|
||||||
totalSeconds = (int)Math.Truncate(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
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}";
|
message = $"{i + 1:000}.{container.G} / {containersCount:000}) {container.Items.Count:000} file(s) - {totalSeconds} total second(s) - {container.SourceDirectory}";
|
||||||
ParallelWork(firstPass, exceptions, sourceDirectoryChanges, container, filteredItems, message);
|
SavePropertyParallelWork(exceptions, sourceDirectoryChanges, container, container.Items, message);
|
||||||
foreach (Exception exception in exceptions)
|
foreach (Exception exception in exceptions)
|
||||||
_Log.Error(string.Concat(container.SourceDirectory, Environment.NewLine, exception.Message, Environment.NewLine, exception.StackTrace), exception);
|
_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!"));
|
throw new Exception(string.Concat("All in [", container.SourceDirectory, "]failed!"));
|
||||||
if (exceptions.Count != 0)
|
if (exceptions.Count != 0)
|
||||||
_ExceptionsDirectories.Add(container.SourceDirectory);
|
_ExceptionsDirectories.Add(container.SourceDirectory);
|
||||||
if (!firstPass || exceptions.Count != 0)
|
if (exceptions.Count != 0)
|
||||||
anyFilesMoved = null;
|
anyFilesMoved = null;
|
||||||
else
|
else
|
||||||
anyFilesMoved = AnyFilesMoved(container.SourceDirectory, filteredItems);
|
anyFilesMoved = AnyFilesMoved(container.SourceDirectory, container.Items);
|
||||||
if (Directory.GetFiles(propertyRoot, "*.txt", SearchOption.TopDirectoryOnly).Any())
|
if (Directory.GetFiles(propertyRoot, "*.txt", SearchOption.TopDirectoryOnly).Any())
|
||||||
{
|
{
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
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;
|
Shared.Models.Property result;
|
||||||
if (item.ImageFileHolder is null)
|
if (item.ImageFileHolder is null)
|
||||||
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
||||||
bool firstPass = false;
|
|
||||||
bool isValidMetadataExtensions = _Configuration.ValidMetadataExtensions.Contains(item.ImageFileHolder.ExtensionLowered);
|
bool isValidMetadataExtensions = _Configuration.ValidMetadataExtensions.Contains(item.ImageFileHolder.ExtensionLowered);
|
||||||
bool isIgnoreExtension = item.ValidImageFormatExtension && _Configuration.IgnoreExtensions.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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -688,17 +676,4 @@ public class A_Property
|
|||||||
return results.OrderBy(l => l.Ticks).ToArray();
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -147,7 +147,7 @@ public class Container
|
|||||||
return results;
|
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;
|
int result = 0;
|
||||||
Shared.Models.Container[] results;
|
Shared.Models.Container[] results;
|
||||||
@ -236,12 +236,7 @@ public class Container
|
|||||||
if (sourceDirectoryFileHolder.ExtensionLowered is ".json")
|
if (sourceDirectoryFileHolder.ExtensionLowered is ".json")
|
||||||
continue;
|
continue;
|
||||||
isValidImageFormatExtension = configuration.ValidImageFormatExtensions.Contains(sourceDirectoryFileHolder.ExtensionLowered);
|
isValidImageFormatExtension = configuration.ValidImageFormatExtensions.Contains(sourceDirectoryFileHolder.ExtensionLowered);
|
||||||
if (firstRun)
|
item = new(sourceDirectoryFileHolder.FullName, relativePath, sourceDirectoryFileHolder, isValidImageFormatExtension, null, null, null);
|
||||||
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);
|
items.Add(item);
|
||||||
}
|
}
|
||||||
if (sourceDirectory == configuration.RootDirectory || items.Any())
|
if (sourceDirectory == configuration.RootDirectory || items.Any())
|
||||||
@ -262,13 +257,13 @@ public class Container
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!firstRun && fileHolderKeyValuePairs.Any())
|
if (fileHolderKeyValuePairs.Any())
|
||||||
throw new Exception();
|
throw new NotSupportedException("Unmapped left!");
|
||||||
results = (from l in keyValuePairs orderby l.Value.G, l.Value.Items.Count select l.Value).ToArray();
|
results = (from l in keyValuePairs orderby l.Value.G, l.Value.Items.Count select l.Value).ToArray();
|
||||||
return new(result, results);
|
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;
|
Shared.Models.Container[] results;
|
||||||
string searchPattern = "*";
|
string searchPattern = "*";
|
||||||
@ -280,7 +275,7 @@ public class Container
|
|||||||
(int j, jsonCollection) = GetJsonGroupCollection(configuration, propertyLogic, aPropertySingletonDirectory);
|
(int j, jsonCollection) = GetJsonGroupCollection(configuration, propertyLogic, aPropertySingletonDirectory);
|
||||||
(int f, fileHolderGroupCollection) = GetFileHolderGroupCollection(configuration, propertyLogic, searchPattern, topDirectories);
|
(int f, fileHolderGroupCollection) = GetFileHolderGroupCollection(configuration, propertyLogic, searchPattern, topDirectories);
|
||||||
collectionFromJson = GetCollection(aPropertySingletonDirectory, jsonCollection);
|
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);
|
return (j, f, t, results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,15 +62,15 @@ public class Property : Properties.IProperty
|
|||||||
|
|
||||||
public List<DateTime> GetDateTimes() => Stateless.Methods.Property.GetDateTimes(_CreationTime, _LastWriteTime, _DateTime, _DateTimeDigitized, _DateTimeOriginal, _GPSDateStamp);
|
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>();
|
string[] results = Array.Empty<string>();
|
||||||
bool? result = null;
|
bool? result = null;
|
||||||
string year;
|
string year;
|
||||||
string directoryName;
|
string directoryName;
|
||||||
string[] directorySegments;
|
string[] directorySegments;
|
||||||
string? check = Path.GetFullPath(filteredSourceDirectoryFile);
|
string? check = Path.GetFullPath(fileHolder.FullName);
|
||||||
string? pathRoot = Path.GetPathRoot(filteredSourceDirectoryFile);
|
string? pathRoot = Path.GetPathRoot(fileHolder.FullName);
|
||||||
if (string.IsNullOrEmpty(pathRoot))
|
if (string.IsNullOrEmpty(pathRoot))
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
if (minimumDateTime.HasValue)
|
if (minimumDateTime.HasValue)
|
||||||
|
@ -38,10 +38,6 @@ public interface IProperty
|
|||||||
static (bool?, string[]) IsWrongYear(string[] segments, string year) =>
|
static (bool?, string[]) IsWrongYear(string[] segments, string year) =>
|
||||||
Property.IsWrongYear(segments, 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);
|
List<DateTime> TestStatic_GetDateTimes(Models.Property property);
|
||||||
static List<DateTime> 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);
|
Property.GetDateTimes(property.CreationTime, property.LastWriteTime, property.DateTime, property.DateTimeDigitized, property.DateTimeOriginal, property.GPSDateStamp);
|
||||||
|
@ -253,10 +253,10 @@ internal abstract class Property
|
|||||||
return new(j, dateTimes, results);
|
return new(j, dateTimes, results);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static bool Any(Models.Container[] propertyHolderCollections)
|
internal static bool Any(Models.Container[] containers)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
foreach (Models.Container container in propertyHolderCollections)
|
foreach (Models.Container container in containers)
|
||||||
{
|
{
|
||||||
if (!container.Items.Any())
|
if (!container.Items.Any())
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user