NullReferenceException
This commit is contained in:
@ -31,7 +31,7 @@ public class DateGroup
|
||||
{ }
|
||||
_AppSettings = appSettings;
|
||||
if (appSettings.MaxDegreeOfParallelism is null)
|
||||
throw new ArgumentNullException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
|
||||
_IsEnvironment = isEnvironment;
|
||||
_Exceptions = new List<string>();
|
||||
_Log = Serilog.Log.ForContext<DateGroup>();
|
||||
@ -46,15 +46,15 @@ public class DateGroup
|
||||
PredictorModel? predictorModel = null;
|
||||
_Configuration = configuration;
|
||||
if (configuration.ByHash is null)
|
||||
throw new ArgumentNullException(nameof(configuration.ByHash));
|
||||
throw new NullReferenceException(nameof(configuration.ByHash));
|
||||
if (configuration.ByCreateDateShortcut is null)
|
||||
throw new ArgumentNullException(nameof(configuration.ByCreateDateShortcut));
|
||||
throw new NullReferenceException(nameof(configuration.ByCreateDateShortcut));
|
||||
if (propertyConfiguration.PopulatePropertyId is null)
|
||||
throw new ArgumentNullException(nameof(propertyConfiguration.PopulatePropertyId));
|
||||
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();
|
||||
PropertyLogic propertyLogic = GetPropertyLogic(reverse, model, predictorModel);
|
||||
string[] dbFiles = Directory.GetFiles(propertyConfiguration.RootDirectory, "*.db", SearchOption.AllDirectories);
|
||||
foreach (string dbFile in dbFiles)
|
||||
File.Delete(dbFile);
|
||||
@ -64,22 +64,22 @@ public class DateGroup
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
if (true || appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.IPath.DeleteEmptyDirectories));
|
||||
List<PropertyHolder[]> propertyHolderCollections = Property.Models.Stateless.A_Property.Get(propertyConfiguration, reverse, model, predictorModel, propertyLogic);
|
||||
List<Container> containers = Property.Models.Stateless.A_Property.Get(propertyConfiguration, propertyLogic);
|
||||
if (configuration.ByCreateDateShortcut.HasValue && configuration.ByCreateDateShortcut.Value)
|
||||
CreateDateShortcut(propertyConfiguration, propertyHolderCollections);
|
||||
CreateDateShortcut(propertyConfiguration, containers);
|
||||
else
|
||||
{
|
||||
List<string> topDirectories = new();
|
||||
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
|
||||
propertyLogic.ParallelWork(propertyConfiguration, model, predictorModel, ticks, propertyHolderCollections, firstPass: true);
|
||||
propertyLogic.ParallelWork(ticks, containers, firstPass: true);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
ticks = LogDelta(ticks, nameof(PropertyLogic.ParallelWork));
|
||||
if (propertyLogic.ExceptionsDirectories.Any())
|
||||
throw new Exception();
|
||||
if (propertyConfiguration.PopulatePropertyId.Value && (configuration.ByCreateDateShortcut.Value || configuration.ByHash.Value))
|
||||
{
|
||||
if (Property.Models.Stateless.A_Property.Any(propertyHolderCollections))
|
||||
propertyLogic.ParallelWork(propertyConfiguration, model, predictorModel, ticks, propertyHolderCollections, firstPass: false);
|
||||
if (Property.Models.Stateless.A_Property.Any(containers))
|
||||
propertyLogic.ParallelWork(ticks, containers, firstPass: false);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
ticks = LogDelta(ticks, nameof(PropertyLogic.ParallelWork));
|
||||
if (propertyLogic.ExceptionsDirectories.Any())
|
||||
@ -94,21 +94,21 @@ public class DateGroup
|
||||
private static void Verify(Models.Configuration configuration)
|
||||
{
|
||||
if (configuration.ByCreateDateShortcut is null)
|
||||
throw new ArgumentNullException(nameof(configuration.ByCreateDateShortcut));
|
||||
throw new NullReferenceException(nameof(configuration.ByCreateDateShortcut));
|
||||
if (configuration.ByDay is null)
|
||||
throw new ArgumentNullException(nameof(configuration.ByDay));
|
||||
throw new NullReferenceException(nameof(configuration.ByDay));
|
||||
if (configuration.ByHash is null)
|
||||
throw new ArgumentNullException(nameof(configuration.ByHash));
|
||||
throw new NullReferenceException(nameof(configuration.ByHash));
|
||||
if (configuration.BySeason is null)
|
||||
throw new ArgumentNullException(nameof(configuration.BySeason));
|
||||
throw new NullReferenceException(nameof(configuration.BySeason));
|
||||
if (configuration.ByWeek is null)
|
||||
throw new ArgumentNullException(nameof(configuration.ByWeek));
|
||||
throw new NullReferenceException(nameof(configuration.ByWeek));
|
||||
if (!configuration.ByCreateDateShortcut.Value && !configuration.ByDay.Value && !configuration.ByWeek.Value && !configuration.BySeason.Value && !configuration.ByHash.Value)
|
||||
throw new Exception("Change configuration!");
|
||||
if (configuration.KeepFullPath is null)
|
||||
throw new ArgumentNullException(nameof(configuration.KeepFullPath));
|
||||
throw new NullReferenceException(nameof(configuration.KeepFullPath));
|
||||
if (configuration?.PropertyConfiguration?.PopulatePropertyId is null)
|
||||
throw new ArgumentNullException(nameof(configuration.PropertyConfiguration.PopulatePropertyId));
|
||||
throw new NullReferenceException(nameof(configuration.PropertyConfiguration.PopulatePropertyId));
|
||||
if (configuration.PropertyConfiguration.PopulatePropertyId.Value && !configuration.ByCreateDateShortcut.Value && !configuration.ByHash.Value)
|
||||
throw new Exception("Change configuration!");
|
||||
if (!configuration.PropertyConfiguration.PopulatePropertyId.Value && configuration.ByHash.Value)
|
||||
@ -153,7 +153,7 @@ public class DateGroup
|
||||
{
|
||||
long result;
|
||||
if (_Log is null)
|
||||
throw new ArgumentNullException(nameof(_Log));
|
||||
throw new NullReferenceException(nameof(_Log));
|
||||
double delta = new TimeSpan(DateTime.Now.Ticks - ticks).TotalMilliseconds;
|
||||
_Log.Debug($"{methodName} took {Math.Floor(delta)} millisecond(s)");
|
||||
result = DateTime.Now.Ticks;
|
||||
@ -164,17 +164,17 @@ public class DateGroup
|
||||
{
|
||||
List<(string Source, string[] Destination)> results = new();
|
||||
if (_Configuration.ByCreateDateShortcut is null)
|
||||
throw new ArgumentNullException(nameof(_Configuration.ByCreateDateShortcut));
|
||||
throw new NullReferenceException(nameof(_Configuration.ByCreateDateShortcut));
|
||||
if (_Configuration.ByDay is null)
|
||||
throw new ArgumentNullException(nameof(_Configuration.ByDay));
|
||||
throw new NullReferenceException(nameof(_Configuration.ByDay));
|
||||
if (_Configuration.ByHash is null)
|
||||
throw new ArgumentNullException(nameof(_Configuration.ByHash));
|
||||
throw new NullReferenceException(nameof(_Configuration.ByHash));
|
||||
if (_Configuration.BySeason is null)
|
||||
throw new ArgumentNullException(nameof(_Configuration.BySeason));
|
||||
throw new NullReferenceException(nameof(_Configuration.BySeason));
|
||||
if (_Configuration.ByWeek is null)
|
||||
throw new ArgumentNullException(nameof(_Configuration.ByWeek));
|
||||
throw new NullReferenceException(nameof(_Configuration.ByWeek));
|
||||
if (_Configuration.KeepFullPath is null)
|
||||
throw new ArgumentNullException(nameof(_Configuration.KeepFullPath));
|
||||
throw new NullReferenceException(nameof(_Configuration.KeepFullPath));
|
||||
char flag;
|
||||
string day;
|
||||
int season;
|
||||
@ -319,7 +319,7 @@ public class DateGroup
|
||||
if (!_Configuration.ByHash.Value || property.Id is null)
|
||||
fileName = filteredSourceDirectoryFileHolder.Name;
|
||||
else
|
||||
fileName = $"{property.Id.Value}{filteredSourceDirectoryFileHolder.Extension.ToLower()}";
|
||||
fileName = $"{property.Id.Value}{filteredSourceDirectoryFileHolder.ExtensionLowered}";
|
||||
destinationCollection.Add(destinationDirectory);
|
||||
destinationCollection.AddRange(directoryNames);
|
||||
destinationCollection.Add(fileName);
|
||||
@ -328,14 +328,14 @@ public class DateGroup
|
||||
return results;
|
||||
}
|
||||
|
||||
private PropertyLogic GetPropertyLogic()
|
||||
private PropertyLogic GetPropertyLogic(bool reverse, Model? model, PredictorModel? predictorModel)
|
||||
{
|
||||
PropertyLogic result;
|
||||
if (_AppSettings.MaxDegreeOfParallelism is null)
|
||||
throw new ArgumentNullException(nameof(_AppSettings.MaxDegreeOfParallelism));
|
||||
throw new NullReferenceException(nameof(_AppSettings.MaxDegreeOfParallelism));
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new ArgumentNullException(nameof(_Configuration.PropertyConfiguration));
|
||||
result = new(_AppSettings.MaxDegreeOfParallelism.Value, _Configuration.PropertyConfiguration);
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
result = new(_AppSettings.MaxDegreeOfParallelism.Value, _Configuration.PropertyConfiguration, reverse, model, predictorModel);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -343,9 +343,9 @@ public class DateGroup
|
||||
{
|
||||
List<(string Source, string[] Destination)> results = new();
|
||||
if (_Configuration.KeepFullPath is null)
|
||||
throw new ArgumentNullException(nameof(_Configuration.KeepFullPath));
|
||||
throw new NullReferenceException(nameof(_Configuration.KeepFullPath));
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new ArgumentNullException(nameof(_Configuration.PropertyConfiguration));
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
string? topDirectory;
|
||||
string? checkDirectory;
|
||||
string sourceDirectory;
|
||||
@ -380,9 +380,9 @@ public class DateGroup
|
||||
private void MoveFiles(List<string> topDirectories, List<Property.Models.DirectoryInfo> groupCollection)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new ArgumentNullException(nameof(_Log));
|
||||
throw new NullReferenceException(nameof(_Log));
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new ArgumentNullException(nameof(_Configuration.PropertyConfiguration));
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
string directoryName;
|
||||
List<string> distinct = new();
|
||||
List<(string Source, string[] Destination)> fileMoveCollectionAll = GetFileMoveCollectionAll(topDirectories, groupCollection);
|
||||
@ -434,44 +434,48 @@ public class DateGroup
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(_Configuration.PropertyConfiguration.RootDirectory);
|
||||
}
|
||||
|
||||
private static void CreateDateShortcut(Property.Models.Configuration configuration, List<PropertyHolder[]> propertyHolderCollections)
|
||||
private static void CreateDateShortcut(Property.Models.Configuration configuration, List<Container> containers)
|
||||
{
|
||||
string path;
|
||||
string fileName;
|
||||
string directory;
|
||||
int selectedTotal;
|
||||
const int minimum = 3;
|
||||
List<Item> selectedItems;
|
||||
List<DateTime> dateTimes;
|
||||
DateTime? minimumDateTime;
|
||||
const int maximumHours = 24;
|
||||
string? relativePathDirectory;
|
||||
WindowsShortcut windowsShortcut;
|
||||
TimeSpan threeStandardDeviationHigh;
|
||||
List<PropertyHolder> selectedPropertyHolderCollection;
|
||||
string aPropertyContentDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "()");
|
||||
foreach (PropertyHolder[] propertyHolderCollection in propertyHolderCollections)
|
||||
foreach (Container container in containers)
|
||||
{
|
||||
if (!propertyHolderCollection.Any())
|
||||
if (!container.Items.Any())
|
||||
continue;
|
||||
selectedTotal = 0;
|
||||
threeStandardDeviationHigh = Property.Models.Stateless.A_Property.GetThreeStandardDeviationHigh(minimum, propertyHolderCollection);
|
||||
threeStandardDeviationHigh = Property.Models.Stateless.A_Property.GetThreeStandardDeviationHigh(minimum, container);
|
||||
if (threeStandardDeviationHigh.TotalHours > maximumHours)
|
||||
threeStandardDeviationHigh = new(maximumHours, 0, 0);
|
||||
for (int i = 0; i < propertyHolderCollection.Length; i++)
|
||||
for (int i = 0; i < container.Items.Count; i++)
|
||||
{
|
||||
(i, dateTimes, selectedPropertyHolderCollection) = Property.Models.Stateless.A_Property.Get(propertyHolderCollection, threeStandardDeviationHigh, i);
|
||||
selectedTotal += selectedPropertyHolderCollection.Count;
|
||||
foreach (PropertyHolder propertyHolder in selectedPropertyHolderCollection)
|
||||
(i, dateTimes, selectedItems) = Property.Models.Stateless.A_Property.Get(container, threeStandardDeviationHigh, i);
|
||||
selectedTotal += selectedItems.Count;
|
||||
foreach (Item item in selectedItems)
|
||||
{
|
||||
if (propertyHolder.Property is null || propertyHolder.MinimumDateTime is null)
|
||||
if (item.Property is null)
|
||||
continue;
|
||||
relativePathDirectory = Path.GetDirectoryName(propertyHolder.RelativePath);
|
||||
relativePathDirectory = Path.GetDirectoryName(item.RelativePath);
|
||||
if (string.IsNullOrEmpty(relativePathDirectory))
|
||||
continue;
|
||||
path = Path.GetFullPath($"{configuration.RootDirectory}{propertyHolder.RelativePath[..^5]}");
|
||||
minimumDateTime = Property.Models.Stateless.A_Property.GetMinimumDateTime(item.Property);
|
||||
if (minimumDateTime is null)
|
||||
continue;
|
||||
path = Path.GetFullPath($"{configuration.RootDirectory}{item.RelativePath[..^5]}");
|
||||
directory = Path.Combine($"{aPropertyContentDirectory}{relativePathDirectory}", $"{dateTimes.Min():yyyy-MM-dd_HH-mm-ss}---{dateTimes.Max():yyyy-MM-dd_HH-mm-ss}");
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
fileName = Path.Combine(directory, $"{Path.GetFileName(propertyHolder.RelativePath[..^5])}.lnk");
|
||||
fileName = Path.Combine(directory, $"{Path.GetFileName(item.RelativePath[..^5])}.lnk");
|
||||
if (File.Exists(fileName))
|
||||
continue;
|
||||
windowsShortcut = new() { Path = path };
|
||||
@ -479,10 +483,10 @@ public class DateGroup
|
||||
windowsShortcut.Dispose();
|
||||
if (!File.Exists(fileName))
|
||||
continue;
|
||||
File.SetLastWriteTime(fileName, propertyHolder.MinimumDateTime.Value);
|
||||
File.SetLastWriteTime(fileName, minimumDateTime.Value);
|
||||
}
|
||||
}
|
||||
if (selectedTotal < propertyHolderCollection.Length && selectedTotal < (from l in propertyHolderCollection where l.Property is not null && l.MinimumDateTime.HasValue select true).Count())
|
||||
if (selectedTotal < container.Items.Count && selectedTotal < (from l in container.Items where l.Property is not null select true).Count())
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user