This commit is contained in:
2022-08-22 09:10:19 -07:00
parent f72fcee1db
commit bc2174b17a
150 changed files with 4323 additions and 6259 deletions

View File

@ -10,7 +10,7 @@
<PropertyGroup>
<PackageId>Phares.View.by.Distance.Date.Group</PackageId>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<Version>5.0.402.104</Version>
<Version>6.0.100.1</Version>
<Authors>Mike Phares</Authors>
<Company>Phares</Company>
<IncludeSymbols>true</IncludeSymbols>

View File

@ -19,7 +19,7 @@ public class DateGroup
private readonly IsEnvironment _IsEnvironment;
private readonly Models.Configuration _Configuration;
private readonly List<KeyValuePair<string, string>> _FileKeyValuePairs;
private readonly Dictionary<string, List<Tuple<string, A_Property>>> _FilePropertiesKeyValuePairs;
private readonly Dictionary<string, List<Tuple<string, Shared.Models.Property>>> _FilePropertiesKeyValuePairs;
public DateGroup(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
{
@ -34,35 +34,34 @@ public class DateGroup
_Exceptions = new List<string>();
_Log = Serilog.Log.ForContext<DateGroup>();
_FileKeyValuePairs = new List<KeyValuePair<string, string>>();
_FilePropertiesKeyValuePairs = new Dictionary<string, List<Tuple<string, A_Property>>>();
Property.Models.Configuration propertyConfiguration = Property.Models.Stateless.Configuration.Get(isEnvironment, configurationRoot, workingDirectory);
_FilePropertiesKeyValuePairs = new Dictionary<string, List<Tuple<string, Shared.Models.Property>>>();
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
Property.Models.Configuration.Verify(propertyConfiguration);
Models.Configuration configuration = Models.Stateless.Configuration.Get(isEnvironment, configurationRoot, workingDirectory, propertyConfiguration);
Verify(configuration);
bool reverse = false;
Model? model = null;
PredictorModel? predictorModel = null;
_Configuration = configuration;
string outputExtension = ".jpg";
PredictorModel? predictorModel = null;
if (configuration.ByHash is null)
throw new NullReferenceException(nameof(configuration.ByHash));
if (configuration.ByCreateDateShortcut is null)
throw new NullReferenceException(nameof(configuration.ByCreateDateShortcut));
if (propertyConfiguration.PopulatePropertyId is null)
throw new NullReferenceException(nameof(propertyConfiguration.PopulatePropertyId));
if (!_IsEnvironment.Development)
throw new Exception("This program only allows development environments!");
long ticks = DateTime.Now.Ticks;
PropertyLogic propertyLogic = GetPropertyLogic(reverse, model, predictorModel);
A_Property propertyLogic = GetPropertyLogic(reverse, model, outputExtension, predictorModel);
string[] dbFiles = Directory.GetFiles(propertyConfiguration.RootDirectory, "*.db", SearchOption.AllDirectories);
foreach (string dbFile in dbFiles)
File.Delete(dbFile);
if (true || appSettings.MaxDegreeOfParallelism < 2)
ticks = LogDelta(ticks, nameof(File.Delete));
for (int i = 1; i < 10; i++)
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
if (true || appSettings.MaxDegreeOfParallelism < 2)
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.IPath.DeleteEmptyDirectories));
List<Container> containers = Property.Models.Stateless.A_Property.Get(propertyConfiguration, propertyLogic);
ticks = LogDelta(ticks, nameof(Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories));
List<Shared.Models.Container> containers = A_Property.Get(propertyConfiguration, propertyLogic);
if (configuration.ByCreateDateShortcut.HasValue && configuration.ByCreateDateShortcut.Value)
CreateDateShortcut(propertyConfiguration, containers);
else
@ -71,15 +70,15 @@ public class DateGroup
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
propertyLogic.ParallelWork(ticks, containers, firstPass: true);
if (appSettings.MaxDegreeOfParallelism < 2)
ticks = LogDelta(ticks, nameof(PropertyLogic.ParallelWork));
ticks = LogDelta(ticks, nameof(A_Property.ParallelWork));
if (propertyLogic.ExceptionsDirectories.Any())
throw new Exception();
if (propertyConfiguration.PopulatePropertyId.Value && (configuration.ByCreateDateShortcut.Value || configuration.ByHash.Value))
if (propertyConfiguration.PopulatePropertyId && (configuration.ByCreateDateShortcut.Value || configuration.ByHash.Value))
{
if (Property.Models.Stateless.A_Property.Any(containers))
if (Shared.Models.Stateless.Methods.IProperty.Any(containers))
propertyLogic.ParallelWork(ticks, containers, firstPass: false);
if (appSettings.MaxDegreeOfParallelism < 2)
ticks = LogDelta(ticks, nameof(PropertyLogic.ParallelWork));
ticks = LogDelta(ticks, nameof(A_Property.ParallelWork));
if (propertyLogic.ExceptionsDirectories.Any())
throw new Exception();
}
@ -107,9 +106,9 @@ public class DateGroup
throw new NullReferenceException(nameof(configuration.KeepFullPath));
if (configuration?.PropertyConfiguration?.PopulatePropertyId is null)
throw new NullReferenceException(nameof(configuration.PropertyConfiguration.PopulatePropertyId));
if (configuration.PropertyConfiguration.PopulatePropertyId.Value && !configuration.ByCreateDateShortcut.Value && !configuration.ByHash.Value)
if (configuration.PropertyConfiguration.PopulatePropertyId && !configuration.ByCreateDateShortcut.Value && !configuration.ByHash.Value)
throw new Exception("Change configuration!");
if (!configuration.PropertyConfiguration.PopulatePropertyId.Value && configuration.ByHash.Value)
if (!configuration.PropertyConfiguration.PopulatePropertyId && configuration.ByHash.Value)
throw new Exception("Change configuration!");
if (configuration.ByCreateDateShortcut.Value && configuration.ByDay.Value && configuration.ByWeek.Value && configuration.BySeason.Value && configuration.ByHash.Value)
throw new Exception("Change configuration!");
@ -147,7 +146,7 @@ public class DateGroup
return result;
}
private long LogDelta(long ticks, string methodName)
private long LogDelta(long ticks, string? methodName)
{
long result;
if (_Log is null)
@ -185,19 +184,19 @@ public class DateGroup
string weekOfYear;
string? directory;
string seasonValue;
A_Property? property;
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();
FileHolder filteredSourceDirectoryFileHolder;
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)
@ -222,7 +221,7 @@ public class DateGroup
directoryName = Path.GetFileName(check);
directorySegments = directoryName.Split(' ');
topDirectorySegments.AddRange(directorySegments);
(_, matches) = Property.Models.Stateless.A_Property.IsWrongYear(directorySegments, string.Empty);
(_, matches) = Shared.Models.Stateless.Methods.IProperty.IsWrongYear(directorySegments, string.Empty);
if (matches.Any())
break;
}
@ -240,7 +239,7 @@ public class DateGroup
if (property is null)
continue;
filteredSourceDirectoryFileHolder = group.SourceDirectoryFileHolderCollection[i];
minimumDateTime = Property.Models.Stateless.A_Property.GetMinimumDateTime(property);
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(property);
directory = filteredSourceDirectoryFileHolder.DirectoryName;
if (string.IsNullOrEmpty(directory))
continue;
@ -261,7 +260,7 @@ public class DateGroup
flag = '=';
}
}
(season, seasonName) = Property.Models.Stateless.A_Property.GetSeason(minimumDateTime.Value.DayOfYear);
(season, seasonName) = Shared.Models.Stateless.Methods.IProperty.GetSeason(minimumDateTime.Value.DayOfYear);
if ((from l in topDirectorySegments where l == "Christmas" select true).Any())
seasonValue = string.Empty;
else
@ -326,12 +325,12 @@ public class DateGroup
return results;
}
private PropertyLogic GetPropertyLogic(bool reverse, Model? model, PredictorModel? predictorModel)
private A_Property GetPropertyLogic(bool reverse, Model? model, string outputExtension, PredictorModel? predictorModel)
{
PropertyLogic result;
A_Property result;
if (_Configuration?.PropertyConfiguration is null)
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
result = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, reverse, model, predictorModel);
result = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, outputExtension, reverse, model, predictorModel);
return result;
}
@ -427,17 +426,17 @@ public class DateGroup
}
_Log.Information($"Done moving back {moved} file(s)");
for (int i = 1; i < 10; i++)
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(_Configuration.PropertyConfiguration.RootDirectory);
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(_Configuration.PropertyConfiguration.RootDirectory);
}
private static void CreateDateShortcut(Property.Models.Configuration configuration, List<Container> containers)
private static void CreateDateShortcut(Property.Models.Configuration configuration, List<Shared.Models.Container> containers)
{
string path;
string fileName;
string directory;
int selectedTotal;
const int minimum = 3;
List<Item> selectedItems;
List<Shared.Models.Item> selectedItems;
List<DateTime> dateTimes;
DateTime? minimumDateTime;
const int maximumHours = 24;
@ -445,26 +444,26 @@ public class DateGroup
WindowsShortcut windowsShortcut;
TimeSpan threeStandardDeviationHigh;
string aPropertyContentDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "()");
foreach (Container container in containers)
foreach (Shared.Models.Container container in containers)
{
if (!container.Items.Any())
continue;
selectedTotal = 0;
threeStandardDeviationHigh = Property.Models.Stateless.A_Property.GetThreeStandardDeviationHigh(minimum, container);
threeStandardDeviationHigh = Shared.Models.Stateless.Methods.IProperty.GetThreeStandardDeviationHigh(minimum, container);
if (threeStandardDeviationHigh.TotalHours > maximumHours)
threeStandardDeviationHigh = new(maximumHours, 0, 0);
for (int i = 0; i < container.Items.Count; i++)
{
(i, dateTimes, selectedItems) = Property.Models.Stateless.A_Property.Get(container, threeStandardDeviationHigh, i);
(i, dateTimes, selectedItems) = Shared.Models.Stateless.Methods.IProperty.Get(container, threeStandardDeviationHigh, i);
selectedTotal += selectedItems.Count;
foreach (Item item in selectedItems)
foreach (Shared.Models.Item item in selectedItems)
{
if (item.Property is null)
continue;
relativePathDirectory = Path.GetDirectoryName(item.RelativePath);
if (string.IsNullOrEmpty(relativePathDirectory))
continue;
minimumDateTime = Property.Models.Stateless.A_Property.GetMinimumDateTime(item.Property);
minimumDateTime = Shared.Models.Stateless.Methods.IProperty.GetMinimumDateTime(item.Property);
if (minimumDateTime is null)
continue;
path = Path.GetFullPath($"{configuration.RootDirectory}{item.RelativePath[..^5]}");

View File

@ -39,41 +39,41 @@ public class Program
if (args is null)
throw new Exception("args is null!");
#nullable disable
if (Property.Models.Stateless.A_Property.IsWrongYear("-".Split(' '), "2021").Item1.HasValue)
if (IProperty.IsWrongYear("-".Split(' '), "2021").Item1.HasValue)
throw new Exception("-");
if (Property.Models.Stateless.A_Property.IsWrongYear("Christmass".Split(' '), "2021").Item1.HasValue)
if (IProperty.IsWrongYear("Christmass".Split(' '), "2021").Item1.HasValue)
throw new Exception("Christmass");
if (Property.Models.Stateless.A_Property.IsWrongYear("Christmass 2021".Split(' '), "2021").Item1.Value)
if (IProperty.IsWrongYear("Christmass 2021".Split(' '), "2021").Item1.Value)
throw new Exception("Christmass");
if (Property.Models.Stateless.A_Property.IsWrongYear("Christmass ~2021".Split(' '), "2021").Item1.Value)
if (IProperty.IsWrongYear("Christmass ~2021".Split(' '), "2021").Item1.Value)
throw new Exception("Christmass");
if (Property.Models.Stateless.A_Property.IsWrongYear("Christmass ~2021.4".Split(' '), "2021").Item1.Value)
if (IProperty.IsWrongYear("Christmass ~2021.4".Split(' '), "2021").Item1.Value)
throw new Exception("Christmass");
if (!Property.Models.Stateless.A_Property.IsWrongYear("Christmass 2021".Split(' '), "2025").Item1.Value)
if (!IProperty.IsWrongYear("Christmass 2021".Split(' '), "2025").Item1.Value)
throw new Exception("Christmass");
if (!Property.Models.Stateless.A_Property.IsWrongYear("Christmass ~2021".Split(' '), "2025").Item1.Value)
if (!IProperty.IsWrongYear("Christmass ~2021".Split(' '), "2025").Item1.Value)
throw new Exception("Christmass");
if (!Property.Models.Stateless.A_Property.IsWrongYear("Christmass ~2021.4".Split(' '), "2025").Item1.Value)
if (!IProperty.IsWrongYear("Christmass ~2021.4".Split(' '), "2025").Item1.Value)
throw new Exception("Christmass");
if (Property.Models.Stateless.A_Property.IsWrongYear("England 2017".Split(' '), "2017").Item1.Value)
if (IProperty.IsWrongYear("England 2017".Split(' '), "2017").Item1.Value)
throw new Exception("England");
if (Property.Models.Stateless.A_Property.IsWrongYear("Logan Michael".Split(' '), "2021").Item1.HasValue)
if (IProperty.IsWrongYear("Logan Michael".Split(' '), "2021").Item1.HasValue)
throw new Exception("Logan Michael");
if (Property.Models.Stateless.A_Property.IsWrongYear("Logan Michael 2021".Split(' '), "2021").Item1.Value)
if (IProperty.IsWrongYear("Logan Michael 2021".Split(' '), "2021").Item1.Value)
throw new Exception("Logan Michael");
if (Property.Models.Stateless.A_Property.IsWrongYear("Logan Michael ~2021".Split(' '), "2021").Item1.Value)
if (IProperty.IsWrongYear("Logan Michael ~2021".Split(' '), "2021").Item1.Value)
throw new Exception("Logan Michael");
if (Property.Models.Stateless.A_Property.IsWrongYear("Logan Michael ~2021.4".Split(' '), "2021").Item1.Value)
if (IProperty.IsWrongYear("Logan Michael ~2021.4".Split(' '), "2021").Item1.Value)
throw new Exception("Logan Michael");
if (!Property.Models.Stateless.A_Property.IsWrongYear("Logan Michael 2021".Split(' '), "2025").Item1.Value)
if (!IProperty.IsWrongYear("Logan Michael 2021".Split(' '), "2025").Item1.Value)
throw new Exception("Logan Michael");
if (!Property.Models.Stateless.A_Property.IsWrongYear("Logan Michael ~2021".Split(' '), "2025").Item1.Value)
if (!IProperty.IsWrongYear("Logan Michael ~2021".Split(' '), "2025").Item1.Value)
throw new Exception("Logan Michael");
if (!Property.Models.Stateless.A_Property.IsWrongYear("Logan Michael ~2021.4".Split(' '), "2025").Item1.Value)
if (!IProperty.IsWrongYear("Logan Michael ~2021.4".Split(' '), "2025").Item1.Value)
throw new Exception("Logan Michael");
if (Property.Models.Stateless.A_Property.IsWrongYear("Logan Michael ~2021.4".Split(' '), "2021").Item2[0] != "~2021.4")
if (IProperty.IsWrongYear("Logan Michael ~2021.4".Split(' '), "2021").Item2[0] != "~2021.4")
throw new Exception("Logan Michael");
if (Property.Models.Stateless.A_Property.IsWrongYear("Chelsea's 2nd Birthday =2014".Split(' '), "2014").Item1.Value)
if (IProperty.IsWrongYear("Chelsea's 2nd Birthday =2014".Split(' '), "2014").Item1.Value)
throw new Exception("Chelsea");
#nullable restore
Shared.Models.Console console = new();

View File

@ -55,15 +55,15 @@
"ByHash": false,
"BySeason": false,
"ByWeek": false,
"DateGroup": "2022-08-14",
"DateGroup": "2022-08-22",
"FileNameDirectorySeparator": ".Z.",
"ForcePropertyLastWriteTimeToCreationTime": false,
"KeepFullPath": false,
"MaxImagesInDirectoryForTopLevelFirstPass": 50,
"MaxImagesInDirectoryForTopLevelFirstPass": 10,
"Pattern": "[^ABCDEFGHIJKLMNOPQRSTUVWXYZbcdfghjklmnpqrstvwxyz0-9]",
"PopulatePropertyId": true,
"PropertiesChangedForProperty": false,
"RootDirectory": "C:/Tmp/Phares/Compare/Images 2022-08-14 - b756859b616424dc98b7742a64c15a8951632473 - III",
"RootDirectory": "C:/Tmp/Phares/Compare/Images 2022-08-22 - b756859b616424dc98b7742a64c15a8951632473 - III",
"WriteBitmapDataBytes": false,
"IgnoreExtensions": [
".gif",