Serilog
This commit is contained in:
@ -12,7 +12,6 @@ namespace View_by_Distance.Compare;
|
||||
public class Compare
|
||||
{
|
||||
|
||||
private readonly Serilog.ILogger? _Log;
|
||||
private readonly AppSettings _AppSettings;
|
||||
private readonly IsEnvironment _IsEnvironment;
|
||||
private readonly Models.Configuration _Configuration;
|
||||
@ -38,7 +37,6 @@ public class Compare
|
||||
_RenameCFindReplace = new();
|
||||
_SpellingFindReplace = new();
|
||||
_IsEnvironment = isEnvironment;
|
||||
_Log = Serilog.Log.ForContext<Compare>();
|
||||
_FileKeyValuePairs = new List<KeyValuePair<string, string>>();
|
||||
_FilePropertiesKeyValuePairs = new Dictionary<string, List<Tuple<string, Shared.Models.Property>>>();
|
||||
string searchPattern = "*";
|
||||
@ -107,7 +105,7 @@ public class Compare
|
||||
(_, groupCollection) = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
||||
_Log.Information($"{nameof(Property.Models.Stateless.Container.GetGroupCollection)} has finished");
|
||||
_Logger?.LogInformation($"{nameof(Property.Models.Stateless.Container.GetGroupCollection)} has finished");
|
||||
_Configuration = configuration;
|
||||
List<string> missingVerifyToSeasonCollection = GetMissingVerifyToSeasonCollection(topDirectories, groupCollection);
|
||||
if (missingVerifyToSeasonCollection.Any())
|
||||
@ -120,7 +118,7 @@ public class Compare
|
||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
||||
}
|
||||
_Log.Information($"{nameof(PossiblyRename)} has finished");
|
||||
_Logger?.LogInformation($"{nameof(PossiblyRename)} has finished");
|
||||
if (PossiblyRenameB(topDirectories, groupCollection))
|
||||
{
|
||||
topDirectories.Clear();
|
||||
@ -129,7 +127,7 @@ public class Compare
|
||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
||||
}
|
||||
_Log.Information($"{nameof(PossiblyRenameB)} has finished");
|
||||
_Logger?.LogInformation($"{nameof(PossiblyRenameB)} has finished");
|
||||
if (PossiblyRenameC(topDirectories, groupCollection))
|
||||
{
|
||||
topDirectories.Clear();
|
||||
@ -138,7 +136,7 @@ public class Compare
|
||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
||||
}
|
||||
_Log.Information($"{nameof(PossiblyRenameC)} has finished");
|
||||
_Logger?.LogInformation($"{nameof(PossiblyRenameC)} has finished");
|
||||
if (PossiblyCorrect(topDirectories, groupCollection))
|
||||
{
|
||||
topDirectories.Clear();
|
||||
@ -147,11 +145,11 @@ public class Compare
|
||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
||||
}
|
||||
_Log.Information($"{nameof(PossiblyCorrect)} has finished");
|
||||
_Logger?.LogInformation($"{nameof(PossiblyCorrect)} has finished");
|
||||
string[] dbFiles = Directory.GetFiles(propertyConfiguration.RootDirectory, "*.db", SearchOption.AllDirectories);
|
||||
foreach (string dbFile in dbFiles)
|
||||
File.Delete(dbFile);
|
||||
_Log.Information("deleting *.db files has finished");
|
||||
_Logger?.LogInformation("deleting *.db files has finished");
|
||||
if (dbFiles.Any())
|
||||
{
|
||||
topDirectories.Clear();
|
||||
@ -175,14 +173,14 @@ public class Compare
|
||||
}
|
||||
if (!isSilent)
|
||||
{
|
||||
_Log.Information("First pass completed");
|
||||
_Logger?.LogInformation("First pass completed");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
_Log.Information("Press \"Y\" key to continue or close console if compare not needed");
|
||||
_Logger?.LogInformation("Press \"Y\" key to continue or close console if compare not needed");
|
||||
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||
break;
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
_Logger?.LogInformation(". . .");
|
||||
}
|
||||
if (!isSilent)
|
||||
{
|
||||
@ -192,51 +190,51 @@ public class Compare
|
||||
ConsoleKey? consoleKey = null;
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
_Log.Information($"Execute {nameof(ChangeExtensionFromDeleteToJson)} \"Y(es)\" or \"N(o)\"?");
|
||||
_Logger?.LogInformation($"Execute {nameof(ChangeExtensionFromDeleteToJson)} \"Y(es)\" or \"N(o)\"?");
|
||||
consoleKey = Console.ReadKey().Key;
|
||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||
break;
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
_Logger?.LogInformation(". . .");
|
||||
if (consoleKey == ConsoleKey.Y)
|
||||
ChangeExtensionFromDeleteToJson(aPropertySingletonDirectory);
|
||||
}
|
||||
}
|
||||
if (!isSilent)
|
||||
{
|
||||
_Log.Information("Second pass completed");
|
||||
_Logger?.LogInformation("Second pass completed");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
_Log.Information("Press \"Y\" key to continue or close console if compare not needed");
|
||||
_Logger?.LogInformation("Press \"Y\" key to continue or close console if compare not needed");
|
||||
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||
break;
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
_Logger?.LogInformation(". . .");
|
||||
}
|
||||
string aPropertyContentCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(A_Property), "[()]");
|
||||
ThirdPassToMove(propertyConfiguration, mapLogic, propertyLogic, containers, aPropertyContentCollectionDirectory);
|
||||
if (!isSilent)
|
||||
{
|
||||
_Log.Information("Third pass completed");
|
||||
_Logger?.LogInformation("Third pass completed");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
_Log.Information("Press \"Y\" key to continue or close console if compare not needed");
|
||||
_Logger?.LogInformation("Press \"Y\" key to continue or close console if compare not needed");
|
||||
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||
break;
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
_Logger?.LogInformation(". . .");
|
||||
}
|
||||
FourthPassCreateWindowsShortcuts(propertyConfiguration, mapLogic, propertyLogic, containers, saveToCollection: false, keepAll: false);
|
||||
if (!isSilent)
|
||||
{
|
||||
_Log.Information("Fourth pass completed");
|
||||
_Logger?.LogInformation("Fourth pass completed");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
_Log.Information("Press \"Y\" key to continue or close console if compare not needed");
|
||||
_Logger?.LogInformation("Press \"Y\" key to continue or close console if compare not needed");
|
||||
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||
break;
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
_Logger?.LogInformation(". . .");
|
||||
}
|
||||
SaveDiffFilesOrSaveLogAndMoveFiles(propertyConfiguration);
|
||||
string currentYearDirectory = Path.Combine(propertyConfiguration.RootDirectory, $". {DateTime.Now:yyyy}");
|
||||
@ -387,8 +385,6 @@ public class Compare
|
||||
private long LogDelta(long ticks, string? methodName)
|
||||
{
|
||||
long result;
|
||||
if (_Log is null)
|
||||
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;
|
||||
@ -438,21 +434,19 @@ public class Compare
|
||||
|
||||
private void SaveDiffFilesOrSaveLogAndMoveFiles(Property.Models.Configuration configuration)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new NullReferenceException(nameof(_Log));
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
|
||||
_Log.Information(aPropertySingletonDirectory);
|
||||
_Log.Information("to");
|
||||
_Log.Information(_Configuration.DiffPropertyDirectory);
|
||||
_Logger?.LogInformation(aPropertySingletonDirectory);
|
||||
_Logger?.LogInformation("to");
|
||||
_Logger?.LogInformation(_Configuration.DiffPropertyDirectory);
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
_Log.Information("Press \"Y\" key to continue or close console if compare not needed");
|
||||
_Logger?.LogInformation("Press \"Y\" key to continue or close console if compare not needed");
|
||||
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||
break;
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
_Logger?.LogInformation(". . .");
|
||||
int loadLessThan = 7;
|
||||
string diffRootDirectory;
|
||||
ConsoleKey? consoleKey = null;
|
||||
@ -486,27 +480,27 @@ public class Compare
|
||||
}
|
||||
for (int x = 0; x < int.MaxValue; x++)
|
||||
{
|
||||
_Log.Information($"Press \"D\" key to {nameof(PropertyCompare.Models.PropertyCompareLogic.SaveDiffFiles)}");
|
||||
_Log.Information($"Press \"M\" key to {nameof(PropertyCompare.Models.PropertyCompareLogic.SaveLogAndMoveFiles)}");
|
||||
_Log.Information("Press \"End\" key when ready to skip");
|
||||
_Logger?.LogInformation($"Press \"D\" key to {nameof(PropertyCompare.Models.PropertyCompareLogic.SaveDiffFiles)}");
|
||||
_Logger?.LogInformation($"Press \"M\" key to {nameof(PropertyCompare.Models.PropertyCompareLogic.SaveLogAndMoveFiles)}");
|
||||
_Logger?.LogInformation("Press \"End\" key when ready to skip");
|
||||
consoleKey = Console.ReadKey().Key;
|
||||
if (consoleKey is ConsoleKey.D or ConsoleKey.M or ConsoleKey.End)
|
||||
break;
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
_Logger?.LogInformation(". . .");
|
||||
if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.D)
|
||||
propertyCompareLogic.SaveDiffFiles(aPropertyCollectionDirectory, loadLessThan, propertyCompareCollection, diffPropertyCompareCollection);
|
||||
else if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.M)
|
||||
{
|
||||
for (int x = 0; x < int.MaxValue; x++)
|
||||
{
|
||||
_Log.Information($"Press \"0 - {loadLessThan}\" key when ready to continue");
|
||||
_Log.Information("Press \"End\" key when ready to skip");
|
||||
_Logger?.LogInformation($"Press \"0 - {loadLessThan}\" key when ready to continue");
|
||||
_Logger?.LogInformation("Press \"End\" key when ready to skip");
|
||||
consoleKey = Console.ReadKey().Key;
|
||||
if (consoleKey.Value is ConsoleKey.D0 or ConsoleKey.D1 or ConsoleKey.D2 or ConsoleKey.D3 or ConsoleKey.D4 or ConsoleKey.D5 or ConsoleKey.D6 or ConsoleKey.End)
|
||||
break;
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
_Logger?.LogInformation(". . .");
|
||||
int i = int.Parse(consoleKey.Value.ToString()[1..]);
|
||||
propertyCompareLogic.SaveLogAndMoveFiles(aPropertyCollectionDirectory, loadLessThan, propertyCompareCollection, diffPropertyCompareCollection, i);
|
||||
}
|
||||
@ -717,8 +711,6 @@ public class Compare
|
||||
|
||||
private void CreateWindowsShortcuts((long Ticks, string FilteredSourceDirectoryFile, string PropertyDirectory, int PropertyId)[] collection, bool keepAll)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new NullReferenceException(nameof(_Log));
|
||||
int z = 0;
|
||||
string fileName;
|
||||
WindowsShortcut windowsShortcut;
|
||||
@ -755,8 +747,6 @@ public class Compare
|
||||
|
||||
private void ThirdPassToMove(Property.Models.Configuration configuration, Map.Models.MapLogic mapLogic, A_Property propertyLogic, Shared.Models.Container[] containers, string aPropertyContentCollectionDirectory)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new NullReferenceException(nameof(_Log));
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
int stay = 0;
|
||||
@ -809,16 +799,16 @@ public class Compare
|
||||
if (!Directory.Exists(distinctDirectory))
|
||||
_ = Directory.CreateDirectory(distinctDirectory);
|
||||
}
|
||||
_Log.Information($"{stay} file(s) are staying and {fileMoveCollection.Count} file(s) will be moved");
|
||||
_Logger?.LogInformation($"{stay} file(s) are staying and {fileMoveCollection.Count} file(s) will be moved");
|
||||
for (int y = 0; y < int.MaxValue; y++)
|
||||
{
|
||||
_Log.Information($"Press \"M\" key to {nameof(File.Move)}");
|
||||
_Log.Information("Press \"End\" key when ready to skip or close console if compare not needed");
|
||||
_Logger?.LogInformation($"Press \"M\" key to {nameof(File.Move)}");
|
||||
_Logger?.LogInformation("Press \"End\" key when ready to skip or close console if compare not needed");
|
||||
consoleKey = Console.ReadKey().Key;
|
||||
if (consoleKey is ConsoleKey.M or ConsoleKey.End)
|
||||
break;
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
_Logger?.LogInformation(". . .");
|
||||
if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.M)
|
||||
{
|
||||
foreach (string fileMove in fileMoveCollection)
|
||||
@ -833,8 +823,6 @@ public class Compare
|
||||
|
||||
private void FourthPassCreateWindowsShortcuts(Property.Models.Configuration configuration, Map.Models.MapLogic mapLogic, A_Property propertyLogic, Shared.Models.Container[] containers, bool saveToCollection, bool keepAll)
|
||||
{
|
||||
if (_Log is null)
|
||||
throw new NullReferenceException(nameof(_Log));
|
||||
int stay = 0;
|
||||
ConsoleKey? consoleKey = null;
|
||||
long ticks = DateTime.Now.Ticks;
|
||||
@ -863,16 +851,16 @@ public class Compare
|
||||
}
|
||||
}
|
||||
collection = propertyLogic.GetPropertyIds(directoryInfoCollection, saveToCollection);
|
||||
_Log.Information($"{stay} file(s) are staying and {fileMoveCollection.Count} file(s) will be moved");
|
||||
_Logger?.LogInformation($"{stay} file(s) are staying and {fileMoveCollection.Count} file(s) will be moved");
|
||||
for (int x = 0; x < int.MaxValue; x++)
|
||||
{
|
||||
_Log.Information($"Press \"S\" key to {nameof(CreateWindowsShortcuts)}");
|
||||
_Log.Information("Press \"End\" key when ready to skip or close console if compare not needed");
|
||||
_Logger?.LogInformation($"Press \"S\" key to {nameof(CreateWindowsShortcuts)}");
|
||||
_Logger?.LogInformation("Press \"End\" key when ready to skip or close console if compare not needed");
|
||||
consoleKey = Console.ReadKey().Key;
|
||||
if (consoleKey is ConsoleKey.M or ConsoleKey.End)
|
||||
break;
|
||||
}
|
||||
_Log.Information(". . .");
|
||||
_Logger?.LogInformation(". . .");
|
||||
if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.S)
|
||||
CreateWindowsShortcuts(collection, keepAll);
|
||||
}
|
||||
|
Reference in New Issue
Block a user