Ready to test
This commit is contained in:
@ -14,8 +14,6 @@ public class Compare
|
||||
|
||||
private readonly Serilog.ILogger? _Log;
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly List<string> _Exceptions;
|
||||
private readonly string[] _VerifyToSeason;
|
||||
private readonly IsEnvironment _IsEnvironment;
|
||||
private readonly Models.Configuration _Configuration;
|
||||
private readonly List<KeyValuePair<string, string>> _FileKeyValuePairs;
|
||||
@ -42,20 +40,20 @@ public class Compare
|
||||
_RenameCFindReplace = new();
|
||||
_SpellingFindReplace = new();
|
||||
_IsEnvironment = isEnvironment;
|
||||
_Exceptions = new List<string>();
|
||||
_Log = Serilog.Log.ForContext<Compare>();
|
||||
_FileKeyValuePairs = new List<KeyValuePair<string, string>>();
|
||||
_FilePropertiesKeyValuePairs = new Dictionary<string, List<Tuple<string, A_Property>>>();
|
||||
string message;
|
||||
string searchPattern = "*";
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
List<string> topDirectories = new();
|
||||
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> groupCollection;
|
||||
Property.Models.Configuration propertyConfiguration = Property.Models.Stateless.Configuration.Get(isEnvironment, configurationRoot, workingDirectory);
|
||||
Property.Models.Configuration.Verify(propertyConfiguration);
|
||||
Models.Configuration configuration = Models.Stateless.Configuration.Get(isEnvironment, configurationRoot, workingDirectory, propertyConfiguration);
|
||||
Models.Configuration configuration = Models.Stateless.Configuration.Get(isEnvironment, configurationRoot, workingDirectory, propertyConfiguration);
|
||||
Verify(configuration);
|
||||
if (propertyConfiguration.MaxImagesInDirectoryForTopLevelFirstPass is null)
|
||||
throw new Exception($"{nameof(propertyConfiguration.MaxImagesInDirectoryForTopLevelFirstPass)} is null!");
|
||||
bool reverse = false;
|
||||
string modelName = nameof(modelName);
|
||||
string predictorModelName = nameof(predictorModelName);
|
||||
if (propertyConfiguration.PopulatePropertyId is null)
|
||||
throw new Exception($"{nameof(propertyConfiguration.PopulatePropertyId)} is null!");
|
||||
foreach (string spelling in configuration.Spelling)
|
||||
@ -105,11 +103,11 @@ public class Compare
|
||||
throw new Exception("Change configuration!");
|
||||
_RenameCFindReplace.Add(new(renameFrom, renameTo));
|
||||
}
|
||||
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, propertyConfiguration.MaxImagesInDirectoryForTopLevelFirstPass.Value, reverse: false);
|
||||
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, reverse: false);
|
||||
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");
|
||||
_VerifyToSeason = propertyConfiguration.VerifyToSeason.Select(l => Path.Combine(propertyConfiguration.RootDirectory, l)).ToArray();
|
||||
_Configuration = configuration;
|
||||
List<string> missingVerifyToSeasonCollection = GetMissingVerifyToSeasonCollection(topDirectories, groupCollection);
|
||||
if (missingVerifyToSeasonCollection.Any())
|
||||
throw new Exception($"Update configuration with the following {Environment.NewLine} {string.Join(Environment.NewLine, missingVerifyToSeasonCollection)}");
|
||||
@ -117,7 +115,7 @@ public class Compare
|
||||
{
|
||||
topDirectories.Clear();
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, propertyConfiguration.MaxImagesInDirectoryForTopLevelFirstPass.Value, reverse: false);
|
||||
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, reverse: false);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.A_Property.GetGroupCollection));
|
||||
}
|
||||
@ -126,7 +124,7 @@ public class Compare
|
||||
{
|
||||
topDirectories.Clear();
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, propertyConfiguration.MaxImagesInDirectoryForTopLevelFirstPass.Value, reverse: false);
|
||||
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, reverse: false);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.A_Property.GetGroupCollection));
|
||||
}
|
||||
@ -135,7 +133,7 @@ public class Compare
|
||||
{
|
||||
topDirectories.Clear();
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, propertyConfiguration.MaxImagesInDirectoryForTopLevelFirstPass.Value, reverse: false);
|
||||
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, reverse: false);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.A_Property.GetGroupCollection));
|
||||
}
|
||||
@ -144,7 +142,7 @@ public class Compare
|
||||
{
|
||||
topDirectories.Clear();
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, propertyConfiguration.MaxImagesInDirectoryForTopLevelFirstPass.Value, reverse: false);
|
||||
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, reverse: false);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.A_Property.GetGroupCollection));
|
||||
}
|
||||
@ -157,20 +155,14 @@ public class Compare
|
||||
{
|
||||
topDirectories.Clear();
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, propertyConfiguration.MaxImagesInDirectoryForTopLevelFirstPass.Value, reverse: false);
|
||||
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, reverse: false);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.A_Property.GetGroupCollection));
|
||||
}
|
||||
PropertyLogic propertyLogic = GetPropertyLogic();
|
||||
if (_IsEnvironment.Development && propertyConfiguration.PopulatePropertyId.Value && !propertyLogic.IndicesFromOld.Any())
|
||||
throw new Exception("Copy keyValuePairs-####.json file");
|
||||
_Exceptions.AddRange(propertyLogic.DoWork(propertyConfiguration, topDirectories, groupCollection, firstPass: true));
|
||||
message = $"There were {_Exceptions.Count} exception(s) thrown! {Environment.NewLine}{string.Join(Environment.NewLine, _Exceptions)}";
|
||||
_Log.Information(message);
|
||||
if (_Exceptions.Count != 0)
|
||||
throw new Exception(message);
|
||||
if (appSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
ticks = LogDelta(ticks, nameof(PropertyLogic.DoWork));
|
||||
List<PropertyHolder[]> propertyHolderCollections = Property.Models.Stateless.A_Property.Get(propertyConfiguration, reverse, modelName, predictorModelName, propertyLogic);
|
||||
if (!isSilent)
|
||||
{
|
||||
_Log.Information("First pass completed");
|
||||
@ -182,10 +174,9 @@ public class Compare
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
}
|
||||
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(A_Property), "{}");
|
||||
string aPropertyContentCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(A_Property), "[()]");
|
||||
if (!isSilent)
|
||||
{
|
||||
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(A_Property), "{}");
|
||||
if (Directory.Exists(aPropertySingletonDirectory))
|
||||
{
|
||||
ConsoleKey? consoleKey = null;
|
||||
@ -199,37 +190,8 @@ public class Compare
|
||||
_Log.Information(". . .");
|
||||
if (consoleKey == ConsoleKey.Y)
|
||||
ChangeExtensionFromDeleteToJson(aPropertySingletonDirectory);
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
_Log.Information($"Execute {nameof(Property.Models.Stateless.A_Property.SearchForAbandonedFilesFull)} \"Y(es)\" or \"N(o)\"?");
|
||||
consoleKey = Console.ReadKey().Key;
|
||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||
break;
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
if (consoleKey == ConsoleKey.Y)
|
||||
{
|
||||
Property.Models.Stateless.A_Property.SearchForAbandonedFilesFull(propertyConfiguration.RootDirectory, aPropertySingletonDirectory, onlyJson: false);
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
_Log.Information($"Execute {nameof(Property.Models.Stateless.IPath.DeleteEmptyDirectories)} \"Y(es)\" or \"N(o)\"?");
|
||||
consoleKey = Console.ReadKey().Key;
|
||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||
break;
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
_ = Property.Models.Stateless.IPath.DeleteEmptyDirectories(aPropertySingletonDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
topDirectories.Clear();
|
||||
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories, propertyConfiguration.MaxImagesInDirectoryForTopLevelFirstPass.Value, reverse: false);
|
||||
_Exceptions.AddRange(propertyLogic.DoWork(propertyConfiguration, topDirectories, groupCollection, firstPass: false));
|
||||
message = $"There were {_Exceptions.Count} exception(s) thrown! {Environment.NewLine}{string.Join(Environment.NewLine, _Exceptions)}";
|
||||
_Log.Information(message);
|
||||
if (_Exceptions.Count != 0)
|
||||
throw new Exception(message);
|
||||
if (!isSilent)
|
||||
{
|
||||
_Log.Information("Second pass completed");
|
||||
@ -241,7 +203,8 @@ public class Compare
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
}
|
||||
ThirdPassToMove(propertyLogic, propertyConfiguration, aPropertyContentCollectionDirectory, topDirectories, groupCollection);
|
||||
string aPropertyContentCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(A_Property), "[()]");
|
||||
ThirdPassToMove(propertyConfiguration, modelName, predictorModelName, propertyLogic, propertyHolderCollections, aPropertyContentCollectionDirectory);
|
||||
if (!isSilent)
|
||||
{
|
||||
_Log.Information("Third pass completed");
|
||||
@ -253,7 +216,7 @@ public class Compare
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
}
|
||||
FourthPassCreateWindowsShortcuts(propertyLogic, propertyConfiguration, topDirectories, groupCollection, saveToCollection: false, keepAll: false);
|
||||
FourthPassCreateWindowsShortcuts(propertyConfiguration, modelName, predictorModelName, propertyLogic, propertyHolderCollections, saveToCollection: false, keepAll: false);
|
||||
if (!isSilent)
|
||||
{
|
||||
_Log.Information("Fourth pass completed");
|
||||
@ -269,7 +232,6 @@ public class Compare
|
||||
string currentYearDirectory = Path.Combine(propertyConfiguration.RootDirectory, $". {DateTime.Now:yyyy}");
|
||||
if (!Directory.Exists(currentYearDirectory))
|
||||
_ = Directory.CreateDirectory(currentYearDirectory);
|
||||
_Configuration = configuration;
|
||||
}
|
||||
|
||||
private string GetRename(string renameA)
|
||||
@ -430,16 +392,16 @@ public class Compare
|
||||
throw new Exception($"{nameof(_AppSettings.MaxDegreeOfParallelism)} is null!");
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new Exception($"{nameof(_Configuration.PropertyConfiguration)} must be set!");
|
||||
result = new(_AppSettings.MaxDegreeOfParallelism.Value, _Configuration.PropertyConfiguration, _VerifyToSeason);
|
||||
string fromPerpareForOld = "34720-637858334555170379.tsv";
|
||||
string fromPerpareForOldFile = Path.Combine(_Configuration.PropertyConfiguration.RootDirectory, fromPerpareForOld);
|
||||
if (File.Exists(fromPerpareForOldFile))
|
||||
result = new(_AppSettings.MaxDegreeOfParallelism.Value, _Configuration.PropertyConfiguration);
|
||||
string fromPrepareForOld = "34720-637858334555170379.tsv";
|
||||
string fromPrepareForOldFile = Path.Combine(_Configuration.PropertyConfiguration.RootDirectory, fromPrepareForOld);
|
||||
if (File.Exists(fromPrepareForOldFile))
|
||||
{
|
||||
string[] lines;
|
||||
string[] columns;
|
||||
List<string> debug = new();
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
lines = File.ReadAllLines(fromPerpareForOldFile);
|
||||
lines = File.ReadAllLines(fromPrepareForOldFile);
|
||||
string resultsDirectory = $"{_Configuration.PropertyConfiguration.RootDirectory} - Results";
|
||||
int[]? zeros = (from l in result.IndicesFromNew where l.Value.Any() select l.Value[0]).ToArray();
|
||||
lines = (from l in result.IndicesFromNew select string.Concat(l.Key, '\t', string.Join('\t', l.Value))).ToArray();
|
||||
@ -461,7 +423,7 @@ public class Compare
|
||||
else
|
||||
debug.Add(propertyId.ToString());
|
||||
}
|
||||
File.WriteAllLines(Path.Combine(resultsDirectory, $"{ticks}-{fromPerpareForOld}"), debug);
|
||||
File.WriteAllLines(Path.Combine(resultsDirectory, $"{ticks}-{fromPrepareForOld}"), debug);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -551,7 +513,8 @@ public class Compare
|
||||
string searchPattern = "*.delete";
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
List<string> topDirectories = new();
|
||||
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(aPropertySingletonDirectory, searchPattern, topDirectories);
|
||||
List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> groupCollection;
|
||||
groupCollection = Property.Models.Stateless.A_Property.GetGroupCollection(aPropertySingletonDirectory, searchPattern, topDirectories);
|
||||
if (_AppSettings.MaxDegreeOfParallelism.Value < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.A_Property.GetGroupCollection));
|
||||
foreach ((int g, string sourceDirectory, string[] sourceDirectoryFiles, int r) in groupCollection)
|
||||
@ -786,7 +749,7 @@ public class Compare
|
||||
}
|
||||
}
|
||||
|
||||
private void ThirdPassToMove(PropertyLogic propertyLogic, Property.Models.Configuration configuration, string aPropertyContentCollectionDirectory, List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> groupCollection)
|
||||
private void ThirdPassToMove(Property.Models.Configuration configuration, string modelName, string predictorModelName, PropertyLogic propertyLogic, List<PropertyHolder[]> propertyHolderCollections, string aPropertyContentCollectionDirectory)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new Exception($"{nameof(_Log)} is null!");
|
||||
@ -798,14 +761,17 @@ public class Compare
|
||||
A_Property? property;
|
||||
string? directoryName;
|
||||
ConsoleKey? consoleKey = null;
|
||||
DateTime dateTime = DateTime.Now;
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
string filteredSourceDirectoryFile;
|
||||
List<string> fileStayCollection = new();
|
||||
List<string> fileMoveCollection = new();
|
||||
List<string> distinctDirectories = new();
|
||||
List<KeyValuePair<int, int[]>> valueCollection = new();
|
||||
List<Group> groupResultsCollection = propertyLogic.GetParallelWork(configuration, topDirectories, groupCollection, firstPass: false, filterOnFirstPass: false);
|
||||
foreach (Group group in groupResultsCollection)
|
||||
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
|
||||
propertyLogic.ParallelWork(configuration, modelName, predictorModelName, ticks, propertyHolderCollections, firstPass: false);
|
||||
if (propertyLogic.ExceptionsDirectories.Any())
|
||||
throw new Exception();
|
||||
foreach (Property.Models.DirectoryInfo group in directoryInfoCollection)
|
||||
{
|
||||
for (int i = 0; i < group.PropertyCollection.Length; i++)
|
||||
{
|
||||
@ -823,9 +789,9 @@ public class Compare
|
||||
string[] lines = (from l in valueCollection select string.Concat(l.Key, '\t', string.Join('\t', l.Value))).ToArray();
|
||||
if (!Directory.Exists(aPropertyContentCollectionDirectory))
|
||||
_ = Directory.CreateDirectory(aPropertyContentCollectionDirectory);
|
||||
File.WriteAllLines(Path.Combine(aPropertyContentCollectionDirectory, $"{dateTime.Ticks}.tsv"), lines);
|
||||
File.WriteAllLines(Path.Combine(aPropertyContentCollectionDirectory, $"{ticks}.tsv"), lines);
|
||||
string json = JsonSerializer.Serialize(valueCollection, new JsonSerializerOptions { WriteIndented = true });
|
||||
File.WriteAllText(Path.Combine(aPropertyContentCollectionDirectory, $"{dateTime.Ticks}.json"), json);
|
||||
File.WriteAllText(Path.Combine(aPropertyContentCollectionDirectory, $"{ticks}.json"), json);
|
||||
foreach (string fileMove in fileMoveCollection)
|
||||
{
|
||||
directoryName = Path.GetDirectoryName(string.Concat(_Configuration.PropertyConfiguration.RootDirectory, id, fileMove[_Configuration.PropertyConfiguration.RootDirectory.Length..]));
|
||||
@ -861,19 +827,23 @@ public class Compare
|
||||
}
|
||||
}
|
||||
|
||||
private void FourthPassCreateWindowsShortcuts(PropertyLogic propertyLogic, Property.Models.Configuration configuration, List<string> topDirectories, List<(int g, string sourceDirectory, string[] sourceDirectoryFiles, int r)> groupCollection, bool saveToCollection, bool keepAll)
|
||||
private void FourthPassCreateWindowsShortcuts(Property.Models.Configuration configuration, string modelName, string predictorModelName, PropertyLogic propertyLogic, List<PropertyHolder[]> propertyHolderCollections, bool saveToCollection, bool keepAll)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new Exception($"{nameof(_Log)} is null!");
|
||||
int stay = 0;
|
||||
A_Property? property;
|
||||
ConsoleKey? consoleKey = null;
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
string filteredSourceDirectoryFile;
|
||||
List<string> fileMoveCollection = new();
|
||||
List<KeyValuePair<int, int[]>> valueCollection = new();
|
||||
(long Ticks, string FilteredSourceDirectoryFile, string PropertyDirectory, int PropertyId)[] collection;
|
||||
List<Group> groupResultsCollection = propertyLogic.GetParallelWork(configuration, topDirectories, groupCollection, firstPass: false, filterOnFirstPass: false);
|
||||
foreach (Group group in groupResultsCollection)
|
||||
List<Property.Models.DirectoryInfo> directoryInfoCollection = new();
|
||||
propertyLogic.ParallelWork(configuration, modelName, predictorModelName, ticks, propertyHolderCollections, firstPass: false);
|
||||
if (propertyLogic.ExceptionsDirectories.Any())
|
||||
throw new Exception();
|
||||
foreach (Property.Models.DirectoryInfo group in directoryInfoCollection)
|
||||
{
|
||||
for (int i = 0; i < group.PropertyCollection.Length; i++)
|
||||
{
|
||||
@ -888,7 +858,7 @@ public class Compare
|
||||
fileMoveCollection.Add(filteredSourceDirectoryFile);
|
||||
}
|
||||
}
|
||||
collection = propertyLogic.GetPropertyIds(configuration, groupResultsCollection, saveToCollection);
|
||||
collection = propertyLogic.GetPropertyIds(configuration, modelName, predictorModelName, 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++)
|
||||
{
|
||||
|
Reference in New Issue
Block a user