NullReferenceException

This commit is contained in:
2022-08-13 11:19:08 -07:00
parent 3aeab88384
commit 0392de1920
33 changed files with 1278 additions and 1030 deletions

View File

@ -35,7 +35,7 @@ public class Compare
string[] segments;
_AppSettings = appSettings;
if (appSettings.MaxDegreeOfParallelism is null)
throw new ArgumentNullException(nameof(appSettings.MaxDegreeOfParallelism));
throw new NullReferenceException(nameof(appSettings.MaxDegreeOfParallelism));
_RenameFindReplace = new();
_RenameBFindReplace = new();
_RenameCFindReplace = new();
@ -55,8 +55,9 @@ public class Compare
bool reverse = false;
Model? model = null;
PredictorModel? predictorModel = null;
PropertyLogic propertyLogic = GetPropertyLogic(reverse, model, predictorModel);
if (propertyConfiguration.PopulatePropertyId is null)
throw new ArgumentNullException(nameof(propertyConfiguration.PopulatePropertyId));
throw new NullReferenceException(nameof(propertyConfiguration.PopulatePropertyId));
foreach (string spelling in configuration.Spelling)
{
segments = spelling.Split('|');
@ -104,10 +105,10 @@ public class Compare
throw new Exception("Change configuration!");
_RenameCFindReplace.Add(new(renameFrom, renameTo));
}
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, reverse: false);
groupCollection = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
if (appSettings.MaxDegreeOfParallelism.Value < 2)
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.A_Property.GetGroupCollection));
_Log.Information($"{nameof(Property.Models.Stateless.A_Property.GetGroupCollection)} has finished");
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
_Log.Information($"{nameof(Property.Models.Stateless.Container.GetGroupCollection)} has finished");
_Configuration = configuration;
List<string> missingVerifyToSeasonCollection = GetMissingVerifyToSeasonCollection(topDirectories, groupCollection);
if (missingVerifyToSeasonCollection.Any())
@ -116,36 +117,36 @@ public class Compare
{
topDirectories.Clear();
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, reverse: false);
groupCollection = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
if (appSettings.MaxDegreeOfParallelism.Value < 2)
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.A_Property.GetGroupCollection));
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
}
_Log.Information($"{nameof(PossiblyRename)} has finished");
if (PossiblyRenameB(topDirectories, groupCollection))
{
topDirectories.Clear();
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, reverse: false);
groupCollection = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
if (appSettings.MaxDegreeOfParallelism.Value < 2)
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.A_Property.GetGroupCollection));
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
}
_Log.Information($"{nameof(PossiblyRenameB)} has finished");
if (PossiblyRenameC(topDirectories, groupCollection))
{
topDirectories.Clear();
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, reverse: false);
groupCollection = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
if (appSettings.MaxDegreeOfParallelism.Value < 2)
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.A_Property.GetGroupCollection));
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
}
_Log.Information($"{nameof(PossiblyRenameC)} has finished");
if (PossiblyCorrect(topDirectories, groupCollection))
{
topDirectories.Clear();
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, reverse: false);
groupCollection = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
if (appSettings.MaxDegreeOfParallelism.Value < 2)
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.A_Property.GetGroupCollection));
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
}
_Log.Information($"{nameof(PossiblyCorrect)} has finished");
string[] dbFiles = Directory.GetFiles(propertyConfiguration.RootDirectory, "*.db", SearchOption.AllDirectories);
@ -156,14 +157,13 @@ public class Compare
{
topDirectories.Clear();
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, reverse: false);
groupCollection = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
if (appSettings.MaxDegreeOfParallelism.Value < 2)
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.A_Property.GetGroupCollection));
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
}
PropertyLogic propertyLogic = GetPropertyLogic();
if (_IsEnvironment.Development && propertyConfiguration.PopulatePropertyId.Value && !propertyLogic.KeyValuePairs.Any())
throw new Exception("Copy keyValuePairs-####.json file");
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 (!isSilent)
{
_Log.Information("First pass completed");
@ -205,7 +205,7 @@ public class Compare
_Log.Information(". . .");
}
string aPropertyContentCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(A_Property), "[()]");
ThirdPassToMove(propertyConfiguration, model, predictorModel, propertyLogic, propertyHolderCollections, aPropertyContentCollectionDirectory);
ThirdPassToMove(propertyConfiguration, model, predictorModel, propertyLogic, containers, aPropertyContentCollectionDirectory);
if (!isSilent)
{
_Log.Information("Third pass completed");
@ -217,7 +217,7 @@ public class Compare
}
_Log.Information(". . .");
}
FourthPassCreateWindowsShortcuts(propertyConfiguration, model, predictorModel, propertyLogic, propertyHolderCollections, saveToCollection: false, keepAll: false);
FourthPassCreateWindowsShortcuts(propertyConfiguration, model, predictorModel, propertyLogic, containers, saveToCollection: false, keepAll: false);
if (!isSilent)
{
_Log.Information("Fourth pass completed");
@ -372,28 +372,28 @@ public class Compare
private static void Verify(Models.Configuration configuration)
{
if (configuration.Spelling is null || !configuration.Spelling.Any())
throw new ArgumentNullException(nameof(configuration.Spelling));
throw new NullReferenceException(nameof(configuration.Spelling));
}
private long LogDelta(long ticks, string methodName)
{
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;
return result;
}
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);
string fromPrepareForOld = "34720-637858334555170379.tsv";
string fromPrepareForOldFile = Path.Combine(_Configuration.PropertyConfiguration.RootDirectory, fromPrepareForOld);
if (File.Exists(fromPrepareForOldFile))
@ -432,11 +432,11 @@ public class Compare
private void SaveDiffFilesOrSaveLogAndMoveFiles(Property.Models.Configuration configuration)
{
if (_Log is null)
throw new ArgumentNullException(nameof(_Log));
throw new NullReferenceException(nameof(_Log));
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));
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
_Log.Information(aPropertySingletonDirectory);
_Log.Information("to");
@ -510,14 +510,14 @@ public class Compare
private void ChangeExtensionFromDeleteToJson(string aPropertySingletonDirectory)
{
if (_AppSettings.MaxDegreeOfParallelism is null)
throw new ArgumentNullException(nameof(_AppSettings.MaxDegreeOfParallelism));
throw new NullReferenceException(nameof(_AppSettings.MaxDegreeOfParallelism));
string searchPattern = "*.delete";
long ticks = DateTime.Now.Ticks;
List<string> topDirectories = new();
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> groupCollection;
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(aPropertySingletonDirectory, searchPattern, topDirectories);
groupCollection = Property.Models.Stateless.Container.GetGroupCollection(aPropertySingletonDirectory, searchPattern, topDirectories);
if (_AppSettings.MaxDegreeOfParallelism.Value < 2)
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.A_Property.GetGroupCollection));
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles, int r) in groupCollection)
{
if (!topDirectories.Any())
@ -647,7 +647,7 @@ public class Compare
private bool PossiblyCorrect(List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> groupCollection)
{
if (_Configuration?.PropertyConfiguration is null)
throw new ArgumentNullException(nameof(_Configuration.PropertyConfiguration));
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
bool result = false;
string corrected;
string correctedMoveTo;
@ -695,7 +695,7 @@ public class Compare
private List<string> GetMissingVerifyToSeasonCollection(List<string> _, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> groupCollection)
{
if (_Configuration?.PropertyConfiguration is null)
throw new ArgumentNullException(nameof(_Configuration.PropertyConfiguration));
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
List<string> results = new();
string check;
foreach ((int _, string sourceDirectory, string[] _, int _) in groupCollection)
@ -715,7 +715,7 @@ public class Compare
private void CreateWindowsShortcuts((long Ticks, string FilteredSourceDirectoryFile, string PropertyDirectory, int PropertyId)[] collection, bool keepAll)
{
if (_Log is null)
throw new ArgumentNullException(nameof(_Log));
throw new NullReferenceException(nameof(_Log));
int z = 0;
string fileName;
WindowsShortcut windowsShortcut;
@ -750,12 +750,12 @@ public class Compare
}
}
private void ThirdPassToMove(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, PropertyLogic propertyLogic, List<PropertyHolder[]> propertyHolderCollections, string aPropertyContentCollectionDirectory)
private void ThirdPassToMove(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, PropertyLogic propertyLogic, List<Container> containers, string aPropertyContentCollectionDirectory)
{
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));
int stay = 0;
string fileName;
string id = " - Id";
@ -769,7 +769,7 @@ public class Compare
List<string> distinctDirectories = new();
List<KeyValuePair<int, int[]>> valueCollection = new();
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
propertyLogic.ParallelWork(configuration, model, predictorModel, ticks, propertyHolderCollections, firstPass: false);
propertyLogic.ParallelWork(ticks, containers, firstPass: false);
if (propertyLogic.ExceptionsDirectories.Any())
throw new Exception();
foreach (Property.Models.DirectoryInfo group in directoryInfoCollection)
@ -828,10 +828,10 @@ public class Compare
}
}
private void FourthPassCreateWindowsShortcuts(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, PropertyLogic propertyLogic, List<PropertyHolder[]> propertyHolderCollections, bool saveToCollection, bool keepAll)
private void FourthPassCreateWindowsShortcuts(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, PropertyLogic propertyLogic, List<Container> containers, bool saveToCollection, bool keepAll)
{
if (_Log is null)
throw new ArgumentNullException(nameof(_Log));
throw new NullReferenceException(nameof(_Log));
int stay = 0;
A_Property? property;
ConsoleKey? consoleKey = null;
@ -841,7 +841,7 @@ public class Compare
List<KeyValuePair<int, int[]>> valueCollection = new();
(long Ticks, string FilteredSourceDirectoryFile, string PropertyDirectory, int PropertyId)[] collection;
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
propertyLogic.ParallelWork(configuration, model, predictorModel, ticks, propertyHolderCollections, firstPass: false);
propertyLogic.ParallelWork(ticks, containers, firstPass: false);
if (propertyLogic.ExceptionsDirectories.Any())
throw new Exception();
foreach (Property.Models.DirectoryInfo group in directoryInfoCollection)
@ -859,7 +859,7 @@ public class Compare
fileMoveCollection.Add(filteredSourceDirectoryFile);
}
}
collection = propertyLogic.GetPropertyIds(configuration, model, predictorModel, directoryInfoCollection, saveToCollection);
collection = propertyLogic.GetPropertyIds(directoryInfoCollection, saveToCollection);
_Log.Information($"{stay} file(s) are staying and {fileMoveCollection.Count} file(s) will be moved");
for (int x = 0; x < int.MaxValue; x++)
{