Serilog
This commit is contained in:
parent
cd5ab223c9
commit
37b7ad2a1f
@ -33,7 +33,6 @@
|
|||||||
<SupportedPlatform Include="browser" />
|
<SupportedPlatform Include="browser" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -12,7 +12,6 @@ namespace View_by_Distance.Compare;
|
|||||||
public class Compare
|
public class Compare
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly Serilog.ILogger? _Log;
|
|
||||||
private readonly AppSettings _AppSettings;
|
private readonly AppSettings _AppSettings;
|
||||||
private readonly IsEnvironment _IsEnvironment;
|
private readonly IsEnvironment _IsEnvironment;
|
||||||
private readonly Models.Configuration _Configuration;
|
private readonly Models.Configuration _Configuration;
|
||||||
@ -38,7 +37,6 @@ public class Compare
|
|||||||
_RenameCFindReplace = new();
|
_RenameCFindReplace = new();
|
||||||
_SpellingFindReplace = new();
|
_SpellingFindReplace = new();
|
||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
_Log = Serilog.Log.ForContext<Compare>();
|
|
||||||
_FileKeyValuePairs = new List<KeyValuePair<string, string>>();
|
_FileKeyValuePairs = new List<KeyValuePair<string, string>>();
|
||||||
_FilePropertiesKeyValuePairs = new Dictionary<string, List<Tuple<string, Shared.Models.Property>>>();
|
_FilePropertiesKeyValuePairs = new Dictionary<string, List<Tuple<string, Shared.Models.Property>>>();
|
||||||
string searchPattern = "*";
|
string searchPattern = "*";
|
||||||
@ -107,7 +105,7 @@ public class Compare
|
|||||||
(_, groupCollection) = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
(_, groupCollection) = Property.Models.Stateless.Container.GetGroupCollection(propertyConfiguration.RootDirectory, searchPattern, topDirectories);
|
||||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
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;
|
_Configuration = configuration;
|
||||||
List<string> missingVerifyToSeasonCollection = GetMissingVerifyToSeasonCollection(topDirectories, groupCollection);
|
List<string> missingVerifyToSeasonCollection = GetMissingVerifyToSeasonCollection(topDirectories, groupCollection);
|
||||||
if (missingVerifyToSeasonCollection.Any())
|
if (missingVerifyToSeasonCollection.Any())
|
||||||
@ -120,7 +118,7 @@ public class Compare
|
|||||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
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))
|
if (PossiblyRenameB(topDirectories, groupCollection))
|
||||||
{
|
{
|
||||||
topDirectories.Clear();
|
topDirectories.Clear();
|
||||||
@ -129,7 +127,7 @@ public class Compare
|
|||||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
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))
|
if (PossiblyRenameC(topDirectories, groupCollection))
|
||||||
{
|
{
|
||||||
topDirectories.Clear();
|
topDirectories.Clear();
|
||||||
@ -138,7 +136,7 @@ public class Compare
|
|||||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
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))
|
if (PossiblyCorrect(topDirectories, groupCollection))
|
||||||
{
|
{
|
||||||
topDirectories.Clear();
|
topDirectories.Clear();
|
||||||
@ -147,11 +145,11 @@ public class Compare
|
|||||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
if (appSettings.MaxDegreeOfParallelism < 2)
|
||||||
ticks = LogDelta(ticks, nameof(Property.Models.Stateless.Container.GetGroupCollection));
|
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);
|
string[] dbFiles = Directory.GetFiles(propertyConfiguration.RootDirectory, "*.db", SearchOption.AllDirectories);
|
||||||
foreach (string dbFile in dbFiles)
|
foreach (string dbFile in dbFiles)
|
||||||
File.Delete(dbFile);
|
File.Delete(dbFile);
|
||||||
_Log.Information("deleting *.db files has finished");
|
_Logger?.LogInformation("deleting *.db files has finished");
|
||||||
if (dbFiles.Any())
|
if (dbFiles.Any())
|
||||||
{
|
{
|
||||||
topDirectories.Clear();
|
topDirectories.Clear();
|
||||||
@ -175,14 +173,14 @@ public class Compare
|
|||||||
}
|
}
|
||||||
if (!isSilent)
|
if (!isSilent)
|
||||||
{
|
{
|
||||||
_Log.Information("First pass completed");
|
_Logger?.LogInformation("First pass completed");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
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)
|
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Logger?.LogInformation(". . .");
|
||||||
}
|
}
|
||||||
if (!isSilent)
|
if (!isSilent)
|
||||||
{
|
{
|
||||||
@ -192,51 +190,51 @@ public class Compare
|
|||||||
ConsoleKey? consoleKey = null;
|
ConsoleKey? consoleKey = null;
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
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;
|
consoleKey = Console.ReadKey().Key;
|
||||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Logger?.LogInformation(". . .");
|
||||||
if (consoleKey == ConsoleKey.Y)
|
if (consoleKey == ConsoleKey.Y)
|
||||||
ChangeExtensionFromDeleteToJson(aPropertySingletonDirectory);
|
ChangeExtensionFromDeleteToJson(aPropertySingletonDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isSilent)
|
if (!isSilent)
|
||||||
{
|
{
|
||||||
_Log.Information("Second pass completed");
|
_Logger?.LogInformation("Second pass completed");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
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)
|
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Logger?.LogInformation(". . .");
|
||||||
}
|
}
|
||||||
string aPropertyContentCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(A_Property), "[()]");
|
string aPropertyContentCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(A_Property), "[()]");
|
||||||
ThirdPassToMove(propertyConfiguration, mapLogic, propertyLogic, containers, aPropertyContentCollectionDirectory);
|
ThirdPassToMove(propertyConfiguration, mapLogic, propertyLogic, containers, aPropertyContentCollectionDirectory);
|
||||||
if (!isSilent)
|
if (!isSilent)
|
||||||
{
|
{
|
||||||
_Log.Information("Third pass completed");
|
_Logger?.LogInformation("Third pass completed");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
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)
|
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Logger?.LogInformation(". . .");
|
||||||
}
|
}
|
||||||
FourthPassCreateWindowsShortcuts(propertyConfiguration, mapLogic, propertyLogic, containers, saveToCollection: false, keepAll: false);
|
FourthPassCreateWindowsShortcuts(propertyConfiguration, mapLogic, propertyLogic, containers, saveToCollection: false, keepAll: false);
|
||||||
if (!isSilent)
|
if (!isSilent)
|
||||||
{
|
{
|
||||||
_Log.Information("Fourth pass completed");
|
_Logger?.LogInformation("Fourth pass completed");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
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)
|
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Logger?.LogInformation(". . .");
|
||||||
}
|
}
|
||||||
SaveDiffFilesOrSaveLogAndMoveFiles(propertyConfiguration);
|
SaveDiffFilesOrSaveLogAndMoveFiles(propertyConfiguration);
|
||||||
string currentYearDirectory = Path.Combine(propertyConfiguration.RootDirectory, $". {DateTime.Now:yyyy}");
|
string currentYearDirectory = Path.Combine(propertyConfiguration.RootDirectory, $". {DateTime.Now:yyyy}");
|
||||||
@ -387,8 +385,6 @@ public class Compare
|
|||||||
private long LogDelta(long ticks, string? methodName)
|
private long LogDelta(long ticks, string? methodName)
|
||||||
{
|
{
|
||||||
long result;
|
long result;
|
||||||
if (_Log is null)
|
|
||||||
throw new NullReferenceException(nameof(_Log));
|
|
||||||
double delta = new TimeSpan(DateTime.Now.Ticks - ticks).TotalMilliseconds;
|
double delta = new TimeSpan(DateTime.Now.Ticks - ticks).TotalMilliseconds;
|
||||||
_Log.Debug($"{methodName} took {Math.Floor(delta)} millisecond(s)");
|
_Log.Debug($"{methodName} took {Math.Floor(delta)} millisecond(s)");
|
||||||
result = DateTime.Now.Ticks;
|
result = DateTime.Now.Ticks;
|
||||||
@ -438,21 +434,19 @@ public class Compare
|
|||||||
|
|
||||||
private void SaveDiffFilesOrSaveLogAndMoveFiles(Property.Models.Configuration configuration)
|
private void SaveDiffFilesOrSaveLogAndMoveFiles(Property.Models.Configuration configuration)
|
||||||
{
|
{
|
||||||
if (_Log is null)
|
|
||||||
throw new NullReferenceException(nameof(_Log));
|
|
||||||
if (_Configuration?.PropertyConfiguration is null)
|
if (_Configuration?.PropertyConfiguration is null)
|
||||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||||
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
|
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(A_Property), "{}");
|
||||||
_Log.Information(aPropertySingletonDirectory);
|
_Logger?.LogInformation(aPropertySingletonDirectory);
|
||||||
_Log.Information("to");
|
_Logger?.LogInformation("to");
|
||||||
_Log.Information(_Configuration.DiffPropertyDirectory);
|
_Logger?.LogInformation(_Configuration.DiffPropertyDirectory);
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
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)
|
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Logger?.LogInformation(". . .");
|
||||||
int loadLessThan = 7;
|
int loadLessThan = 7;
|
||||||
string diffRootDirectory;
|
string diffRootDirectory;
|
||||||
ConsoleKey? consoleKey = null;
|
ConsoleKey? consoleKey = null;
|
||||||
@ -486,27 +480,27 @@ public class Compare
|
|||||||
}
|
}
|
||||||
for (int x = 0; x < int.MaxValue; x++)
|
for (int x = 0; x < int.MaxValue; x++)
|
||||||
{
|
{
|
||||||
_Log.Information($"Press \"D\" key to {nameof(PropertyCompare.Models.PropertyCompareLogic.SaveDiffFiles)}");
|
_Logger?.LogInformation($"Press \"D\" key to {nameof(PropertyCompare.Models.PropertyCompareLogic.SaveDiffFiles)}");
|
||||||
_Log.Information($"Press \"M\" key to {nameof(PropertyCompare.Models.PropertyCompareLogic.SaveLogAndMoveFiles)}");
|
_Logger?.LogInformation($"Press \"M\" key to {nameof(PropertyCompare.Models.PropertyCompareLogic.SaveLogAndMoveFiles)}");
|
||||||
_Log.Information("Press \"End\" key when ready to skip");
|
_Logger?.LogInformation("Press \"End\" key when ready to skip");
|
||||||
consoleKey = Console.ReadKey().Key;
|
consoleKey = Console.ReadKey().Key;
|
||||||
if (consoleKey is ConsoleKey.D or ConsoleKey.M or ConsoleKey.End)
|
if (consoleKey is ConsoleKey.D or ConsoleKey.M or ConsoleKey.End)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Logger?.LogInformation(". . .");
|
||||||
if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.D)
|
if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.D)
|
||||||
propertyCompareLogic.SaveDiffFiles(aPropertyCollectionDirectory, loadLessThan, propertyCompareCollection, diffPropertyCompareCollection);
|
propertyCompareLogic.SaveDiffFiles(aPropertyCollectionDirectory, loadLessThan, propertyCompareCollection, diffPropertyCompareCollection);
|
||||||
else if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.M)
|
else if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.M)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < int.MaxValue; x++)
|
for (int x = 0; x < int.MaxValue; x++)
|
||||||
{
|
{
|
||||||
_Log.Information($"Press \"0 - {loadLessThan}\" key when ready to continue");
|
_Logger?.LogInformation($"Press \"0 - {loadLessThan}\" key when ready to continue");
|
||||||
_Log.Information("Press \"End\" key when ready to skip");
|
_Logger?.LogInformation("Press \"End\" key when ready to skip");
|
||||||
consoleKey = Console.ReadKey().Key;
|
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)
|
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;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Logger?.LogInformation(". . .");
|
||||||
int i = int.Parse(consoleKey.Value.ToString()[1..]);
|
int i = int.Parse(consoleKey.Value.ToString()[1..]);
|
||||||
propertyCompareLogic.SaveLogAndMoveFiles(aPropertyCollectionDirectory, loadLessThan, propertyCompareCollection, diffPropertyCompareCollection, i);
|
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)
|
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;
|
int z = 0;
|
||||||
string fileName;
|
string fileName;
|
||||||
WindowsShortcut windowsShortcut;
|
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)
|
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)
|
if (_Configuration?.PropertyConfiguration is null)
|
||||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||||
int stay = 0;
|
int stay = 0;
|
||||||
@ -809,16 +799,16 @@ public class Compare
|
|||||||
if (!Directory.Exists(distinctDirectory))
|
if (!Directory.Exists(distinctDirectory))
|
||||||
_ = Directory.CreateDirectory(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++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
_Log.Information($"Press \"M\" key to {nameof(File.Move)}");
|
_Logger?.LogInformation($"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 \"End\" key when ready to skip or close console if compare not needed");
|
||||||
consoleKey = Console.ReadKey().Key;
|
consoleKey = Console.ReadKey().Key;
|
||||||
if (consoleKey is ConsoleKey.M or ConsoleKey.End)
|
if (consoleKey is ConsoleKey.M or ConsoleKey.End)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Logger?.LogInformation(". . .");
|
||||||
if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.M)
|
if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.M)
|
||||||
{
|
{
|
||||||
foreach (string fileMove in fileMoveCollection)
|
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)
|
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;
|
int stay = 0;
|
||||||
ConsoleKey? consoleKey = null;
|
ConsoleKey? consoleKey = null;
|
||||||
long ticks = DateTime.Now.Ticks;
|
long ticks = DateTime.Now.Ticks;
|
||||||
@ -863,16 +851,16 @@ public class Compare
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
collection = propertyLogic.GetPropertyIds(directoryInfoCollection, saveToCollection);
|
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++)
|
for (int x = 0; x < int.MaxValue; x++)
|
||||||
{
|
{
|
||||||
_Log.Information($"Press \"S\" key to {nameof(CreateWindowsShortcuts)}");
|
_Logger?.LogInformation($"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 \"End\" key when ready to skip or close console if compare not needed");
|
||||||
consoleKey = Console.ReadKey().Key;
|
consoleKey = Console.ReadKey().Key;
|
||||||
if (consoleKey is ConsoleKey.M or ConsoleKey.End)
|
if (consoleKey is ConsoleKey.M or ConsoleKey.End)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Logger?.LogInformation(". . .");
|
||||||
if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.S)
|
if (consoleKey.HasValue && consoleKey.Value == ConsoleKey.S)
|
||||||
CreateWindowsShortcuts(collection, keepAll);
|
CreateWindowsShortcuts(collection, keepAll);
|
||||||
}
|
}
|
||||||
|
@ -37,10 +37,6 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="7.0.5" />
|
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="7.0.5" />
|
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||||
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
||||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Compare.Models.Stateless;
|
|
||||||
|
|
||||||
public static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +1,5 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Compare.Models;
|
using View_by_Distance.Compare.Models;
|
||||||
@ -11,9 +10,8 @@ namespace View_by_Distance.Compare;
|
|||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Secondary(List<string> args)
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
||||||
{
|
{
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -29,9 +27,6 @@ public class Program
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
ILogger log = Log.ForContext<Program>();
|
|
||||||
int silentIndex = args.IndexOf("s");
|
int silentIndex = args.IndexOf("s");
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
args.RemoveAt(silentIndex);
|
args.RemoveAt(silentIndex);
|
||||||
@ -40,31 +35,28 @@ public class Program
|
|||||||
if (args is null)
|
if (args is null)
|
||||||
throw new Exception("args is null!");
|
throw new Exception("args is null!");
|
||||||
Shared.Models.Console console = new();
|
Shared.Models.Console console = new();
|
||||||
Compare _ = new(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
Compare _ = new(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
logger?.LogError(ex, "Error!");
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
}
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
log.Debug("Done. Bye");
|
logger?.LogDebug("Done. Bye");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Debug("Done. Press 'Enter' to end");
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
||||||
_ = Console.ReadLine();
|
_ = Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
||||||
if (args is not null)
|
if (args is not null)
|
||||||
Secondary(args.ToList());
|
Secondary(logger, args.ToList());
|
||||||
else
|
else
|
||||||
Secondary(new List<string>());
|
Secondary(logger, new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -39,10 +39,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Property\Property.csproj" />
|
<ProjectReference Include="..\Property\Property.csproj" />
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using ShellProgressBar;
|
using ShellProgressBar;
|
||||||
using View_by_Distance.Copy.Distinct.Models;
|
using View_by_Distance.Copy.Distinct.Models;
|
||||||
using View_by_Distance.Shared.Models;
|
using View_by_Distance.Shared.Models;
|
||||||
@ -19,7 +19,7 @@ public class CopyDistinct
|
|||||||
private readonly IReadOnlyDictionary<string, string[]> _FileGroups;
|
private readonly IReadOnlyDictionary<string, string[]> _FileGroups;
|
||||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||||
|
|
||||||
public CopyDistinct(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
public CopyDistinct(List<string> args, ILogger<Program> logger, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
||||||
{
|
{
|
||||||
if (isSilent)
|
if (isSilent)
|
||||||
{ }
|
{ }
|
||||||
@ -29,15 +29,14 @@ public class CopyDistinct
|
|||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
_WorkingDirectory = workingDirectory;
|
_WorkingDirectory = workingDirectory;
|
||||||
_ConfigurationRoot = configurationRoot;
|
_ConfigurationRoot = configurationRoot;
|
||||||
ILogger? log = Log.ForContext<CopyDistinct>();
|
|
||||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
_PropertyConfiguration = propertyConfiguration;
|
_PropertyConfiguration = propertyConfiguration;
|
||||||
_Configuration = configuration;
|
_Configuration = configuration;
|
||||||
log.Information(propertyConfiguration.RootDirectory);
|
logger?.LogInformation(propertyConfiguration.RootDirectory);
|
||||||
(bool move, List<string[]> filesCollection, bool anyLenFiles, bool moveBack) = Verify();
|
(bool move, List<string[]> filesCollection, bool anyLenFiles, bool moveBack) = Verify();
|
||||||
_FileGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, appSettings.CopyTo, new string[] { appSettings.ResultDirectoryKey });
|
_FileGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, appSettings.CopyTo, new string[] { appSettings.ResultDirectoryKey });
|
||||||
List<string> lines = CopyDistinctFilesInDirectories(log, move, filesCollection, anyLenFiles, moveBack);
|
List<string> lines = CopyDistinctFilesInDirectories(logger, move, filesCollection, anyLenFiles, moveBack);
|
||||||
if (lines.Any())
|
if (lines.Any())
|
||||||
File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", lines);
|
File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", lines);
|
||||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||||
@ -154,7 +153,7 @@ public class CopyDistinct
|
|||||||
return (distinctDirectories.ToArray(), results);
|
return (distinctDirectories.ToArray(), results);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<string> CopyDistinctFilesInDirectories(ILogger log, bool move, List<string[]> filesCollection, bool anyLenFiles, bool moveBack)
|
private List<string> CopyDistinctFilesInDirectories(ILogger<Program>? logger, bool move, List<string[]> filesCollection, bool anyLenFiles, bool moveBack)
|
||||||
{
|
{
|
||||||
List<string> results = new();
|
List<string> results = new();
|
||||||
ProgressBar progressBar;
|
ProgressBar progressBar;
|
||||||
@ -184,30 +183,30 @@ public class CopyDistinct
|
|||||||
_ = Directory.CreateDirectory(distinctDirectory);
|
_ = Directory.CreateDirectory(distinctDirectory);
|
||||||
}
|
}
|
||||||
if (move)
|
if (move)
|
||||||
log.Information($"Ready to Move {toDoCollection.Count} file(s)?");
|
logger?.LogInformation($"Ready to Move {toDoCollection.Count} file(s)?");
|
||||||
else if (!moveBack)
|
else if (!moveBack)
|
||||||
log.Information($"Ready to Copy {toDoCollection.Count} file(s)?");
|
logger?.LogInformation($"Ready to Copy {toDoCollection.Count} file(s)?");
|
||||||
else
|
else
|
||||||
log.Information($"Ready to Move back {toDoCollection.Count} file(s)?");
|
logger?.LogInformation($"Ready to Move back {toDoCollection.Count} file(s)?");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
if (move)
|
if (move)
|
||||||
log.Information("Press \"Y\" key to move file(s), \"N\" key to log file(s) or close console to not move files");
|
logger?.LogInformation("Press \"Y\" key to move file(s), \"N\" key to log file(s) or close console to not move files");
|
||||||
else if (!moveBack)
|
else if (!moveBack)
|
||||||
log.Information("Press \"Y\" key to copy file(s), \"N\" key to log file(s) or close console to not copy files");
|
logger?.LogInformation("Press \"Y\" key to copy file(s), \"N\" key to log file(s) or close console to not copy files");
|
||||||
else
|
else
|
||||||
log.Information("Press \"Y\" key to move back file(s), \"N\" key to log file(s) or close console to not move back files");
|
logger?.LogInformation("Press \"Y\" key to move back file(s), \"N\" key to log file(s) or close console to not move back files");
|
||||||
consoleKey = System.Console.ReadKey().Key;
|
consoleKey = System.Console.ReadKey().Key;
|
||||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log.Information(". . .");
|
logger?.LogInformation(". . .");
|
||||||
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
|
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
|
||||||
{
|
{
|
||||||
if (move || moveBack)
|
if (move || moveBack)
|
||||||
log.Information("Nothing moved!");
|
logger?.LogInformation("Nothing moved!");
|
||||||
else
|
else
|
||||||
log.Information("Nothing copied!");
|
logger?.LogInformation("Nothing copied!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -215,9 +214,9 @@ public class CopyDistinct
|
|||||||
results.AddRange(Shared.Models.Stateless.Methods.IDirectory.CopyOrMove(toDoCollection, move, moveBack, () => progressBar.Tick()));
|
results.AddRange(Shared.Models.Stateless.Methods.IDirectory.CopyOrMove(toDoCollection, move, moveBack, () => progressBar.Tick()));
|
||||||
progressBar.Dispose();
|
progressBar.Dispose();
|
||||||
if (move || moveBack)
|
if (move || moveBack)
|
||||||
log.Information("Done moving");
|
logger?.LogInformation("Done moving");
|
||||||
else
|
else
|
||||||
log.Information("Done copying");
|
logger?.LogInformation("Done copying");
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Copy.Distinct.Models.Stateless;
|
|
||||||
|
|
||||||
public static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Copy.Distinct.Models;
|
using View_by_Distance.Copy.Distinct.Models;
|
||||||
@ -11,9 +13,8 @@ namespace View_by_Distance.Copy.Distinct;
|
|||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Secondary(List<string> args)
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
||||||
{
|
{
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -30,9 +31,6 @@ public class Program
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
ILogger log = Log.ForContext<Program>();
|
|
||||||
int silentIndex = args.IndexOf("s");
|
int silentIndex = args.IndexOf("s");
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
args.RemoveAt(silentIndex);
|
args.RemoveAt(silentIndex);
|
||||||
@ -41,31 +39,28 @@ public class Program
|
|||||||
if (args is null)
|
if (args is null)
|
||||||
throw new Exception("args is null!");
|
throw new Exception("args is null!");
|
||||||
Shared.Models.Console console = new();
|
Shared.Models.Console console = new();
|
||||||
_ = new CopyDistinct(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
_ = new CopyDistinct(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
logger?.LogError(ex, "Error!");
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
}
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
log.Debug("Done. Bye");
|
logger?.LogDebug("Done. Bye");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Debug("Done. Press 'Enter' to end");
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
||||||
_ = Console.ReadLine();
|
_ = Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
||||||
if (args is not null)
|
if (args is not null)
|
||||||
Secondary(args.ToList());
|
Secondary(logger, args.ToList());
|
||||||
else
|
else
|
||||||
Secondary(new List<string>());
|
Secondary(logger, new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -39,10 +39,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="7.0.5" />
|
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
|
||||||
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||||
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
||||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -13,15 +14,15 @@ namespace View_by_Distance.Date.Group;
|
|||||||
public class DateGroup
|
public class DateGroup
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly Serilog.ILogger? _Log;
|
|
||||||
private readonly AppSettings _AppSettings;
|
private readonly AppSettings _AppSettings;
|
||||||
private readonly List<string> _Exceptions;
|
private readonly List<string> _Exceptions;
|
||||||
|
private readonly ILogger<Program>? _Logger;
|
||||||
private readonly IsEnvironment _IsEnvironment;
|
private readonly IsEnvironment _IsEnvironment;
|
||||||
private readonly Models.Configuration _Configuration;
|
private readonly Models.Configuration _Configuration;
|
||||||
private readonly List<KeyValuePair<string, string>> _FileKeyValuePairs;
|
private readonly List<KeyValuePair<string, string>> _FileKeyValuePairs;
|
||||||
private readonly Dictionary<string, List<Tuple<string, Shared.Models.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)
|
public DateGroup(List<string> args, ILogger<Program>? logger, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
||||||
{
|
{
|
||||||
if (isSilent)
|
if (isSilent)
|
||||||
{ }
|
{ }
|
||||||
@ -29,15 +30,15 @@ public class DateGroup
|
|||||||
{ }
|
{ }
|
||||||
if (console is null)
|
if (console is null)
|
||||||
{ }
|
{ }
|
||||||
|
_Logger = logger;
|
||||||
_AppSettings = appSettings;
|
_AppSettings = appSettings;
|
||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
_Exceptions = new List<string>();
|
_Exceptions = new List<string>();
|
||||||
_Log = Serilog.Log.ForContext<DateGroup>();
|
|
||||||
_FileKeyValuePairs = new List<KeyValuePair<string, string>>();
|
_FileKeyValuePairs = new List<KeyValuePair<string, string>>();
|
||||||
_FilePropertiesKeyValuePairs = new Dictionary<string, List<Tuple<string, Shared.Models.Property>>>();
|
_FilePropertiesKeyValuePairs = new Dictionary<string, List<Tuple<string, Shared.Models.Property>>>();
|
||||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
Models.Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
Models.Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
_Log.Information(propertyConfiguration.RootDirectory);
|
_Logger?.LogInformation(propertyConfiguration.RootDirectory);
|
||||||
Property.Models.Configuration.Verify(propertyConfiguration, requireExist: true);
|
Property.Models.Configuration.Verify(propertyConfiguration, requireExist: true);
|
||||||
Verify(configuration);
|
Verify(configuration);
|
||||||
bool reverse = false;
|
bool reverse = false;
|
||||||
@ -49,12 +50,8 @@ public class DateGroup
|
|||||||
string[] dbFiles = Directory.GetFiles(propertyConfiguration.RootDirectory, "*.db", SearchOption.AllDirectories);
|
string[] dbFiles = Directory.GetFiles(propertyConfiguration.RootDirectory, "*.db", SearchOption.AllDirectories);
|
||||||
foreach (string dbFile in dbFiles)
|
foreach (string dbFile in dbFiles)
|
||||||
File.Delete(dbFile);
|
File.Delete(dbFile);
|
||||||
if (true || appSettings.MaxDegreeOfParallelism < 2)
|
|
||||||
ticks = LogDelta(ticks, nameof(File.Delete));
|
|
||||||
for (int i = 1; i < 10; i++)
|
for (int i = 1; i < 10; i++)
|
||||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||||
if (true || appSettings.MaxDegreeOfParallelism < 2)
|
|
||||||
ticks = LogDelta(ticks, nameof(Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories));
|
|
||||||
string destinationRoot = Property.Models.Stateless.IResult.GetResultsGroupDirectory(propertyConfiguration, "Z) Moved");
|
string destinationRoot = Property.Models.Stateless.IResult.GetResultsGroupDirectory(propertyConfiguration, "Z) Moved");
|
||||||
string aResultsFullGroupDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(_Configuration.PropertyConfiguration, nameof(A_Property));
|
string aResultsFullGroupDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(_Configuration.PropertyConfiguration, nameof(A_Property));
|
||||||
string aPropertySingletonDirectory = Path.Combine(aResultsFullGroupDirectory, "{}");
|
string aPropertySingletonDirectory = Path.Combine(aResultsFullGroupDirectory, "{}");
|
||||||
@ -67,8 +64,6 @@ public class DateGroup
|
|||||||
if (propertyConfiguration.PopulatePropertyId && (configuration.ByCreateDateShortcut || configuration.ByHash) && Shared.Models.Stateless.Methods.IProperty.Any(containers))
|
if (propertyConfiguration.PopulatePropertyId && (configuration.ByCreateDateShortcut || configuration.ByHash) && Shared.Models.Stateless.Methods.IProperty.Any(containers))
|
||||||
{
|
{
|
||||||
propertyLogic.SavePropertyParallelWork(ticks, metadata, t, containers);
|
propertyLogic.SavePropertyParallelWork(ticks, metadata, t, containers);
|
||||||
if (appSettings.MaxDegreeOfParallelism < 2)
|
|
||||||
ticks = LogDelta(ticks, nameof(A_Property.SavePropertyParallelWork));
|
|
||||||
if (propertyLogic.ExceptionsDirectories.Any())
|
if (propertyLogic.ExceptionsDirectories.Any())
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
@ -133,17 +128,6 @@ public class DateGroup
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<(Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)> GetMoveFileCollection(string destinationDirectory, string topDirectory, Item[] filteredItems)
|
private List<(Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)> GetMoveFileCollection(string destinationDirectory, string topDirectory, Item[] filteredItems)
|
||||||
{
|
{
|
||||||
List<(Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)> results = new();
|
List<(Item Item, long LastWriteTimeTicks, long MinimumDateTimeTicks, string[] Destination)> results = new();
|
||||||
@ -376,8 +360,6 @@ public class DateGroup
|
|||||||
|
|
||||||
private void MoveFiles(Property.Models.Configuration configuration, string destinationRoot, Container[] containers)
|
private void MoveFiles(Property.Models.Configuration configuration, string destinationRoot, Container[] containers)
|
||||||
{
|
{
|
||||||
if (_Log is null)
|
|
||||||
throw new NullReferenceException(nameof(_Log));
|
|
||||||
string checkDirectory;
|
string checkDirectory;
|
||||||
bool hasDuplicate;
|
bool hasDuplicate;
|
||||||
string fullFileName;
|
string fullFileName;
|
||||||
@ -410,14 +392,14 @@ public class DateGroup
|
|||||||
_ = Directory.CreateDirectory(checkDirectory);
|
_ = Directory.CreateDirectory(checkDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_Log.Information($"Ready to move {fileMoveCollectionAll.Length} file(s)?");
|
_Logger?.LogInformation($"Ready to move {fileMoveCollectionAll.Length} file(s)?");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
_Log.Information("Press \"Y\" key to move file(s) or close console to not move files");
|
_Logger?.LogInformation("Press \"Y\" key to move file(s) or close console to not move files");
|
||||||
if (System.Console.ReadKey().Key == ConsoleKey.Y)
|
if (System.Console.ReadKey().Key == ConsoleKey.Y)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Logger?.LogInformation(". . .");
|
||||||
int moved = 0;
|
int moved = 0;
|
||||||
foreach ((Item item, long lastWriteTimeTicks, long minimumDateTimeTicks, string[] destination) in fileMoveCollectionAll)
|
foreach ((Item item, long lastWriteTimeTicks, long minimumDateTimeTicks, string[] destination) in fileMoveCollectionAll)
|
||||||
{
|
{
|
||||||
@ -454,14 +436,14 @@ public class DateGroup
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(destinationRoot);
|
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(destinationRoot);
|
||||||
_Log.Information($"{moved} file(s) moved");
|
_Logger?.LogInformation($"{moved} file(s) moved");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
_Log.Information("Press \"Y\" key to move file(s) back or close console to leave them moved");
|
_Logger?.LogInformation("Press \"Y\" key to move file(s) back or close console to leave them moved");
|
||||||
if (System.Console.ReadKey().Key == ConsoleKey.Y)
|
if (System.Console.ReadKey().Key == ConsoleKey.Y)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Logger?.LogInformation(". . .");
|
||||||
foreach ((Item item, long lastWriteTimeTicks, long minimumDateTimeTicks, string[] destination) in fileMoveCollectionAll)
|
foreach ((Item item, long lastWriteTimeTicks, long minimumDateTimeTicks, string[] destination) in fileMoveCollectionAll)
|
||||||
{
|
{
|
||||||
fullFileName = Path.Combine(destination);
|
fullFileName = Path.Combine(destination);
|
||||||
@ -472,7 +454,7 @@ public class DateGroup
|
|||||||
File.Move(fullFileName, item.ImageFileHolder.FullName);
|
File.Move(fullFileName, item.ImageFileHolder.FullName);
|
||||||
moved += 1;
|
moved += 1;
|
||||||
}
|
}
|
||||||
_Log.Information($"Done moving back {moved} file(s)");
|
_Logger?.LogInformation($"Done moving back {moved} file(s)");
|
||||||
for (int i = 1; i < 10; i++)
|
for (int i = 1; i < 10; i++)
|
||||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(configuration.RootDirectory);
|
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(configuration.RootDirectory);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Date.Group.Models.Stateless;
|
|
||||||
|
|
||||||
public static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Date.Group.Models;
|
using View_by_Distance.Date.Group.Models;
|
||||||
@ -11,9 +13,8 @@ namespace View_by_Distance.Date.Group;
|
|||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Secondary(List<string> args)
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
||||||
{
|
{
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -30,9 +31,6 @@ public class Program
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
ILogger log = Log.ForContext<Program>();
|
|
||||||
int silentIndex = args.IndexOf("s");
|
int silentIndex = args.IndexOf("s");
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
args.RemoveAt(silentIndex);
|
args.RemoveAt(silentIndex);
|
||||||
@ -79,31 +77,28 @@ public class Program
|
|||||||
throw new Exception("Chelsea");
|
throw new Exception("Chelsea");
|
||||||
#nullable restore
|
#nullable restore
|
||||||
Shared.Models.Console console = new();
|
Shared.Models.Console console = new();
|
||||||
DateGroup _ = new(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
DateGroup _ = new(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
logger?.LogError(ex, "Error!");
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
}
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
log.Debug("Done. Bye");
|
logger?.LogDebug("Done. Bye");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Debug("Done. Press 'Enter' to end");
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
||||||
_ = Console.ReadLine();
|
_ = Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
||||||
if (args is not null)
|
if (args is not null)
|
||||||
Secondary(args.ToList());
|
Secondary(logger, args.ToList());
|
||||||
else
|
else
|
||||||
Secondary(new List<string>());
|
Secondary(logger, new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -38,10 +38,6 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="7.0.5" />
|
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="7.0.5" />
|
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||||
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
||||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using ShellProgressBar;
|
using ShellProgressBar;
|
||||||
using View_by_Distance.Delete.By.Distinct.Models;
|
using View_by_Distance.Delete.By.Distinct.Models;
|
||||||
using View_by_Distance.Property.Models;
|
using View_by_Distance.Property.Models;
|
||||||
@ -11,28 +11,27 @@ namespace View_by_Distance.Delete.By.Distinct;
|
|||||||
public class DeleteByDistinct
|
public class DeleteByDistinct
|
||||||
{
|
{
|
||||||
|
|
||||||
public DeleteByDistinct(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
public DeleteByDistinct(List<string> args, ILogger<Program> logger, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
||||||
{
|
{
|
||||||
if (isSilent)
|
if (isSilent)
|
||||||
{ }
|
{ }
|
||||||
if (console is null)
|
if (console is null)
|
||||||
{ }
|
{ }
|
||||||
long ticks = DateTime.Now.Ticks;
|
long ticks = DateTime.Now.Ticks;
|
||||||
ILogger? log = Log.ForContext<DeleteByDistinct>();
|
|
||||||
Dictionary<string, List<string>> keyValuePairs = new();
|
Dictionary<string, List<string>> keyValuePairs = new();
|
||||||
Configuration configuration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
Configuration configuration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true };
|
||||||
log.Information(configuration.RootDirectory);
|
logger?.LogInformation(configuration.RootDirectory);
|
||||||
if (!appSettings.TicksForLong && !appSettings.SizeForLong)
|
if (!appSettings.TicksForLong && !appSettings.SizeForLong)
|
||||||
throw new Exception("Check appSettings file!");
|
throw new Exception("Check appSettings file!");
|
||||||
bool compareIsPopulatedAndNotTheSame = !string.IsNullOrEmpty(appSettings.CompareRootDirectory) && appSettings.CompareRootDirectory != configuration.RootDirectory;
|
bool compareIsPopulatedAndNotTheSame = !string.IsNullOrEmpty(appSettings.CompareRootDirectory) && appSettings.CompareRootDirectory != configuration.RootDirectory;
|
||||||
Work(appSettings, ticks, log, configuration.RootDirectory, nameof(configuration.RootDirectory), options, keyValuePairs, logOnly: compareIsPopulatedAndNotTheSame);
|
Work(appSettings, ticks, logger, configuration.RootDirectory, nameof(configuration.RootDirectory), options, keyValuePairs, logOnly: compareIsPopulatedAndNotTheSame);
|
||||||
if (compareIsPopulatedAndNotTheSame)
|
if (compareIsPopulatedAndNotTheSame)
|
||||||
Work(appSettings, ticks, log, appSettings.CompareRootDirectory, nameof(appSettings.CompareRootDirectory), options, keyValuePairs, logOnly: false);
|
Work(appSettings, ticks, logger, appSettings.CompareRootDirectory, nameof(appSettings.CompareRootDirectory), options, keyValuePairs, logOnly: false);
|
||||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(appSettings.CompareRootDirectory);
|
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(appSettings.CompareRootDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Work(AppSettings appSettings, long ticks, ILogger log, string directory, string variable, ProgressBarOptions options, Dictionary<string, List<string>> keyValuePairs, bool logOnly)
|
private static void Work(AppSettings appSettings, long ticks, ILogger<Program>? logger, string directory, string variable, ProgressBarOptions options, Dictionary<string, List<string>> keyValuePairs, bool logOnly)
|
||||||
{
|
{
|
||||||
string check;
|
string check;
|
||||||
string logFile;
|
string logFile;
|
||||||
@ -48,7 +47,7 @@ public class DeleteByDistinct
|
|||||||
List<string> deletedDirectories = new();
|
List<string> deletedDirectories = new();
|
||||||
Dictionary<long, List<string>> longToCollectionB = new();
|
Dictionary<long, List<string>> longToCollectionB = new();
|
||||||
List<(string Source, string Destination)> renameFiles = new();
|
List<(string Source, string Destination)> renameFiles = new();
|
||||||
log.Information($"Gathering {appSettings.SearchPattern} files from <{directory}>");
|
logger?.LogInformation($"Gathering {appSettings.SearchPattern} files from <{directory}>");
|
||||||
(string directory, string[] files)[] leftCollection = Shared.Models.Stateless.Methods.IFileHolder.GetFiles(directory, appSettings.SearchPattern).ToArray();
|
(string directory, string[] files)[] leftCollection = Shared.Models.Stateless.Methods.IFileHolder.GetFiles(directory, appSettings.SearchPattern).ToArray();
|
||||||
totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||||
message = $") Looking for duplicates from <{directory}> - {totalSeconds} total second(s)";
|
message = $") Looking for duplicates from <{directory}> - {totalSeconds} total second(s)";
|
||||||
@ -105,21 +104,21 @@ public class DeleteByDistinct
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
progressBar.Dispose();
|
progressBar.Dispose();
|
||||||
log.Information(". . .");
|
logger?.LogInformation(". . .");
|
||||||
logFile = $"{ticks}-{variable}-Files-A.lsv";
|
logFile = $"{ticks}-{variable}-Files-A.lsv";
|
||||||
if (!logOnly)
|
if (!logOnly)
|
||||||
File.WriteAllLines(Path.Combine(directory, logFile), deletedFiles);
|
File.WriteAllLines(Path.Combine(directory, logFile), deletedFiles);
|
||||||
if (deletedFiles.Any() && !logOnly)
|
if (deletedFiles.Any() && !logOnly)
|
||||||
{
|
{
|
||||||
log.Information($"Ready to delete {deletedFiles.Count} from {variable} {appSettings.SearchPattern} file(s)? See <{logFile}>");
|
logger?.LogInformation($"Ready to delete {deletedFiles.Count} from {variable} {appSettings.SearchPattern} file(s)? See <{logFile}>");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
log.Information("Press \"Y\" key to delete file(s), \"N\" key to log file(s) or close console to not delete files");
|
logger?.LogInformation("Press \"Y\" key to delete file(s), \"N\" key to log file(s) or close console to not delete files");
|
||||||
consoleKey = Console.ReadKey().Key;
|
consoleKey = Console.ReadKey().Key;
|
||||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log.Information(". . .");
|
logger?.LogInformation(". . .");
|
||||||
if (consoleKey is not null && consoleKey.Value == ConsoleKey.Y)
|
if (consoleKey is not null && consoleKey.Value == ConsoleKey.Y)
|
||||||
{
|
{
|
||||||
foreach (string file in deletedFiles)
|
foreach (string file in deletedFiles)
|
||||||
@ -150,7 +149,7 @@ public class DeleteByDistinct
|
|||||||
deletedDirectories.AddRange(collection);
|
deletedDirectories.AddRange(collection);
|
||||||
}
|
}
|
||||||
progressBar.Dispose();
|
progressBar.Dispose();
|
||||||
log.Information(". . .");
|
logger?.LogInformation(". . .");
|
||||||
logFile = $"{ticks + 1}-{variable}-Directories.lsv";
|
logFile = $"{ticks + 1}-{variable}-Directories.lsv";
|
||||||
File.WriteAllLines(Path.Combine(directory, logFile), deletedDirectories.Distinct());
|
File.WriteAllLines(Path.Combine(directory, logFile), deletedDirectories.Distinct());
|
||||||
}
|
}
|
||||||
@ -161,15 +160,15 @@ public class DeleteByDistinct
|
|||||||
File.WriteAllLines(Path.Combine(directory, logFile), renameFiles.Select(l => l.Source));
|
File.WriteAllLines(Path.Combine(directory, logFile), renameFiles.Select(l => l.Source));
|
||||||
logFile = $"{ticks}-{variable}-Files-C.lsv";
|
logFile = $"{ticks}-{variable}-Files-C.lsv";
|
||||||
File.WriteAllLines(Path.Combine(directory, logFile), renameFiles.Select(l => l.Destination));
|
File.WriteAllLines(Path.Combine(directory, logFile), renameFiles.Select(l => l.Destination));
|
||||||
log.Information($"Ready to rename to match {renameFiles.Count} from {variable} {appSettings.SearchPattern} file(s)? See <{logFile}>");
|
logger?.LogInformation($"Ready to rename to match {renameFiles.Count} from {variable} {appSettings.SearchPattern} file(s)? See <{logFile}>");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
log.Information("Press \"Y\" key to rename to match file(s), \"N\" key to log file(s) or close console to not rename to match files");
|
logger?.LogInformation("Press \"Y\" key to rename to match file(s), \"N\" key to log file(s) or close console to not rename to match files");
|
||||||
consoleKey = Console.ReadKey().Key;
|
consoleKey = Console.ReadKey().Key;
|
||||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log.Information(". . .");
|
logger?.LogInformation(". . .");
|
||||||
if (consoleKey is not null && consoleKey.Value == ConsoleKey.Y)
|
if (consoleKey is not null && consoleKey.Value == ConsoleKey.Y)
|
||||||
{
|
{
|
||||||
foreach ((string source, string destination) in renameFiles)
|
foreach ((string source, string destination) in renameFiles)
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Delete.By.Distinct.Models.Stateless;
|
|
||||||
|
|
||||||
public static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Delete.By.Distinct.Models;
|
using View_by_Distance.Delete.By.Distinct.Models;
|
||||||
@ -11,9 +13,8 @@ namespace View_by_Distance.Delete.By.Distinct;
|
|||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Secondary(List<string> args)
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
||||||
{
|
{
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -30,9 +31,6 @@ public class Program
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
ILogger log = Log.ForContext<Program>();
|
|
||||||
int silentIndex = args.IndexOf("s");
|
int silentIndex = args.IndexOf("s");
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
args.RemoveAt(silentIndex);
|
args.RemoveAt(silentIndex);
|
||||||
@ -41,31 +39,28 @@ public class Program
|
|||||||
if (args is null)
|
if (args is null)
|
||||||
throw new Exception("args is null!");
|
throw new Exception("args is null!");
|
||||||
Shared.Models.Console console = new();
|
Shared.Models.Console console = new();
|
||||||
_ = new DeleteByDistinct(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
_ = new DeleteByDistinct(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
logger?.LogError(ex, "Error!");
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
}
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
log.Debug("Done. Bye");
|
logger?.LogDebug("Done. Bye");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Debug("Done. Press 'Enter' to end");
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
||||||
_ = Console.ReadLine();
|
_ = Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
||||||
if (args is not null)
|
if (args is not null)
|
||||||
Secondary(args.ToList());
|
Secondary(logger, args.ToList());
|
||||||
else
|
else
|
||||||
Secondary(new List<string>());
|
Secondary(logger, new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -38,10 +38,6 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="7.0.5" />
|
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="7.0.5" />
|
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||||
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
||||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using View_by_Distance.Delete.By.Relative.Models;
|
using View_by_Distance.Delete.By.Relative.Models;
|
||||||
using View_by_Distance.Property.Models;
|
using View_by_Distance.Property.Models;
|
||||||
using View_by_Distance.Shared.Models.Methods;
|
using View_by_Distance.Shared.Models.Methods;
|
||||||
@ -10,7 +10,7 @@ namespace View_by_Distance.Delete.By.Relative;
|
|||||||
public class DeleteByRelative
|
public class DeleteByRelative
|
||||||
{
|
{
|
||||||
|
|
||||||
public DeleteByRelative(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
public DeleteByRelative(List<string> args, ILogger<Program> logger, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
||||||
{
|
{
|
||||||
if (isSilent)
|
if (isSilent)
|
||||||
{ }
|
{ }
|
||||||
@ -20,9 +20,8 @@ public class DeleteByRelative
|
|||||||
string checkFileName;
|
string checkFileName;
|
||||||
string searchPattern = "*";
|
string searchPattern = "*";
|
||||||
long ticks = DateTime.Now.Ticks;
|
long ticks = DateTime.Now.Ticks;
|
||||||
ILogger? log = Log.ForContext<DeleteByRelative>();
|
|
||||||
Configuration configuration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
Configuration configuration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
log.Information(configuration.RootDirectory);
|
logger?.LogInformation(configuration.RootDirectory);
|
||||||
int length = configuration.RootDirectory.Length;
|
int length = configuration.RootDirectory.Length;
|
||||||
if (string.IsNullOrEmpty(appSettings.CompareRootDirectory) || Path.GetFullPath(appSettings.CompareRootDirectory) == Path.GetFullPath(configuration.RootDirectory))
|
if (string.IsNullOrEmpty(appSettings.CompareRootDirectory) || Path.GetFullPath(appSettings.CompareRootDirectory) == Path.GetFullPath(configuration.RootDirectory))
|
||||||
throw new Exception("Check AppSettings file!");
|
throw new Exception("Check AppSettings file!");
|
||||||
@ -60,14 +59,14 @@ public class DeleteByRelative
|
|||||||
File.WriteAllLines(deleteLog, deleteFiles);
|
File.WriteAllLines(deleteLog, deleteFiles);
|
||||||
if (deleteFiles.Count > 0)
|
if (deleteFiles.Count > 0)
|
||||||
{
|
{
|
||||||
log.Information($"Ready to delete {deleteFiles.Count} file(s)? See <{deleteLog}>");
|
logger?.LogInformation($"Ready to delete {deleteFiles.Count} file(s)? See <{deleteLog}>");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
log.Information("Press \"Y\" key to delete file(s) or close console to not delete files");
|
logger?.LogInformation("Press \"Y\" key to delete file(s) or close console to not delete files");
|
||||||
if (Console.ReadKey().Key == ConsoleKey.Y)
|
if (Console.ReadKey().Key == ConsoleKey.Y)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log.Information(". . .");
|
logger?.LogInformation(". . .");
|
||||||
foreach (string deleteFile in deleteFiles)
|
foreach (string deleteFile in deleteFiles)
|
||||||
{
|
{
|
||||||
File.Delete(deleteFile);
|
File.Delete(deleteFile);
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Delete.By.Relative.Models.Stateless;
|
|
||||||
|
|
||||||
public static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Delete.By.Relative.Models;
|
using View_by_Distance.Delete.By.Relative.Models;
|
||||||
@ -11,9 +13,8 @@ namespace View_by_Distance.Delete.By.Relative;
|
|||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Secondary(List<string> args)
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
||||||
{
|
{
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -30,9 +31,6 @@ public class Program
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
ILogger log = Log.ForContext<Program>();
|
|
||||||
int silentIndex = args.IndexOf("s");
|
int silentIndex = args.IndexOf("s");
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
args.RemoveAt(silentIndex);
|
args.RemoveAt(silentIndex);
|
||||||
@ -41,31 +39,28 @@ public class Program
|
|||||||
if (args is null)
|
if (args is null)
|
||||||
throw new Exception("args is null!");
|
throw new Exception("args is null!");
|
||||||
Shared.Models.Console console = new();
|
Shared.Models.Console console = new();
|
||||||
_ = new DeleteByRelative(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
_ = new DeleteByRelative(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
logger?.LogError(ex, "Error!");
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
}
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
log.Debug("Done. Bye");
|
logger?.LogDebug("Done. Bye");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Debug("Done. Press 'Enter' to end");
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
||||||
_ = Console.ReadLine();
|
_ = Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
||||||
if (args is not null)
|
if (args is not null)
|
||||||
Secondary(args.ToList());
|
Secondary(logger, args.ToList());
|
||||||
else
|
else
|
||||||
Secondary(new List<string>());
|
Secondary(logger, new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -35,7 +35,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||||
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Distance.Models.Stateless;
|
|
||||||
|
|
||||||
internal static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +1,6 @@
|
|||||||
using ShellProgressBar;
|
using ShellProgressBar;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using View_by_Distance.Distance.Models.Stateless;
|
|
||||||
using View_by_Distance.FaceRecognitionDotNet;
|
using View_by_Distance.FaceRecognitionDotNet;
|
||||||
using View_by_Distance.Property.Models.Stateless;
|
using View_by_Distance.Property.Models.Stateless;
|
||||||
using View_by_Distance.Shared.Models;
|
using View_by_Distance.Shared.Models;
|
||||||
@ -17,7 +16,6 @@ public partial class E_Distance : IDistance<MetadataExtractor.Directory>
|
|||||||
private readonly List<string> _Moved;
|
private readonly List<string> _Moved;
|
||||||
private readonly List<double?> _Debug;
|
private readonly List<double?> _Debug;
|
||||||
private readonly List<string> _Renamed;
|
private readonly List<string> _Renamed;
|
||||||
private readonly Serilog.ILogger? _Log;
|
|
||||||
private readonly int _FaceConfidencePercent;
|
private readonly int _FaceConfidencePercent;
|
||||||
private readonly bool _DistanceRenameToMatch;
|
private readonly bool _DistanceRenameToMatch;
|
||||||
private readonly bool _DistanceMoveUnableToMatch;
|
private readonly bool _DistanceMoveUnableToMatch;
|
||||||
@ -35,7 +33,6 @@ public partial class E_Distance : IDistance<MetadataExtractor.Directory>
|
|||||||
_AllMappedFaceFiles = new();
|
_AllMappedFaceFiles = new();
|
||||||
_AllMappedFaceFileNames = new();
|
_AllMappedFaceFileNames = new();
|
||||||
_DuplicateMappedFaceFiles = new();
|
_DuplicateMappedFaceFiles = new();
|
||||||
_Log = Serilog.Log.ForContext<E_Distance>();
|
|
||||||
_DistanceRenameToMatch = distanceRenameToMatch;
|
_DistanceRenameToMatch = distanceRenameToMatch;
|
||||||
_FaceConfidencePercent = faceConfidencePercent;
|
_FaceConfidencePercent = faceConfidencePercent;
|
||||||
_DistanceMoveUnableToMatch = distanceMoveUnableToMatch;
|
_DistanceMoveUnableToMatch = distanceMoveUnableToMatch;
|
||||||
@ -298,16 +295,13 @@ public partial class E_Distance : IDistance<MetadataExtractor.Directory>
|
|||||||
|
|
||||||
public void Clear()
|
public void Clear()
|
||||||
{
|
{
|
||||||
if (_Log is null)
|
// double?[] debug = (from l in _Debug where l is null or not 0 select l).ToArray();
|
||||||
throw new NullReferenceException(nameof(_Log));
|
// if (debug.Length > 0)
|
||||||
double?[] debug = (from l in _Debug where l is null or not 0 select l).ToArray();
|
// {
|
||||||
if (debug.Length > 0)
|
// string debugMessage = $"{_Debug.Count - debug.Length} - {debug.Min()} - {_Debug.Max()}";
|
||||||
{
|
// }
|
||||||
string debugMessage = $"{_Debug.Count - debug.Length} - {debug.Min()} - {_Debug.Max()}";
|
// if (_DuplicateMappedFaceFiles.Count > 0)
|
||||||
_Log.Info(debugMessage);
|
// _Log.Info($"Renamed {_DuplicateMappedFaceFiles.Count} to *.dup file(s)");
|
||||||
}
|
|
||||||
if (_DuplicateMappedFaceFiles.Count > 0)
|
|
||||||
_Log.Info($"Renamed {_DuplicateMappedFaceFiles.Count} to *.dup file(s)");
|
|
||||||
if (_Moved.Count > 0 || _Renamed.Count > 0)
|
if (_Moved.Count > 0 || _Renamed.Count > 0)
|
||||||
throw new NotImplementedException("Restart!");
|
throw new NotImplementedException("Restart!");
|
||||||
_Debug.Clear();
|
_Debug.Clear();
|
||||||
|
@ -30,10 +30,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
<ProjectReference Include="..\Shared\View-by-Distance.Shared.csproj" />
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@ -14,7 +13,6 @@ namespace View_by_Distance.Drag_Drop_Explorer;
|
|||||||
public partial class DragDropExplorer : Form
|
public partial class DragDropExplorer : Form
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly ILogger _Logger;
|
|
||||||
private readonly Calendar _Calendar;
|
private readonly Calendar _Calendar;
|
||||||
private readonly TextBox _PathTextBox;
|
private readonly TextBox _PathTextBox;
|
||||||
private readonly TextBox _JsonTextBox;
|
private readonly TextBox _JsonTextBox;
|
||||||
@ -27,13 +25,11 @@ public partial class DragDropExplorer : Form
|
|||||||
public DragDropExplorer()
|
public DragDropExplorer()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
ILogger logger;
|
|
||||||
AppSettings appSettings;
|
AppSettings appSettings;
|
||||||
string workingDirectory;
|
string workingDirectory;
|
||||||
IsEnvironment isEnvironment;
|
IsEnvironment isEnvironment;
|
||||||
IConfigurationRoot configurationRoot;
|
IConfigurationRoot configurationRoot;
|
||||||
_Calendar = new CultureInfo("en-US").Calendar;
|
_Calendar = new CultureInfo("en-US").Calendar;
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -48,11 +44,6 @@ public partial class DragDropExplorer : Form
|
|||||||
throw new Exception("Working path name must have parentDirectory value!");
|
throw new Exception("Working path name must have parentDirectory value!");
|
||||||
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
logger = Log.ForContext<DragDropExplorer>();
|
|
||||||
logger.Information("Complete");
|
|
||||||
_Logger = logger;
|
|
||||||
_AppSettings = appSettings;
|
_AppSettings = appSettings;
|
||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
_WorkingDirectory = workingDirectory;
|
_WorkingDirectory = workingDirectory;
|
||||||
@ -130,7 +121,6 @@ public partial class DragDropExplorer : Form
|
|||||||
_FirstTextBox.Text = string.Empty;
|
_FirstTextBox.Text = string.Empty;
|
||||||
_PathTextBox.Text = string.Empty;
|
_PathTextBox.Text = string.Empty;
|
||||||
_JsonTextBox.Text = string.Empty;
|
_JsonTextBox.Text = string.Empty;
|
||||||
_Logger.Information("No data");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -30,10 +30,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
@ -13,7 +12,6 @@ namespace View_by_Distance.Drag.Drop.Move;
|
|||||||
public partial class DragDropMove : Form
|
public partial class DragDropMove : Form
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly ILogger _Logger;
|
|
||||||
private readonly TextBox _PathTextBox;
|
private readonly TextBox _PathTextBox;
|
||||||
private readonly TextBox _JsonTextBox;
|
private readonly TextBox _JsonTextBox;
|
||||||
private readonly TextBox _FirstTextBox;
|
private readonly TextBox _FirstTextBox;
|
||||||
@ -25,12 +23,10 @@ public partial class DragDropMove : Form
|
|||||||
public DragDropMove()
|
public DragDropMove()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
ILogger logger;
|
|
||||||
AppSettings appSettings;
|
AppSettings appSettings;
|
||||||
string workingDirectory;
|
string workingDirectory;
|
||||||
IsEnvironment isEnvironment;
|
IsEnvironment isEnvironment;
|
||||||
IConfigurationRoot configurationRoot;
|
IConfigurationRoot configurationRoot;
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -45,11 +41,6 @@ public partial class DragDropMove : Form
|
|||||||
throw new Exception("Working path name must have parentDirectory value!");
|
throw new Exception("Working path name must have parentDirectory value!");
|
||||||
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
logger = Log.ForContext<DragDropMove>();
|
|
||||||
logger.Information("Complete");
|
|
||||||
_Logger = logger;
|
|
||||||
_AppSettings = appSettings;
|
_AppSettings = appSettings;
|
||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
_WorkingDirectory = workingDirectory;
|
_WorkingDirectory = workingDirectory;
|
||||||
@ -186,7 +177,6 @@ public partial class DragDropMove : Form
|
|||||||
_FirstTextBox.Text = string.Empty;
|
_FirstTextBox.Text = string.Empty;
|
||||||
_PathTextBox.Text = string.Empty;
|
_PathTextBox.Text = string.Empty;
|
||||||
_JsonTextBox.Text = string.Empty;
|
_JsonTextBox.Text = string.Empty;
|
||||||
_Logger.Information("No data");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@ -31,10 +31,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\FaceRecognitionDotNet\FaceRecognitionDotNet.csproj" />
|
<ProjectReference Include="..\FaceRecognitionDotNet\FaceRecognitionDotNet.csproj" />
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Drag_Drop.Models;
|
using View_by_Distance.Drag_Drop.Models;
|
||||||
@ -14,7 +13,6 @@ namespace View_by_Distance.Drag_Drop;
|
|||||||
public partial class DragDropSearch : Form
|
public partial class DragDropSearch : Form
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly ILogger _Logger;
|
|
||||||
private readonly TextBox _TextBox;
|
private readonly TextBox _TextBox;
|
||||||
private readonly AppSettings _AppSettings;
|
private readonly AppSettings _AppSettings;
|
||||||
private readonly ProgressBar _ProgressBar;
|
private readonly ProgressBar _ProgressBar;
|
||||||
@ -29,14 +27,12 @@ public partial class DragDropSearch : Form
|
|||||||
public DragDropSearch()
|
public DragDropSearch()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
ILogger logger;
|
|
||||||
_IdToItem = new();
|
_IdToItem = new();
|
||||||
AppSettings appSettings;
|
AppSettings appSettings;
|
||||||
string workingDirectory;
|
string workingDirectory;
|
||||||
IsEnvironment isEnvironment;
|
IsEnvironment isEnvironment;
|
||||||
Models.Configuration configuration;
|
Models.Configuration configuration;
|
||||||
IConfigurationRoot configurationRoot;
|
IConfigurationRoot configurationRoot;
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Property.Models.Configuration propertyConfiguration;
|
Property.Models.Configuration propertyConfiguration;
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
@ -51,14 +47,9 @@ public partial class DragDropSearch : Form
|
|||||||
throw new Exception("Working path name must have parentDirectory value!");
|
throw new Exception("Working path name must have parentDirectory value!");
|
||||||
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
logger = Log.ForContext<DragDropSearch>();
|
|
||||||
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
(_, _, string resizeFileNameExtension) = C_Resize.GetTuple(configuration.OutputExtension, configuration.OutputQuality);
|
(_, _, string resizeFileNameExtension) = C_Resize.GetTuple(configuration.OutputExtension, configuration.OutputQuality);
|
||||||
logger.Information("Complete");
|
|
||||||
_Logger = logger;
|
|
||||||
_AppSettings = appSettings;
|
_AppSettings = appSettings;
|
||||||
_Configuration = configuration;
|
_Configuration = configuration;
|
||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
@ -128,14 +119,6 @@ public partial class DragDropSearch : Form
|
|||||||
continue;
|
continue;
|
||||||
_IdToItem.Add(item.Property.Id.Value, item);
|
_IdToItem.Add(item.Property.Id.Value, item);
|
||||||
}
|
}
|
||||||
if (_Logger is null)
|
|
||||||
throw new NullReferenceException(nameof(_Logger));
|
|
||||||
_Logger.Debug((_AppSettings is null).ToString());
|
|
||||||
_Logger.Debug((_Configuration is null).ToString());
|
|
||||||
_Logger.Debug((_IsEnvironment is null).ToString());
|
|
||||||
_Logger.Debug((_WorkingDirectory is null).ToString());
|
|
||||||
_Logger.Debug((_ConfigurationRoot is null).ToString());
|
|
||||||
_Logger.Debug((_PropertyConfiguration is null).ToString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string? GetFaceEncoding(string file)
|
public static string? GetFaceEncoding(string file)
|
||||||
@ -179,8 +162,6 @@ public partial class DragDropSearch : Form
|
|||||||
{
|
{
|
||||||
Text = item.ImageFileHolder.Name;
|
Text = item.ImageFileHolder.Name;
|
||||||
_TextBox.Text = item.ImageFileHolder.FullName;
|
_TextBox.Text = item.ImageFileHolder.FullName;
|
||||||
if (item.ImageFileHolder.DirectoryName is not null)
|
|
||||||
_Logger.Information(item.ImageFileHolder.DirectoryName);
|
|
||||||
if (!string.IsNullOrEmpty(item.ImageFileHolder.DirectoryName))
|
if (!string.IsNullOrEmpty(item.ImageFileHolder.DirectoryName))
|
||||||
_ = Process.Start("explorer.exe", string.Concat("\"", item.ImageFileHolder.DirectoryName, "\""));
|
_ = Process.Start("explorer.exe", string.Concat("\"", item.ImageFileHolder.DirectoryName, "\""));
|
||||||
}
|
}
|
||||||
|
@ -31,10 +31,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@ -24,7 +23,6 @@ public partial class DragDropSetPropertyItem : Form
|
|||||||
short? PropertyItemType,
|
short? PropertyItemType,
|
||||||
string? Value);
|
string? Value);
|
||||||
|
|
||||||
private readonly ILogger _Logger;
|
|
||||||
private readonly TextBox _PathTextBox;
|
private readonly TextBox _PathTextBox;
|
||||||
private readonly TextBox _JsonTextBox;
|
private readonly TextBox _JsonTextBox;
|
||||||
private readonly TextBox _FirstTextBox;
|
private readonly TextBox _FirstTextBox;
|
||||||
@ -37,12 +35,10 @@ public partial class DragDropSetPropertyItem : Form
|
|||||||
public DragDropSetPropertyItem()
|
public DragDropSetPropertyItem()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
ILogger logger;
|
|
||||||
AppSettings appSettings;
|
AppSettings appSettings;
|
||||||
string workingDirectory;
|
string workingDirectory;
|
||||||
IsEnvironment isEnvironment;
|
IsEnvironment isEnvironment;
|
||||||
IConfigurationRoot configurationRoot;
|
IConfigurationRoot configurationRoot;
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -55,14 +51,9 @@ public partial class DragDropSetPropertyItem : Form
|
|||||||
throw new Exception("Working path name must have parentDirectory setTo!");
|
throw new Exception("Working path name must have parentDirectory setTo!");
|
||||||
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
logger = Log.ForContext<DragDropSetPropertyItem>();
|
|
||||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
Property.Models.Configuration.Verify(propertyConfiguration, requireExist: false);
|
Property.Models.Configuration.Verify(propertyConfiguration, requireExist: false);
|
||||||
_PropertyConfiguration = propertyConfiguration;
|
_PropertyConfiguration = propertyConfiguration;
|
||||||
logger.Information("Complete");
|
|
||||||
_Logger = logger;
|
|
||||||
_AppSettings = appSettings;
|
_AppSettings = appSettings;
|
||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
_WorkingDirectory = workingDirectory;
|
_WorkingDirectory = workingDirectory;
|
||||||
@ -107,11 +98,8 @@ public partial class DragDropSetPropertyItem : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetMessage(string message)
|
private void SetMessage(string message) =>
|
||||||
{
|
|
||||||
_Logger.Information(message);
|
|
||||||
_JsonTextBox.Text = message;
|
_JsonTextBox.Text = message;
|
||||||
}
|
|
||||||
|
|
||||||
private List<Record> GetRecords(ASCIIEncoding asciiEncoding, int tagId, List<string> files)
|
private List<Record> GetRecords(ASCIIEncoding asciiEncoding, int tagId, List<string> files)
|
||||||
{
|
{
|
||||||
|
@ -37,10 +37,6 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="7.0.5" />
|
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="7.0.5" />
|
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||||
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
||||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using ShellProgressBar;
|
using ShellProgressBar;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
@ -14,7 +14,7 @@ namespace View_by_Distance.Duplicate.Search;
|
|||||||
public class DuplicateSearch
|
public class DuplicateSearch
|
||||||
{
|
{
|
||||||
|
|
||||||
public DuplicateSearch(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
public DuplicateSearch(List<string> args, ILogger<Program> logger, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
||||||
{
|
{
|
||||||
if (isSilent)
|
if (isSilent)
|
||||||
{ }
|
{ }
|
||||||
@ -22,9 +22,8 @@ public class DuplicateSearch
|
|||||||
{ }
|
{ }
|
||||||
string searchPattern = "*";
|
string searchPattern = "*";
|
||||||
long ticks = DateTime.Now.Ticks;
|
long ticks = DateTime.Now.Ticks;
|
||||||
ILogger? log = Log.ForContext<DuplicateSearch>();
|
|
||||||
Configuration configuration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
Configuration configuration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
log.Information(configuration.RootDirectory);
|
logger?.LogInformation(configuration.RootDirectory);
|
||||||
if (appSettings.IndexOnly)
|
if (appSettings.IndexOnly)
|
||||||
WriteIndexData(ticks, configuration, searchPattern);
|
WriteIndexData(ticks, configuration, searchPattern);
|
||||||
else
|
else
|
||||||
@ -38,9 +37,9 @@ public class DuplicateSearch
|
|||||||
Dictionary<int, List<MappingFromItem?>> idToCollection = GetIdToCollection(argZero, configuration, argZeroIsConfigurationRootDirectory, containers, destinationRoot, preloadIds);
|
Dictionary<int, List<MappingFromItem?>> idToCollection = GetIdToCollection(argZero, configuration, argZeroIsConfigurationRootDirectory, containers, destinationRoot, preloadIds);
|
||||||
int duplicates = (from l in idToCollection where l.Value.Count > 1 select 1).Sum();
|
int duplicates = (from l in idToCollection where l.Value.Count > 1 select 1).Sum();
|
||||||
if (duplicates == 0)
|
if (duplicates == 0)
|
||||||
log.Information($"Found {duplicates} duplicate file(s)");
|
logger?.LogInformation($"Found {duplicates} duplicate file(s)");
|
||||||
else
|
else
|
||||||
QuestionMove(ticks, log, destinationRoot, idToCollection, duplicates);
|
QuestionMove(ticks, logger, destinationRoot, idToCollection, duplicates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +60,7 @@ public class DuplicateSearch
|
|||||||
File.WriteAllText(Path.Combine(alongSideDirectory, $"{directoryName}-{ticks}.json"), json);
|
File.WriteAllText(Path.Combine(alongSideDirectory, $"{directoryName}-{ticks}.json"), json);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Move(ILogger log, long ticks, string destinationRoot, List<(FileHolder ImageFileHolder, string Destination)> collection)
|
private static void Move(ILogger<Program>? logger, long ticks, string destinationRoot, List<(FileHolder ImageFileHolder, string Destination)> collection)
|
||||||
{
|
{
|
||||||
StringBuilder stringBuilder = new();
|
StringBuilder stringBuilder = new();
|
||||||
foreach ((FileHolder fileHolder, string destination) in collection)
|
foreach ((FileHolder fileHolder, string destination) in collection)
|
||||||
@ -70,28 +69,28 @@ public class DuplicateSearch
|
|||||||
_ = stringBuilder.AppendLine(destination);
|
_ = stringBuilder.AppendLine(destination);
|
||||||
}
|
}
|
||||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(Path.Combine(destinationRoot, $"{ticks}file(s).lsv"), stringBuilder.ToString(), updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(Path.Combine(destinationRoot, $"{ticks}file(s).lsv"), stringBuilder.ToString(), updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||||
log.Information($"Ready to move {collection.Count} file(s)?");
|
logger?.LogInformation($"Ready to move {collection.Count} file(s)?");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
log.Information("Press \"Y\" key to move file(s) or close console to not move files");
|
logger?.LogInformation("Press \"Y\" key to move file(s) or close console to not move files");
|
||||||
if (System.Console.ReadKey().Key == ConsoleKey.Y)
|
if (System.Console.ReadKey().Key == ConsoleKey.Y)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log.Information(". . .");
|
logger?.LogInformation(". . .");
|
||||||
foreach ((FileHolder fileHolder, string destination) in collection)
|
foreach ((FileHolder fileHolder, string destination) in collection)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{ File.Move(fileHolder.FullName, destination); }
|
{ File.Move(fileHolder.FullName, destination); }
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{ log.Error(exception, $"Failed to move <{fileHolder.FullName}>"); }
|
{ logger?.LogError(exception, $"Failed to move <{fileHolder.FullName}>"); }
|
||||||
}
|
}
|
||||||
log.Information($"{collection.Count} file(s) moved");
|
logger?.LogInformation($"{collection.Count} file(s) moved");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
log.Information("Press \"Y\" key to move file(s) back or close console to leave them moved");
|
logger?.LogInformation("Press \"Y\" key to move file(s) back or close console to leave them moved");
|
||||||
if (System.Console.ReadKey().Key != ConsoleKey.Y)
|
if (System.Console.ReadKey().Key != ConsoleKey.Y)
|
||||||
continue;
|
continue;
|
||||||
log.Information(". . .");
|
logger?.LogInformation(". . .");
|
||||||
foreach ((FileHolder fileHolder, string destination) in collection)
|
foreach ((FileHolder fileHolder, string destination) in collection)
|
||||||
{
|
{
|
||||||
if (!File.Exists(destination))
|
if (!File.Exists(destination))
|
||||||
@ -101,27 +100,27 @@ public class DuplicateSearch
|
|||||||
try
|
try
|
||||||
{ File.Move(destination, fileHolder.FullName); }
|
{ File.Move(destination, fileHolder.FullName); }
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{ log.Error(exception, $"Failed to move <{destination}>"); }
|
{ logger?.LogError(exception, $"Failed to move <{destination}>"); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Information(". . .");
|
logger?.LogInformation(". . .");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void QuestionMove(long ticks, ILogger log, string destinationRoot, Dictionary<int, List<MappingFromItem?>> idToCollection, int duplicates)
|
private static void QuestionMove(long ticks, ILogger<Program>? logger, string destinationRoot, Dictionary<int, List<MappingFromItem?>> idToCollection, int duplicates)
|
||||||
{
|
{
|
||||||
int[] ids = (from l in idToCollection orderby l.Key where l.Value.Any(m => m is not null) select l.Key).ToArray();
|
int[] ids = (from l in idToCollection orderby l.Key where l.Value.Any(m => m is not null) select l.Key).ToArray();
|
||||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(Path.Combine(destinationRoot, $"{ticks}-id(s).lsv"), string.Join(Environment.NewLine, ids), updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(Path.Combine(destinationRoot, $"{ticks}-id(s).lsv"), string.Join(Environment.NewLine, ids), updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||||
string json = JsonSerializer.Serialize(idToCollection, new JsonSerializerOptions { WriteIndented = true });
|
string json = JsonSerializer.Serialize(idToCollection, new JsonSerializerOptions { WriteIndented = true });
|
||||||
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(Path.Combine(destinationRoot, $"{ticks}.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
_ = Shared.Models.Stateless.Methods.IPath.WriteAllText(Path.Combine(destinationRoot, $"{ticks}.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||||
log.Information($"Found {duplicates} duplicate file(s)");
|
logger?.LogInformation($"Found {duplicates} duplicate file(s)");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
log.Information("Press \"Y\" key to continue or close console to leave them moved");
|
logger?.LogInformation("Press \"Y\" key to continue or close console to leave them moved");
|
||||||
if (System.Console.ReadKey().Key != ConsoleKey.Y)
|
if (System.Console.ReadKey().Key != ConsoleKey.Y)
|
||||||
continue;
|
continue;
|
||||||
log.Information(". . .");
|
logger?.LogInformation(". . .");
|
||||||
List<(FileHolder ImageFileHolder, string Destination)> collection = GetCollectionAndCreateDirectories(idToCollection);
|
List<(FileHolder ImageFileHolder, string Destination)> collection = GetCollectionAndCreateDirectories(idToCollection);
|
||||||
Move(log, ticks, destinationRoot, collection);
|
Move(logger, ticks, destinationRoot, collection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Duplicate.Search.Models.Stateless;
|
|
||||||
|
|
||||||
public static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Duplicate.Search.Models;
|
using View_by_Distance.Duplicate.Search.Models;
|
||||||
@ -11,9 +13,8 @@ namespace View_by_Distance.Duplicate.Search;
|
|||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Secondary(List<string> args)
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
||||||
{
|
{
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -30,9 +31,6 @@ public class Program
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
ILogger log = Log.ForContext<Program>();
|
|
||||||
int silentIndex = args.IndexOf("s");
|
int silentIndex = args.IndexOf("s");
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
args.RemoveAt(silentIndex);
|
args.RemoveAt(silentIndex);
|
||||||
@ -41,31 +39,28 @@ public class Program
|
|||||||
if (args is null)
|
if (args is null)
|
||||||
throw new Exception("args is null!");
|
throw new Exception("args is null!");
|
||||||
Shared.Models.Console console = new();
|
Shared.Models.Console console = new();
|
||||||
_ = new DuplicateSearch(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
_ = new DuplicateSearch(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
logger?.LogError(ex, "Error!");
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
}
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
log.Debug("Done. Bye");
|
logger?.LogDebug("Done. Bye");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Debug("Done. Press 'Enter' to end");
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
||||||
_ = Console.ReadLine();
|
_ = Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
||||||
if (args is not null)
|
if (args is not null)
|
||||||
Secondary(args.ToList());
|
Secondary(logger, args.ToList());
|
||||||
else
|
else
|
||||||
Secondary(new List<string>());
|
Secondary(logger, new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -33,7 +33,6 @@
|
|||||||
<SupportedPlatform Include="browser" />
|
<SupportedPlatform Include="browser" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Face.Models.Stateless;
|
|
||||||
|
|
||||||
internal static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -1,11 +1,9 @@
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using View_by_Distance.Face.Models.Stateless;
|
|
||||||
using View_by_Distance.FaceRecognitionDotNet;
|
using View_by_Distance.FaceRecognitionDotNet;
|
||||||
using View_by_Distance.Metadata.Models;
|
using View_by_Distance.Metadata.Models;
|
||||||
using View_by_Distance.Property.Models;
|
using View_by_Distance.Property.Models;
|
||||||
@ -31,7 +29,6 @@ public class D_Face
|
|||||||
|
|
||||||
private readonly Model _Model;
|
private readonly Model _Model;
|
||||||
private readonly string _ArgZero;
|
private readonly string _ArgZero;
|
||||||
private readonly Serilog.ILogger? _Log;
|
|
||||||
private readonly bool _OverrideForFaceImages;
|
private readonly bool _OverrideForFaceImages;
|
||||||
private readonly bool _LoadPhotoPrismLocations;
|
private readonly bool _LoadPhotoPrismLocations;
|
||||||
private readonly ImageCodecInfo _ImageCodecInfo;
|
private readonly ImageCodecInfo _ImageCodecInfo;
|
||||||
@ -75,7 +72,6 @@ public class D_Face
|
|||||||
_ImageCodecInfo = imageCodecInfo;
|
_ImageCodecInfo = imageCodecInfo;
|
||||||
_EncoderParameters = encoderParameters;
|
_EncoderParameters = encoderParameters;
|
||||||
_FileNameExtension = filenameExtension;
|
_FileNameExtension = filenameExtension;
|
||||||
_Log = Serilog.Log.ForContext<D_Face>();
|
|
||||||
_HiddenImageCodecInfo = hiddenImageCodecInfo;
|
_HiddenImageCodecInfo = hiddenImageCodecInfo;
|
||||||
_OverrideForFaceImages = overrideForFaceImages;
|
_OverrideForFaceImages = overrideForFaceImages;
|
||||||
_PropertyConfiguration = propertyConfiguration;
|
_PropertyConfiguration = propertyConfiguration;
|
||||||
@ -219,8 +215,6 @@ public class D_Face
|
|||||||
|
|
||||||
private List<Shared.Models.Face> GetFaces(string outputResolution, Shared.Models.Property property, MappingFromItem mappingFromItem, Dictionary<string, int[]> outputResolutionToResize, List<Location>? locations)
|
private List<Shared.Models.Face> GetFaces(string outputResolution, Shared.Models.Property property, MappingFromItem mappingFromItem, Dictionary<string, int[]> outputResolutionToResize, List<Location>? locations)
|
||||||
{
|
{
|
||||||
if (_Log is null)
|
|
||||||
throw new NullReferenceException(nameof(_Log));
|
|
||||||
if (_PropertyConfiguration.NumberOfJitters is null)
|
if (_PropertyConfiguration.NumberOfJitters is null)
|
||||||
throw new NullReferenceException(nameof(_PropertyConfiguration.NumberOfJitters));
|
throw new NullReferenceException(nameof(_PropertyConfiguration.NumberOfJitters));
|
||||||
if (_PropertyConfiguration.NumberOfTimesToUpsample is null)
|
if (_PropertyConfiguration.NumberOfTimesToUpsample is null)
|
||||||
@ -230,10 +224,7 @@ public class D_Face
|
|||||||
try
|
try
|
||||||
{ unknownImage = FaceRecognition.LoadImageFile(mappingFromItem.ResizedFileHolder.FullName); }
|
{ unknownImage = FaceRecognition.LoadImageFile(mappingFromItem.ResizedFileHolder.FullName); }
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{ unknownImage = null; }
|
||||||
unknownImage = null;
|
|
||||||
_Log.Info(string.Concat(new StackFrame().GetMethod()?.Name, " <", mappingFromItem.ResizedFileHolder.FullName, ">"));
|
|
||||||
}
|
|
||||||
if (unknownImage is not null)
|
if (unknownImage is not null)
|
||||||
{
|
{
|
||||||
(int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation) = Resize.Models.Stateless.Methods.IResize.Get(outputResolution, outputResolutionToResize);
|
(int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation) = Resize.Models.Stateless.Methods.IResize.Get(outputResolution, outputResolutionToResize);
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
<SupportedPlatform Include="browser" />
|
<SupportedPlatform Include="browser" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.FaceParts.Models.Stateless;
|
|
||||||
|
|
||||||
internal static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -22,7 +22,6 @@ public class D2_FaceParts
|
|||||||
protected readonly string _FileNameExtension;
|
protected readonly string _FileNameExtension;
|
||||||
public string FileNameExtension => _FileNameExtension;
|
public string FileNameExtension => _FileNameExtension;
|
||||||
|
|
||||||
private readonly Serilog.ILogger? _Log;
|
|
||||||
private readonly ImageCodecInfo _ImageCodecInfo;
|
private readonly ImageCodecInfo _ImageCodecInfo;
|
||||||
private readonly bool _CheckDFaceAndUpWriteDates;
|
private readonly bool _CheckDFaceAndUpWriteDates;
|
||||||
private readonly bool _OverrideForFaceLandmarkImages;
|
private readonly bool _OverrideForFaceLandmarkImages;
|
||||||
@ -38,7 +37,6 @@ public class D2_FaceParts
|
|||||||
_EncoderParameters = encoderParameters;
|
_EncoderParameters = encoderParameters;
|
||||||
_FileNameExtension = filenameExtension;
|
_FileNameExtension = filenameExtension;
|
||||||
_AngleBracketCollection = new List<string>();
|
_AngleBracketCollection = new List<string>();
|
||||||
_Log = Serilog.Log.ForContext<D2_FaceParts>();
|
|
||||||
_PropertyConfiguration = propertyConfiguration;
|
_PropertyConfiguration = propertyConfiguration;
|
||||||
_CheckDFaceAndUpWriteDates = checkDFaceAndUpWriteDates;
|
_CheckDFaceAndUpWriteDates = checkDFaceAndUpWriteDates;
|
||||||
_OverrideForFaceLandmarkImages = overrideForFaceLandmarkImages;
|
_OverrideForFaceLandmarkImages = overrideForFaceLandmarkImages;
|
||||||
@ -131,10 +129,10 @@ public class D2_FaceParts
|
|||||||
// it will be after rotation.
|
// it will be after rotation.
|
||||||
PointF[] points =
|
PointF[] points =
|
||||||
{
|
{
|
||||||
new PointF(0, 0),
|
new (0, 0),
|
||||||
new PointF(bitmap.Width, 0),
|
new (bitmap.Width, 0),
|
||||||
new PointF(bitmap.Width, bitmap.Height),
|
new (bitmap.Width, bitmap.Height),
|
||||||
new PointF(0, bitmap.Height),
|
new (0, bitmap.Height),
|
||||||
};
|
};
|
||||||
rotate_at_origin.TransformPoints(points);
|
rotate_at_origin.TransformPoints(points);
|
||||||
float xMinimum, xMaximum, yMinimum, yMaximum;
|
float xMinimum, xMaximum, yMinimum, yMaximum;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using ShellProgressBar;
|
using ShellProgressBar;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
@ -29,11 +30,11 @@ public partial class DlibDotNet
|
|||||||
private readonly F_Random _Random;
|
private readonly F_Random _Random;
|
||||||
private readonly IConsole _Console;
|
private readonly IConsole _Console;
|
||||||
private readonly E_Distance _Distance;
|
private readonly E_Distance _Distance;
|
||||||
private readonly Serilog.ILogger? _Log;
|
|
||||||
private readonly IBlurHasher _BlurHasher;
|
private readonly IBlurHasher _BlurHasher;
|
||||||
private readonly D2_FaceParts _FaceParts;
|
private readonly D2_FaceParts _FaceParts;
|
||||||
private readonly AppSettings _AppSettings;
|
private readonly AppSettings _AppSettings;
|
||||||
private readonly List<string> _Exceptions;
|
private readonly List<string> _Exceptions;
|
||||||
|
private readonly ILogger<Program>? _Logger;
|
||||||
private readonly IsEnvironment _IsEnvironment;
|
private readonly IsEnvironment _IsEnvironment;
|
||||||
private readonly bool _PropertyRootExistedBefore;
|
private readonly bool _PropertyRootExistedBefore;
|
||||||
private readonly Models.Configuration _Configuration;
|
private readonly Models.Configuration _Configuration;
|
||||||
@ -43,6 +44,7 @@ public partial class DlibDotNet
|
|||||||
|
|
||||||
public DlibDotNet(
|
public DlibDotNet(
|
||||||
List<string> args,
|
List<string> args,
|
||||||
|
ILogger<Program> logger,
|
||||||
IsEnvironment isEnvironment,
|
IsEnvironment isEnvironment,
|
||||||
IConfigurationRoot configurationRoot,
|
IConfigurationRoot configurationRoot,
|
||||||
AppSettings appSettings,
|
AppSettings appSettings,
|
||||||
@ -51,6 +53,7 @@ public partial class DlibDotNet
|
|||||||
IConsole console)
|
IConsole console)
|
||||||
{
|
{
|
||||||
string message;
|
string message;
|
||||||
|
_Logger = logger;
|
||||||
_Console = console;
|
_Console = console;
|
||||||
_AppSettings = appSettings;
|
_AppSettings = appSettings;
|
||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
@ -59,11 +62,10 @@ public partial class DlibDotNet
|
|||||||
_JLinkResolvedDirectories = new();
|
_JLinkResolvedDirectories = new();
|
||||||
if (ticks.ToString().Last() == '0')
|
if (ticks.ToString().Last() == '0')
|
||||||
ticks += 1;
|
ticks += 1;
|
||||||
_Log = Serilog.Log.ForContext<DlibDotNet>();
|
|
||||||
ReadOnlyCollection<PersonContainer> personContainers;
|
ReadOnlyCollection<PersonContainer> personContainers;
|
||||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
Models.Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
Models.Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
_Log.Information(propertyConfiguration.RootDirectory);
|
_Logger?.LogInformation(propertyConfiguration.RootDirectory);
|
||||||
Property.Models.Configuration.Verify(propertyConfiguration, requireExist: false);
|
Property.Models.Configuration.Verify(propertyConfiguration, requireExist: false);
|
||||||
Verify(configuration);
|
Verify(configuration);
|
||||||
VerifyExtra(args, propertyConfiguration, configuration);
|
VerifyExtra(args, propertyConfiguration, configuration);
|
||||||
@ -78,7 +80,7 @@ public partial class DlibDotNet
|
|||||||
_ArgZeroIsConfigurationRootDirectory = propertyConfiguration.RootDirectory == argZero;
|
_ArgZeroIsConfigurationRootDirectory = propertyConfiguration.RootDirectory == argZero;
|
||||||
if (!Directory.Exists(argZero))
|
if (!Directory.Exists(argZero))
|
||||||
_ = Directory.CreateDirectory(argZero);
|
_ = Directory.CreateDirectory(argZero);
|
||||||
_Log.Information(configuration.ModelDirectory);
|
_Logger?.LogInformation(configuration.ModelDirectory);
|
||||||
{
|
{
|
||||||
(ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) = C_Resize.GetPngLowQuality();
|
(ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) = C_Resize.GetPngLowQuality();
|
||||||
(ImageCodecInfo hiddenImageCodecInfo, EncoderParameters hiddenEncoderParameters, string hiddenFileNameExtension) = C_Resize.GetGifLowQuality();
|
(ImageCodecInfo hiddenImageCodecInfo, EncoderParameters hiddenEncoderParameters, string hiddenFileNameExtension) = C_Resize.GetGifLowQuality();
|
||||||
@ -149,15 +151,15 @@ public partial class DlibDotNet
|
|||||||
if (!_PropertyRootExistedBefore && !_IsEnvironment.Development && _Exceptions.Count == 0 && _ArgZeroIsConfigurationRootDirectory)
|
if (!_PropertyRootExistedBefore && !_IsEnvironment.Development && _Exceptions.Count == 0 && _ArgZeroIsConfigurationRootDirectory)
|
||||||
{
|
{
|
||||||
string d2FacePartsRootDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(D2_FaceParts));
|
string d2FacePartsRootDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(propertyConfiguration, nameof(D2_FaceParts));
|
||||||
_Log.Information(string.Concat("Cleaning <", d2FacePartsRootDirectory, ">"));
|
_Logger?.LogInformation(string.Concat("Cleaning <", d2FacePartsRootDirectory, ">"));
|
||||||
Shared.Models.Stateless.Methods.IPath.ChangeDateForEmptyDirectories(d2FacePartsRootDirectory, ticks);
|
Shared.Models.Stateless.Methods.IPath.ChangeDateForEmptyDirectories(d2FacePartsRootDirectory, ticks);
|
||||||
}
|
}
|
||||||
message = $"There were {_Exceptions.Count} exception(s) thrown! {Environment.NewLine}{string.Join(Environment.NewLine, _Exceptions)}";
|
message = $"There were {_Exceptions.Count} exception(s) thrown! {Environment.NewLine}{string.Join(Environment.NewLine, _Exceptions)}";
|
||||||
_Log.Information(message);
|
_Logger?.LogInformation(message);
|
||||||
if (_Exceptions.Count != 0)
|
if (_Exceptions.Count != 0)
|
||||||
throw new Exception(message);
|
throw new Exception(message);
|
||||||
if (_PropertyRootExistedBefore)
|
if (_PropertyRootExistedBefore)
|
||||||
_Log.Information("First run completed. Run again if wanted");
|
_Logger?.LogInformation("First run completed. Run again if wanted");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void Verify(Models.Configuration configuration)
|
private static void Verify(Models.Configuration configuration)
|
||||||
@ -427,8 +429,6 @@ public partial class DlibDotNet
|
|||||||
private string SaveUrlAndGetNewRootDirectory(string[] files)
|
private string SaveUrlAndGetNewRootDirectory(string[] files)
|
||||||
{
|
{
|
||||||
string result;
|
string result;
|
||||||
if (_Log is null)
|
|
||||||
throw new NullReferenceException(nameof(_Log));
|
|
||||||
if (files.Length == 0)
|
if (files.Length == 0)
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
string? sourceDirectory = Path.GetDirectoryName(files.First());
|
string? sourceDirectory = Path.GetDirectoryName(files.First());
|
||||||
@ -448,7 +448,7 @@ public partial class DlibDotNet
|
|||||||
int length = result.Length;
|
int length = result.Length;
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
_Log.Information("Enter fileNameToCollection url for fileNameToCollection image");
|
_Logger?.LogInformation("Enter fileNameToCollection url for fileNameToCollection image");
|
||||||
line = _Console.ReadLine();
|
line = _Console.ReadLine();
|
||||||
if (string.IsNullOrEmpty(line))
|
if (string.IsNullOrEmpty(line))
|
||||||
break;
|
break;
|
||||||
@ -466,14 +466,12 @@ public partial class DlibDotNet
|
|||||||
_ = new Item(fileHolder, relativePath, isValidImageFormatExtension);
|
_ = new Item(fileHolder, relativePath, isValidImageFormatExtension);
|
||||||
// container.Items.Add(item);
|
// container.Items.Add(item);
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Logger?.LogInformation(". . .");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FullDoWork(string argZero, string propertyRoot, long ticks, string aResultsFullGroupDirectory, string bResultsFullGroupDirectory, int t, Container[] containers, A_Property propertyLogic, B_Metadata metadata, Dictionary<int, List<MappingFromPhotoPrism>> fileNameToCollection, MapLogic mapLogic)
|
private void FullDoWork(string argZero, string propertyRoot, long ticks, string aResultsFullGroupDirectory, string bResultsFullGroupDirectory, int t, Container[] containers, A_Property propertyLogic, B_Metadata metadata, Dictionary<int, List<MappingFromPhotoPrism>> fileNameToCollection, MapLogic mapLogic)
|
||||||
{
|
{
|
||||||
if (_Log is null)
|
|
||||||
throw new NullReferenceException(nameof(_Log));
|
|
||||||
int total;
|
int total;
|
||||||
int notMapped;
|
int notMapped;
|
||||||
string message;
|
string message;
|
||||||
@ -542,11 +540,11 @@ public partial class DlibDotNet
|
|||||||
{
|
{
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
_Log.Information("Press \"Y\" key when ready to continue or close console");
|
_Logger?.LogInformation("Press \"Y\" key when ready to continue or close console");
|
||||||
if (_Console.ReadKey() == ConsoleKey.Y)
|
if (_Console.ReadKey() == ConsoleKey.Y)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_Log.Information(". . .");
|
_Logger?.LogInformation(". . .");
|
||||||
}
|
}
|
||||||
total += container.Items.Count;
|
total += container.Items.Count;
|
||||||
}
|
}
|
||||||
@ -741,37 +739,22 @@ public partial class DlibDotNet
|
|||||||
|
|
||||||
private void LogItemPropertyIsNull(Item item)
|
private void LogItemPropertyIsNull(Item item)
|
||||||
{
|
{
|
||||||
if (_Log is null)
|
|
||||||
throw new NullReferenceException(nameof(_Log));
|
|
||||||
if (!item.SourceDirectoryFileHolder.Exists)
|
if (!item.SourceDirectoryFileHolder.Exists)
|
||||||
_Log.Information(string.Concat("NoJson <", item.ImageFileHolder.FullName, '>'));
|
_Logger?.LogInformation(string.Concat("NoJson <", item.ImageFileHolder.FullName, '>'));
|
||||||
else if (item.FileSizeChanged.HasValue && item.FileSizeChanged.Value)
|
else if (item.FileSizeChanged.HasValue && item.FileSizeChanged.Value)
|
||||||
_Log.Information(string.Concat("FileSizeChanged <", item.ImageFileHolder.FullName, '>'));
|
_Logger?.LogInformation(string.Concat("FileSizeChanged <", item.ImageFileHolder.FullName, '>'));
|
||||||
else if (item.LastWriteTimeChanged.HasValue && item.LastWriteTimeChanged.Value)
|
else if (item.LastWriteTimeChanged.HasValue && item.LastWriteTimeChanged.Value)
|
||||||
_Log.Information(string.Concat("LastWriteTimeChanged <", item.ImageFileHolder.FullName, '>'));
|
_Logger?.LogInformation(string.Concat("LastWriteTimeChanged <", item.ImageFileHolder.FullName, '>'));
|
||||||
else if (item.Moved.HasValue && item.Moved.Value)
|
else if (item.Moved.HasValue && item.Moved.Value)
|
||||||
_Log.Information(string.Concat("Moved <", item.ImageFileHolder.FullName, '>'));
|
_Logger?.LogInformation(string.Concat("Moved <", item.ImageFileHolder.FullName, '>'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LogNameWithoutExtensionIsIdFormatBut(Item item)
|
private void LogNameWithoutExtensionIsIdFormatBut(Item item)
|
||||||
{
|
{
|
||||||
if (_Log is null)
|
_Logger?.LogInformation($"Name without extension is Id format but doesn't match id <{item.ImageFileHolder.FullName}>");
|
||||||
throw new NullReferenceException(nameof(_Log));
|
|
||||||
_Log.Information($"Name without extension is Id format but doesn't match id <{item.ImageFileHolder.FullName}>");
|
|
||||||
File.Move(item.ImageFileHolder.FullName, $"{item.ImageFileHolder.FullName}.rename");
|
File.Move(item.ImageFileHolder.FullName, $"{item.ImageFileHolder.FullName}.rename");
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int GetNotMappedCountAndUpdateMappingFromPersonThenSetMapping(MapLogic mapLogic, Item item, bool? isFocusRelativePath, ReadOnlyCollection<LocationContainer<MetadataExtractor.Directory>> locationContainers, MappingFromItem mappingFromItem, List<MappingFromPhotoPrism>? mappingFromPhotoPrismCollection, List<Shared.Models.Face> faces)
|
private int GetNotMappedCountAndUpdateMappingFromPersonThenSetMapping(MapLogic mapLogic, Item item, bool? isFocusRelativePath, ReadOnlyCollection<LocationContainer<MetadataExtractor.Directory>> locationContainers, MappingFromItem mappingFromItem, List<MappingFromPhotoPrism>? mappingFromPhotoPrismCollection, List<Shared.Models.Face> faces)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
@ -985,8 +968,6 @@ public partial class DlibDotNet
|
|||||||
MappingFromItem mappingFromItem = IMappingFromItem.GetMappingFromItem(containerDateTimes, item, resizedFileHolder);
|
MappingFromItem mappingFromItem = IMappingFromItem.GetMappingFromItem(containerDateTimes, item, resizedFileHolder);
|
||||||
Map.Models.Stateless.Methods.IMapLogic.SetCreationTimeMaybeMoveToDecade(_Configuration.PropertyConfiguration, _Configuration.MoveToDecade && _Configuration.LocationContainerDistanceTolerance is null, mappingFromItem, locationContainers);
|
Map.Models.Stateless.Methods.IMapLogic.SetCreationTimeMaybeMoveToDecade(_Configuration.PropertyConfiguration, _Configuration.MoveToDecade && _Configuration.LocationContainerDistanceTolerance is null, mappingFromItem, locationContainers);
|
||||||
ReadOnlyDictionary<string, MetadataExtractorDirectory> metadataExtractorDirectories = metadata.GetMetadataCollection(subFileTuples, parseExceptions, changesFrom, mappingFromItem);
|
ReadOnlyDictionary<string, MetadataExtractorDirectory> metadataExtractorDirectories = metadata.GetMetadataCollection(subFileTuples, parseExceptions, changesFrom, mappingFromItem);
|
||||||
if (_AppSettings.MaxDegreeOfParallelism < 2)
|
|
||||||
ticks = LogDelta(ticks, nameof(B_Metadata.GetMetadataCollection));
|
|
||||||
if (_AppSettings.Places.Count > 0)
|
if (_AppSettings.Places.Count > 0)
|
||||||
{
|
{
|
||||||
float latitude;
|
float latitude;
|
||||||
@ -1010,14 +991,8 @@ public partial class DlibDotNet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Dictionary<string, int[]> outputResolutionToResize = _Resize.GetResizeKeyValuePairs(_Configuration.PropertyConfiguration, cResultsFullGroupDirectory, subFileTuples, parseExceptions, item.Property, mappingFromItem);
|
Dictionary<string, int[]> outputResolutionToResize = _Resize.GetResizeKeyValuePairs(_Configuration.PropertyConfiguration, cResultsFullGroupDirectory, subFileTuples, parseExceptions, item.Property, mappingFromItem);
|
||||||
if (_AppSettings.MaxDegreeOfParallelism < 2)
|
|
||||||
ticks = LogDelta(ticks, nameof(C_Resize.GetResizeKeyValuePairs));
|
|
||||||
if (_Configuration.SaveResizedSubfiles)
|
if (_Configuration.SaveResizedSubfiles)
|
||||||
{
|
|
||||||
_Resize.SaveResizedSubfile(_Configuration.PropertyConfiguration, outputResolution, cResultsFullGroupDirectory, subFileTuples, item, item.Property, mappingFromItem, outputResolutionToResize);
|
_Resize.SaveResizedSubfile(_Configuration.PropertyConfiguration, outputResolution, cResultsFullGroupDirectory, subFileTuples, item, item.Property, mappingFromItem, outputResolutionToResize);
|
||||||
if (_AppSettings.MaxDegreeOfParallelism < 2)
|
|
||||||
ticks = LogDelta(ticks, nameof(C_Resize.SaveResizedSubfile));
|
|
||||||
}
|
|
||||||
if (!_Configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions.Contains(outputResolution))
|
if (!_Configuration.LoadOrCreateThenSaveImageFacesResultsForOutputResolutions.Contains(outputResolution))
|
||||||
faces = new();
|
faces = new();
|
||||||
else if (!mappingFromItem.ResizedFileHolder.Exists && !File.Exists(mappingFromItem.ResizedFileHolder.FullName))
|
else if (!mappingFromItem.ResizedFileHolder.Exists && !File.Exists(mappingFromItem.ResizedFileHolder.FullName))
|
||||||
@ -1028,14 +1003,10 @@ public partial class DlibDotNet
|
|||||||
if (!fileNameToCollection.TryGetValue(mappingFromItem.Id, out mappingFromPhotoPrismCollection))
|
if (!fileNameToCollection.TryGetValue(mappingFromItem.Id, out mappingFromPhotoPrismCollection))
|
||||||
mappingFromPhotoPrismCollection = null;
|
mappingFromPhotoPrismCollection = null;
|
||||||
faces = _Faces.GetFaces(outputResolution, dResultsFullGroupDirectory, subFileTuples, parseExceptions, property, mappingFromItem, outputResolutionToResize, locationContainers, mappingFromPhotoPrismCollection);
|
faces = _Faces.GetFaces(outputResolution, dResultsFullGroupDirectory, subFileTuples, parseExceptions, property, mappingFromItem, outputResolutionToResize, locationContainers, mappingFromPhotoPrismCollection);
|
||||||
if (_AppSettings.MaxDegreeOfParallelism < 2)
|
|
||||||
ticks = LogDelta(ticks, nameof(D_Face.GetFaces));
|
|
||||||
result = GetNotMappedCountAndUpdateMappingFromPersonThenSetMapping(mapLogic, item, isFocusRelativePath, locationContainers, mappingFromItem, mappingFromPhotoPrismCollection, faces);
|
result = GetNotMappedCountAndUpdateMappingFromPersonThenSetMapping(mapLogic, item, isFocusRelativePath, locationContainers, mappingFromItem, mappingFromPhotoPrismCollection, faces);
|
||||||
List<(Shared.Models.Face, FileInfo?, string, bool Saved)> faceCollection = _Faces.SaveFaces(_FaceParts.FileNameExtension, dResultsFullGroupDirectory, subFileTuples, parseExceptions, mappingFromItem, faces);
|
List<(Shared.Models.Face, FileInfo?, string, bool Saved)> faceCollection = _Faces.SaveFaces(_FaceParts.FileNameExtension, dResultsFullGroupDirectory, subFileTuples, parseExceptions, mappingFromItem, faces);
|
||||||
if (_Configuration.CopyFacesAndSaveFaceLandmarkForOutputResolutions.Contains(outputResolution))
|
if (_Configuration.CopyFacesAndSaveFaceLandmarkForOutputResolutions.Contains(outputResolution))
|
||||||
_FaceParts.CopyFacesAndSaveFaceLandmarkImage(facePartsCollectionDirectory, mappingFromItem, faceCollection);
|
_FaceParts.CopyFacesAndSaveFaceLandmarkImage(facePartsCollectionDirectory, mappingFromItem, faceCollection);
|
||||||
if (_AppSettings.MaxDegreeOfParallelism < 2)
|
|
||||||
ticks = LogDelta(ticks, nameof(D_Face.SaveFaces));
|
|
||||||
if ((_Configuration.DistanceMoveUnableToMatch || _Configuration.DistanceRenameToMatch)
|
if ((_Configuration.DistanceMoveUnableToMatch || _Configuration.DistanceRenameToMatch)
|
||||||
&& _Configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions.Contains(outputResolution)
|
&& _Configuration.LoadOrCreateThenSaveDistanceResultsForOutputResolutions.Contains(outputResolution)
|
||||||
&& locationContainers is not null && faceCollection.All(l => !l.Saved))
|
&& locationContainers is not null && faceCollection.All(l => !l.Saved))
|
||||||
@ -1046,8 +1017,6 @@ public partial class DlibDotNet
|
|||||||
bool saveRotated = false;
|
bool saveRotated = false;
|
||||||
string sourceDirectorySegment = Property.Models.Stateless.IResult.GetRelativePath(_Configuration.PropertyConfiguration, container.SourceDirectory);
|
string sourceDirectorySegment = Property.Models.Stateless.IResult.GetRelativePath(_Configuration.PropertyConfiguration, container.SourceDirectory);
|
||||||
_FaceParts.SaveFaceLandmarkImages(_Configuration.PropertyConfiguration, subFileTuples, parseExceptions, mappingFromItem, faces, saveRotated);
|
_FaceParts.SaveFaceLandmarkImages(_Configuration.PropertyConfiguration, subFileTuples, parseExceptions, mappingFromItem, faces, saveRotated);
|
||||||
if (_AppSettings.MaxDegreeOfParallelism < 2)
|
|
||||||
ticks = LogDelta(ticks, nameof(D2_FaceParts.SaveFaceLandmarkImages));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lock (sourceDirectoryChanges)
|
lock (sourceDirectoryChanges)
|
||||||
@ -1073,8 +1042,6 @@ public partial class DlibDotNet
|
|||||||
Item[] filteredItems,
|
Item[] filteredItems,
|
||||||
string message)
|
string message)
|
||||||
{
|
{
|
||||||
if (_Log is null)
|
|
||||||
throw new NullReferenceException(nameof(_Log));
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
int exceptionsCount = 0;
|
int exceptionsCount = 0;
|
||||||
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = maxDegreeOfParallelism };
|
ParallelOptions parallelOptions = new() { MaxDegreeOfParallelism = maxDegreeOfParallelism };
|
||||||
@ -1108,10 +1075,9 @@ public partial class DlibDotNet
|
|||||||
if (!anyPropertiesChangedForX && (i == 0 || sourceDirectoryChanges.Count > 0))
|
if (!anyPropertiesChangedForX && (i == 0 || sourceDirectoryChanges.Count > 0))
|
||||||
progressBar.Tick();
|
progressBar.Tick();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
exceptionsCount++;
|
exceptionsCount++;
|
||||||
_Log.Error(string.Concat(container.SourceDirectory, Environment.NewLine, ex.Message, Environment.NewLine, ex.StackTrace), ex);
|
|
||||||
if (exceptionsCount == filteredItems.Length)
|
if (exceptionsCount == filteredItems.Length)
|
||||||
throw new Exception(string.Concat("All in [", container.SourceDirectory, "] failed!"));
|
throw new Exception(string.Concat("All in [", container.SourceDirectory, "] failed!"));
|
||||||
}
|
}
|
||||||
@ -1173,8 +1139,6 @@ public partial class DlibDotNet
|
|||||||
|
|
||||||
private void SaveFaceDistances(long ticks, MapLogic mapLogic, string dFacesContentDirectory, string d2FacePartsContentDirectory, string d2FacePartsContentCollectionDirectory, ReadOnlyDictionary<int, ReadOnlyDictionary<int, Mapping>> idToWholePercentagesToMapping, ReadOnlyCollection<FaceDistance> faceDistanceEncodings, ReadOnlyCollection<FaceDistanceContainer> faceDistanceContainers)
|
private void SaveFaceDistances(long ticks, MapLogic mapLogic, string dFacesContentDirectory, string d2FacePartsContentDirectory, string d2FacePartsContentCollectionDirectory, ReadOnlyDictionary<int, ReadOnlyDictionary<int, Mapping>> idToWholePercentagesToMapping, ReadOnlyCollection<FaceDistance> faceDistanceEncodings, ReadOnlyCollection<FaceDistanceContainer> faceDistanceContainers)
|
||||||
{
|
{
|
||||||
if (_Log is null)
|
|
||||||
throw new NullReferenceException(nameof(_Log));
|
|
||||||
int? useFiltersCounter = null;
|
int? useFiltersCounter = null;
|
||||||
DistanceLimits distanceLimits;
|
DistanceLimits distanceLimits;
|
||||||
ReadOnlyCollection<SortingContainer> sortingContainers;
|
ReadOnlyCollection<SortingContainer> sortingContainers;
|
||||||
@ -1183,7 +1147,7 @@ public partial class DlibDotNet
|
|||||||
distanceLimits = new(_Configuration.FaceAreaPermyriad, _Configuration.FaceConfidencePercent, _Configuration.FaceDistancePermyriad, _Configuration.RangeDaysDeltaTolerance, _Configuration.RangeDistanceTolerance, _Configuration.RangeFaceAreaPermyriadTolerance, _Configuration.RangeFaceConfidence, _Configuration.SortingMaximumPerFaceShouldBeHigh);
|
distanceLimits = new(_Configuration.FaceAreaPermyriad, _Configuration.FaceConfidencePercent, _Configuration.FaceDistancePermyriad, _Configuration.RangeDaysDeltaTolerance, _Configuration.RangeDistanceTolerance, _Configuration.RangeFaceAreaPermyriadTolerance, _Configuration.RangeFaceConfidence, _Configuration.SortingMaximumPerFaceShouldBeHigh);
|
||||||
filteredFaceDistanceContainers = E_Distance.FilteredPostLoadFaceDistanceContainers(mapLogic, faceDistanceContainers, skipOlderThan, distanceLimits);
|
filteredFaceDistanceContainers = E_Distance.FilteredPostLoadFaceDistanceContainers(mapLogic, faceDistanceContainers, skipOlderThan, distanceLimits);
|
||||||
if (filteredFaceDistanceContainers.Length == 0)
|
if (filteredFaceDistanceContainers.Length == 0)
|
||||||
_Log.Information("All images have been filtered!");
|
_Logger?.LogInformation("All images have been filtered!");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sortingContainers = E_Distance.SetFaceMappingSortingCollectionThenGetSortedSortingContainers(_AppSettings.MaxDegreeOfParallelism, _MapConfiguration, ticks, mapLogic, distanceLimits, faceDistanceEncodings, filteredFaceDistanceContainers);
|
sortingContainers = E_Distance.SetFaceMappingSortingCollectionThenGetSortedSortingContainers(_AppSettings.MaxDegreeOfParallelism, _MapConfiguration, ticks, mapLogic, distanceLimits, faceDistanceEncodings, filteredFaceDistanceContainers);
|
||||||
@ -1194,7 +1158,7 @@ public partial class DlibDotNet
|
|||||||
distanceLimits = new(_Configuration.FaceAreaPermyriad, _Configuration.FaceConfidencePercent, _Configuration.FaceDistancePermyriad, _Configuration.RangeDaysDeltaTolerance, _Configuration.RangeDistanceTolerance, _Configuration.RangeFaceAreaPermyriadTolerance, _Configuration.RangeFaceConfidence, _Configuration.SortingMaximumPerFaceShouldBeHigh, useFiltersCounter);
|
distanceLimits = new(_Configuration.FaceAreaPermyriad, _Configuration.FaceConfidencePercent, _Configuration.FaceDistancePermyriad, _Configuration.RangeDaysDeltaTolerance, _Configuration.RangeDistanceTolerance, _Configuration.RangeFaceAreaPermyriadTolerance, _Configuration.RangeFaceConfidence, _Configuration.SortingMaximumPerFaceShouldBeHigh, useFiltersCounter);
|
||||||
filteredFaceDistanceContainers = E_Distance.FilteredPostLoadFaceDistanceContainers(mapLogic, faceDistanceContainers, skipOlderThan, distanceLimits);
|
filteredFaceDistanceContainers = E_Distance.FilteredPostLoadFaceDistanceContainers(mapLogic, faceDistanceContainers, skipOlderThan, distanceLimits);
|
||||||
if (filteredFaceDistanceContainers.Length == 0)
|
if (filteredFaceDistanceContainers.Length == 0)
|
||||||
_Log.Information("All images have been filtered!");
|
_Logger?.LogInformation("All images have been filtered!");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sortingContainers = E_Distance.SetFaceMappingSortingCollectionThenGetSortedSortingContainers(_AppSettings.MaxDegreeOfParallelism, _MapConfiguration, ticks, mapLogic, distanceLimits, faceDistanceEncodings, filteredFaceDistanceContainers);
|
sortingContainers = E_Distance.SetFaceMappingSortingCollectionThenGetSortedSortingContainers(_AppSettings.MaxDegreeOfParallelism, _MapConfiguration, ticks, mapLogic, distanceLimits, faceDistanceEncodings, filteredFaceDistanceContainers);
|
||||||
|
@ -41,10 +41,6 @@
|
|||||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||||
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Instance.Models.Stateless;
|
|
||||||
|
|
||||||
public static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -9,14 +9,12 @@ namespace View_by_Distance.Instance.Models;
|
|||||||
internal class F_Random
|
internal class F_Random
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly Serilog.ILogger? _Log;
|
|
||||||
private readonly Configuration _Configuration;
|
private readonly Configuration _Configuration;
|
||||||
private readonly JsonSerializerOptions _WriteIndentedJsonSerializerOptions;
|
private readonly JsonSerializerOptions _WriteIndentedJsonSerializerOptions;
|
||||||
|
|
||||||
internal F_Random(Configuration configuration)
|
internal F_Random(Configuration configuration)
|
||||||
{
|
{
|
||||||
_Configuration = configuration;
|
_Configuration = configuration;
|
||||||
_Log = Serilog.Log.ForContext<F_Random>();
|
|
||||||
_WriteIndentedJsonSerializerOptions = new JsonSerializerOptions { WriteIndented = false };
|
_WriteIndentedJsonSerializerOptions = new JsonSerializerOptions { WriteIndented = false };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Instance.Models;
|
using View_by_Distance.Instance.Models;
|
||||||
@ -10,9 +12,8 @@ namespace View_by_Distance.Instance;
|
|||||||
|
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
public static void Secondary(List<string> args)
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
||||||
{
|
{
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -27,9 +28,6 @@ public class Program
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
ILogger log = Log.ForContext<Program>();
|
|
||||||
int silentIndex = args.IndexOf("s");
|
int silentIndex = args.IndexOf("s");
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
args.RemoveAt(silentIndex);
|
args.RemoveAt(silentIndex);
|
||||||
@ -38,31 +36,28 @@ public class Program
|
|||||||
if (args is null)
|
if (args is null)
|
||||||
throw new Exception("args is null!");
|
throw new Exception("args is null!");
|
||||||
Shared.Models.Console console = new();
|
Shared.Models.Console console = new();
|
||||||
DlibDotNet _ = new(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
DlibDotNet _ = new(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
logger?.LogError(ex, "Error!");
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
}
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
log.Debug("Done. Bye");
|
logger?.LogDebug("Done. Bye");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Debug("Done. Press 'Enter' to end");
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
||||||
_ = Console.ReadLine();
|
_ = Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
||||||
if (args is not null)
|
if (args is not null)
|
||||||
Secondary(args.ToList());
|
Secondary(logger, args.ToList());
|
||||||
else
|
else
|
||||||
Secondary(new List<string>());
|
Secondary(logger, new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -35,7 +35,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||||
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||||
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
|
@ -210,7 +210,6 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly long _Ticks;
|
private readonly long _Ticks;
|
||||||
private readonly Serilog.ILogger? _Log;
|
|
||||||
private readonly Configuration? _Configuration;
|
private readonly Configuration? _Configuration;
|
||||||
private readonly string _EDistanceContentTicksDirectory;
|
private readonly string _EDistanceContentTicksDirectory;
|
||||||
private readonly ReadOnlyDictionary<long, int> _PersonKeyToCount;
|
private readonly ReadOnlyDictionary<long, int> _PersonKeyToCount;
|
||||||
@ -225,10 +224,7 @@ public partial class MapLogic : Shared.Models.Methods.IMapLogic
|
|||||||
{
|
{
|
||||||
_Ticks = ticks;
|
_Ticks = ticks;
|
||||||
_Configuration = configuration;
|
_Configuration = configuration;
|
||||||
_Log = Serilog.Log.ForContext<MapLogic>();
|
|
||||||
_PropertyConfiguration = propertyConfiguration;
|
_PropertyConfiguration = propertyConfiguration;
|
||||||
if (_Log is null)
|
|
||||||
{ }
|
|
||||||
ReadOnlyDictionary<long, int> readOnlyPersonKeyToCount;
|
ReadOnlyDictionary<long, int> readOnlyPersonKeyToCount;
|
||||||
List<PersonContainer> notMappedPersonContainers = new();
|
List<PersonContainer> notMappedPersonContainers = new();
|
||||||
Dictionary<int, List<(string, int)>> skipCollection = new();
|
Dictionary<int, List<(string, int)>> skipCollection = new();
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Map.Models.Stateless;
|
|
||||||
|
|
||||||
internal static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -39,10 +39,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using ShellProgressBar;
|
using ShellProgressBar;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
@ -19,7 +19,7 @@ public class MetadataQuery
|
|||||||
private readonly IConfigurationRoot _ConfigurationRoot;
|
private readonly IConfigurationRoot _ConfigurationRoot;
|
||||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||||
|
|
||||||
public MetadataQuery(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
public MetadataQuery(List<string> args, ILogger<Program> logger, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
||||||
{
|
{
|
||||||
if (isSilent)
|
if (isSilent)
|
||||||
{ }
|
{ }
|
||||||
@ -30,14 +30,13 @@ public class MetadataQuery
|
|||||||
long ticks = DateTime.Now.Ticks;
|
long ticks = DateTime.Now.Ticks;
|
||||||
_WorkingDirectory = workingDirectory;
|
_WorkingDirectory = workingDirectory;
|
||||||
_ConfigurationRoot = configurationRoot;
|
_ConfigurationRoot = configurationRoot;
|
||||||
ILogger? log = Log.ForContext<MetadataQuery>();
|
|
||||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
_PropertyConfiguration = propertyConfiguration;
|
_PropertyConfiguration = propertyConfiguration;
|
||||||
_Configuration = configuration;
|
_Configuration = configuration;
|
||||||
log.Information(propertyConfiguration.RootDirectory);
|
logger?.LogInformation(propertyConfiguration.RootDirectory);
|
||||||
Verify();
|
Verify();
|
||||||
MetadataQueryFilesInDirectories(log, ticks);
|
MetadataQueryFilesInDirectories(logger, ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Verify()
|
private void Verify()
|
||||||
@ -122,10 +121,10 @@ public class MetadataQuery
|
|||||||
return keyValuePairs;
|
return keyValuePairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MetadataQueryFilesInDirectories(ILogger log, long ticks)
|
private void MetadataQueryFilesInDirectories(ILogger<Program>? logger, long ticks)
|
||||||
{
|
{
|
||||||
List<(string FileName, string Count, string TagGroup, string TagIdName, string Value)> collection = GetCollection(ticks);
|
List<(string FileName, string Count, string TagGroup, string TagIdName, string Value)> collection = GetCollection(ticks);
|
||||||
log.Information($"Ready to query {collection.Count} entries?");
|
logger?.LogInformation($"Ready to query {collection.Count} entries?");
|
||||||
IEnumerable<(string FileName, string Count, string TagGroup, string TagIdName, string Value)> enumerable()
|
IEnumerable<(string FileName, string Count, string TagGroup, string TagIdName, string Value)> enumerable()
|
||||||
{
|
{
|
||||||
foreach ((string FileName, string Count, string TagGroup, string TagIdName, string Value) l in collection)
|
foreach ((string FileName, string Count, string TagGroup, string TagIdName, string Value) l in collection)
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Metadata.Query.Models.Stateless;
|
|
||||||
|
|
||||||
public static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Metadata.Query.Models;
|
using View_by_Distance.Metadata.Query.Models;
|
||||||
@ -11,9 +13,8 @@ namespace View_by_Distance.Metadata.Query;
|
|||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Secondary(List<string> args)
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
||||||
{
|
{
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -30,9 +31,6 @@ public class Program
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
ILogger log = Log.ForContext<Program>();
|
|
||||||
int silentIndex = args.IndexOf("s");
|
int silentIndex = args.IndexOf("s");
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
args.RemoveAt(silentIndex);
|
args.RemoveAt(silentIndex);
|
||||||
@ -41,31 +39,28 @@ public class Program
|
|||||||
if (args is null)
|
if (args is null)
|
||||||
throw new Exception("args is null!");
|
throw new Exception("args is null!");
|
||||||
Shared.Models.Console console = new();
|
Shared.Models.Console console = new();
|
||||||
_ = new MetadataQuery(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
_ = new MetadataQuery(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
logger?.LogError(ex, "Error!");
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
}
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
log.Debug("Done. Bye");
|
logger?.LogDebug("Done. Bye");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Debug("Done. Press 'Enter' to end");
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
||||||
_ = Console.ReadLine();
|
_ = Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
||||||
if (args is not null)
|
if (args is not null)
|
||||||
Secondary(args.ToList());
|
Secondary(logger, args.ToList());
|
||||||
else
|
else
|
||||||
Secondary(new List<string>());
|
Secondary(logger, new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -34,7 +34,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
29
Metadata/Models/Avi.cs
Normal file
29
Metadata/Models/Avi.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace View_by_Distance.Metadata.Models;
|
||||||
|
|
||||||
|
public record Avi(string? FramesPerSecond1,
|
||||||
|
string? SamplesPerSecond2,
|
||||||
|
string? Duration3,
|
||||||
|
string? VideoCodec4,
|
||||||
|
string? AudioCodec5,
|
||||||
|
string? Width6,
|
||||||
|
string? Height7,
|
||||||
|
string? Streams8,
|
||||||
|
string? DateTimeOriginal320)
|
||||||
|
{
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
string result = JsonSerializer.Serialize(this, AviSourceGenerationContext.Default.Avi);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||||
|
[JsonSerializable(typeof(Avi))]
|
||||||
|
public partial class AviSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
@ -16,7 +16,6 @@ namespace View_by_Distance.Metadata.Models;
|
|||||||
public class B_Metadata : IMetadata<MetadataExtractor.Directory>
|
public class B_Metadata : IMetadata<MetadataExtractor.Directory>
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly Serilog.ILogger? _Log;
|
|
||||||
private readonly bool _PropertiesChangedForMetadata;
|
private readonly bool _PropertiesChangedForMetadata;
|
||||||
private readonly IPropertyConfiguration _PropertyConfiguration;
|
private readonly IPropertyConfiguration _PropertyConfiguration;
|
||||||
private readonly bool _ForceMetadataLastWriteTimeToCreationTime;
|
private readonly bool _ForceMetadataLastWriteTimeToCreationTime;
|
||||||
@ -26,7 +25,6 @@ public class B_Metadata : IMetadata<MetadataExtractor.Directory>
|
|||||||
public B_Metadata(IPropertyConfiguration propertyConfiguration)
|
public B_Metadata(IPropertyConfiguration propertyConfiguration)
|
||||||
{
|
{
|
||||||
_PropertiesChangedForMetadata = false;
|
_PropertiesChangedForMetadata = false;
|
||||||
_Log = Serilog.Log.ForContext<B_Metadata>();
|
|
||||||
_PropertyConfiguration = propertyConfiguration;
|
_PropertyConfiguration = propertyConfiguration;
|
||||||
_ForceMetadataLastWriteTimeToCreationTime = false;
|
_ForceMetadataLastWriteTimeToCreationTime = false;
|
||||||
_WriteIndentedJsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true };
|
_WriteIndentedJsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true };
|
||||||
@ -35,7 +33,6 @@ public class B_Metadata : IMetadata<MetadataExtractor.Directory>
|
|||||||
|
|
||||||
public B_Metadata(IPropertyConfiguration propertyConfiguration, bool forceMetadataLastWriteTimeToCreationTime, bool propertiesChangedForMetadata, string bResultsFullGroupDirectory)
|
public B_Metadata(IPropertyConfiguration propertyConfiguration, bool forceMetadataLastWriteTimeToCreationTime, bool propertiesChangedForMetadata, string bResultsFullGroupDirectory)
|
||||||
{
|
{
|
||||||
_Log = Serilog.Log.ForContext<B_Metadata>();
|
|
||||||
_PropertyConfiguration = propertyConfiguration;
|
_PropertyConfiguration = propertyConfiguration;
|
||||||
_PropertiesChangedForMetadata = propertiesChangedForMetadata;
|
_PropertiesChangedForMetadata = propertiesChangedForMetadata;
|
||||||
_ForceMetadataLastWriteTimeToCreationTime = forceMetadataLastWriteTimeToCreationTime;
|
_ForceMetadataLastWriteTimeToCreationTime = forceMetadataLastWriteTimeToCreationTime;
|
||||||
|
194
Metadata/Models/Exif.cs
Normal file
194
Metadata/Models/Exif.cs
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace View_by_Distance.Metadata.Models;
|
||||||
|
|
||||||
|
public record Exif(string? InteropIndex1,
|
||||||
|
string? Noise37389,
|
||||||
|
string? FocalPlaneXResolutionTiffEp37390,
|
||||||
|
string? FocalPlaneYResolutionTiffEp37391,
|
||||||
|
string? ImageNumber37393,
|
||||||
|
string? SecurityClassification37394,
|
||||||
|
string? ImageHistory37395,
|
||||||
|
string? SubjectLocationTiffEp37396,
|
||||||
|
string? ExposureIndexTiffEp37397,
|
||||||
|
string? SpatialFreqResponseTiffEp37388,
|
||||||
|
string? StandardIdTiffEp37398,
|
||||||
|
string? UserComment37510,
|
||||||
|
string? SubsecondTime37520,
|
||||||
|
string? SubsecondTimeOriginal37521,
|
||||||
|
string? SubsecondTimeDigitized37522,
|
||||||
|
string? WinTitle40091,
|
||||||
|
string? WinComment40092,
|
||||||
|
string? WinAuthor40093,
|
||||||
|
string? WinKeywords40094,
|
||||||
|
string? Makernote37500,
|
||||||
|
string? WinSubject40095,
|
||||||
|
string? FlashEnergyTiffEp37387,
|
||||||
|
string? Flash37385,
|
||||||
|
string? IsoSpeedLatitudeYYY34868,
|
||||||
|
string? IsoSpeedLatitudeZZZ34869,
|
||||||
|
string? ExifVersion36864,
|
||||||
|
string? DateTimeOriginal36867,
|
||||||
|
string? DateTimeDigitized36868,
|
||||||
|
string? TimeZone36880,
|
||||||
|
string? TimeZoneOriginal36881,
|
||||||
|
string? TimeZoneDigitized36882,
|
||||||
|
string? FocalLength37386,
|
||||||
|
string? ComponentsConfiguration37121,
|
||||||
|
string? ShutterSpeed37377,
|
||||||
|
string? Aperture37378,
|
||||||
|
string? BrightnessValue37379,
|
||||||
|
string? ExposureBias37380,
|
||||||
|
string? MaxAperture37381,
|
||||||
|
string? SubjectDistance37382,
|
||||||
|
string? MeteringMode37383,
|
||||||
|
string? WhiteBalance37384,
|
||||||
|
string? CompressedAverageBitsPerPixel37122,
|
||||||
|
string? IsoSpeed34867,
|
||||||
|
string? FlashpixVersion40960,
|
||||||
|
string? ExifImageWidth40962,
|
||||||
|
string? Sharpness41994,
|
||||||
|
string? DeviceSettingDescription41995,
|
||||||
|
string? SubjectDistanceRange41996,
|
||||||
|
string? ImageUniqueId42016,
|
||||||
|
string? CameraOwnerName42032,
|
||||||
|
string? BodySerialNumber42033,
|
||||||
|
string? LensSpecification42034,
|
||||||
|
string? LensMake42035,
|
||||||
|
string? Saturation41993,
|
||||||
|
string? LensModel42036,
|
||||||
|
string? GdalMetadata42112,
|
||||||
|
string? GdalNoData42113,
|
||||||
|
string? Gamma42240,
|
||||||
|
string? PrintImageMatchingInfo50341,
|
||||||
|
string? PanasonicTitle50898,
|
||||||
|
string? PanasonicTitle250899,
|
||||||
|
string? Padding59932,
|
||||||
|
string? Lens65002,
|
||||||
|
string? LensSerialNumber42037,
|
||||||
|
string? ColorSpace40961,
|
||||||
|
string? Contrast41992,
|
||||||
|
string? SceneCaptureType41990,
|
||||||
|
string? ExifImageHeight40963,
|
||||||
|
string? RelatedSoundFile40964,
|
||||||
|
string? FlashEnergy41483,
|
||||||
|
string? SpatialFreqResponse41484,
|
||||||
|
string? FocalPlaneXResolution41486,
|
||||||
|
string? FocalPlaneYResolution41487,
|
||||||
|
string? FocalPlaneResolutionUnit41488,
|
||||||
|
string? SubjectLocation41492,
|
||||||
|
string? GainControl41991,
|
||||||
|
string? ExposureIndex41493,
|
||||||
|
string? FileSource41728,
|
||||||
|
string? SceneType41729,
|
||||||
|
string? CfaPattern41730,
|
||||||
|
string? CustomRendered41985,
|
||||||
|
string? ExposureMode41986,
|
||||||
|
string? WhiteBalanceMode41987,
|
||||||
|
string? DigitalZoomRatio41988,
|
||||||
|
string? Film35MMEquivFocalLength41989,
|
||||||
|
string? SensingMethod41495,
|
||||||
|
string? RecommendedExposureIndex34866,
|
||||||
|
string? StandardOutputSensitivity34865,
|
||||||
|
string? SensitivityType34864,
|
||||||
|
string? YResolution283,
|
||||||
|
string? PlanarConfiguration284,
|
||||||
|
string? PageName285,
|
||||||
|
string? ResolutionUnit296,
|
||||||
|
string? PageNumber297,
|
||||||
|
string? TransferFunction301,
|
||||||
|
string? Software305,
|
||||||
|
string? DateTime306,
|
||||||
|
string? XResolution282,
|
||||||
|
string? Artist315,
|
||||||
|
string? Predictor317,
|
||||||
|
string? WhitePoint318,
|
||||||
|
string? PrimaryChromaticities319,
|
||||||
|
string? TileWidth322,
|
||||||
|
string? TileLength323,
|
||||||
|
string? TileOffsets324,
|
||||||
|
string? TileByteCounts325,
|
||||||
|
string? SubIfdOffset330,
|
||||||
|
string? HostComputer316,
|
||||||
|
string? ExtraSamples338,
|
||||||
|
string? MaxSampleValue281,
|
||||||
|
string? StripByteCounts279,
|
||||||
|
string? InteropVersion2,
|
||||||
|
string? NewSubfileType254,
|
||||||
|
string? SubfileType255,
|
||||||
|
string? ImageWidth256,
|
||||||
|
string? ImageHeight257,
|
||||||
|
string? BitsPerSample258,
|
||||||
|
string? Compression259,
|
||||||
|
string? PhotometricInterpretation262,
|
||||||
|
string? MinSampleValue280,
|
||||||
|
string? Thresholding263,
|
||||||
|
string? DocumentName269,
|
||||||
|
string? ImageDescription270,
|
||||||
|
string? Make271,
|
||||||
|
string? Model272,
|
||||||
|
string? StripOffsets273,
|
||||||
|
string? Orientation274,
|
||||||
|
string? SamplesPerPixel277,
|
||||||
|
string? RowsPerStrip278,
|
||||||
|
string? FillOrder266,
|
||||||
|
string? SampleFormat339,
|
||||||
|
string? TransferRange342,
|
||||||
|
string? JpegTables347,
|
||||||
|
string? FNumber33437,
|
||||||
|
string? PixelScale33550,
|
||||||
|
string? IptcNaa33723,
|
||||||
|
string? ModelTiePoint33922,
|
||||||
|
string? PhotoshopSettings34377,
|
||||||
|
string? InterColorProfile34675,
|
||||||
|
string? GeoTiffGeoKeys34735,
|
||||||
|
string? GeoTiffGeoDoubleParams34736,
|
||||||
|
string? ExposureTime33434,
|
||||||
|
string? GeoTiffGeoAsciiParams34737,
|
||||||
|
string? SpectralSensitivity34852,
|
||||||
|
string? IsoEquivalent34855,
|
||||||
|
string? OptoElectricConversionFunction34856,
|
||||||
|
string? Interlace34857,
|
||||||
|
string? TimeZoneOffsetTiffEp34858,
|
||||||
|
string? SelfTimerModeTiffEp34859,
|
||||||
|
string? TimeZoneOffset34858,
|
||||||
|
string? SelfTimerMode34859,
|
||||||
|
string? ExposureProgram34850,
|
||||||
|
string? Copyright33432,
|
||||||
|
string? BatteryLevel33423,
|
||||||
|
string? CfaPattern233422,
|
||||||
|
string? JpegProc512,
|
||||||
|
string? JpegRestartInterval515,
|
||||||
|
string? JpegLosslessPredictors517,
|
||||||
|
string? JpegPointTransforms518,
|
||||||
|
string? JpegQTables519,
|
||||||
|
string? JpegDcTables520,
|
||||||
|
string? JpegAcTables521,
|
||||||
|
string? YCbCrCoefficients529,
|
||||||
|
string? YCbCrSubsampling530,
|
||||||
|
string? YCbCrPositioning531,
|
||||||
|
string? ReferenceBlackWhite532,
|
||||||
|
string? StripRowCounts559,
|
||||||
|
string? ApplicationNotes700,
|
||||||
|
string? RelatedImageFileFormat4096,
|
||||||
|
string? RelatedImageWidth4097,
|
||||||
|
string? RelatedImageHeight4098,
|
||||||
|
string? Rating18246,
|
||||||
|
string? RatingPercent18249,
|
||||||
|
string? CfaRepeatPatternDim33421)
|
||||||
|
{
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
string result = JsonSerializer.Serialize(this, ExifSourceGenerationContext.Default.Exif);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||||
|
[JsonSerializable(typeof(Exif))]
|
||||||
|
public partial class ExifSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
36
Metadata/Models/QuickTimeMovieHeader.cs
Normal file
36
Metadata/Models/QuickTimeMovieHeader.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace View_by_Distance.Metadata.Models;
|
||||||
|
|
||||||
|
public record QuickTimeMovieHeader(string? Version1,
|
||||||
|
string? NextTrackId16,
|
||||||
|
string? CurrentTime15,
|
||||||
|
string? SelectionDuration14,
|
||||||
|
string? SelectionTime13,
|
||||||
|
string? PosterTime12,
|
||||||
|
string? PreviewDuration11,
|
||||||
|
string? PreviewTime10,
|
||||||
|
string? Matrix9,
|
||||||
|
string? PreferredVolume8,
|
||||||
|
string? PreferredRate7,
|
||||||
|
string? Duration6,
|
||||||
|
string? TimeScale5,
|
||||||
|
string? Modified4,
|
||||||
|
string? Created3,
|
||||||
|
string? Flags2)
|
||||||
|
{
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
string result = JsonSerializer.Serialize(this, QuickTimeMovieHeaderSourceGenerationContext.Default.QuickTimeMovieHeader);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||||
|
[JsonSerializable(typeof(QuickTimeMovieHeader))]
|
||||||
|
public partial class QuickTimeMovieHeaderSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
33
Metadata/Models/QuickTimeTrackHeader.cs
Normal file
33
Metadata/Models/QuickTimeTrackHeader.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace View_by_Distance.Metadata.Models;
|
||||||
|
|
||||||
|
public record QuickTimeTrackHeader(string? Version1,
|
||||||
|
string? Flags2,
|
||||||
|
string? Created3,
|
||||||
|
string? Modified4,
|
||||||
|
string? TrackId5,
|
||||||
|
string? Duration6,
|
||||||
|
string? Layer7,
|
||||||
|
string? AlternateGroup8,
|
||||||
|
string? Volume9,
|
||||||
|
string? Width10,
|
||||||
|
string? Height11,
|
||||||
|
string? Matrix12,
|
||||||
|
string? Rotation13)
|
||||||
|
{
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
string result = JsonSerializer.Serialize(this, QuickTimeTrackHeaderSourceGenerationContext.Default.QuickTimeTrackHeader);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||||
|
[JsonSerializable(typeof(QuickTimeTrackHeader))]
|
||||||
|
public partial class QuickTimeTrackHeaderSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Metadata.Models.Stateless;
|
|
||||||
|
|
||||||
internal static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -39,10 +39,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using ShellProgressBar;
|
using ShellProgressBar;
|
||||||
using View_by_Distance.Mirror.Length.Models;
|
using View_by_Distance.Mirror.Length.Models;
|
||||||
using View_by_Distance.Shared.Models.Methods;
|
using View_by_Distance.Shared.Models.Methods;
|
||||||
@ -17,7 +17,7 @@ public class MirrorLength
|
|||||||
private readonly IConfigurationRoot _ConfigurationRoot;
|
private readonly IConfigurationRoot _ConfigurationRoot;
|
||||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||||
|
|
||||||
public MirrorLength(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
public MirrorLength(List<string> args, ILogger<Program> logger, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
||||||
{
|
{
|
||||||
if (isSilent)
|
if (isSilent)
|
||||||
{ }
|
{ }
|
||||||
@ -28,14 +28,13 @@ public class MirrorLength
|
|||||||
long ticks = DateTime.Now.Ticks;
|
long ticks = DateTime.Now.Ticks;
|
||||||
_WorkingDirectory = workingDirectory;
|
_WorkingDirectory = workingDirectory;
|
||||||
_ConfigurationRoot = configurationRoot;
|
_ConfigurationRoot = configurationRoot;
|
||||||
ILogger? log = Log.ForContext<MirrorLength>();
|
|
||||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
_PropertyConfiguration = propertyConfiguration;
|
_PropertyConfiguration = propertyConfiguration;
|
||||||
_Configuration = configuration;
|
_Configuration = configuration;
|
||||||
log.Information(propertyConfiguration.RootDirectory);
|
logger?.LogInformation(propertyConfiguration.RootDirectory);
|
||||||
Verify();
|
Verify();
|
||||||
MirrorLengthFilesInDirectories(log, ticks);
|
MirrorLengthFilesInDirectories(logger, ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Verify()
|
private void Verify()
|
||||||
@ -189,7 +188,7 @@ public class MirrorLength
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MirrorLengthFilesInDirectories(ILogger log, long ticks)
|
private void MirrorLengthFilesInDirectories(ILogger<Program>? logger, long ticks)
|
||||||
{
|
{
|
||||||
string message = nameof(MirrorLength);
|
string message = nameof(MirrorLength);
|
||||||
List<(string, string, int)> collectionForMarkDown;
|
List<(string, string, int)> collectionForMarkDown;
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Mirror.Length.Models.Stateless;
|
|
||||||
|
|
||||||
public static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Mirror.Length.Models;
|
using View_by_Distance.Mirror.Length.Models;
|
||||||
@ -11,9 +13,8 @@ namespace View_by_Distance.Mirror.Length;
|
|||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Secondary(List<string> args)
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
||||||
{
|
{
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -30,9 +31,6 @@ public class Program
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
ILogger log = Log.ForContext<Program>();
|
|
||||||
int silentIndex = args.IndexOf("s");
|
int silentIndex = args.IndexOf("s");
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
args.RemoveAt(silentIndex);
|
args.RemoveAt(silentIndex);
|
||||||
@ -41,31 +39,28 @@ public class Program
|
|||||||
if (args is null)
|
if (args is null)
|
||||||
throw new Exception("args is null!");
|
throw new Exception("args is null!");
|
||||||
Shared.Models.Console console = new();
|
Shared.Models.Console console = new();
|
||||||
_ = new MirrorLength(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
_ = new MirrorLength(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
logger?.LogError(ex, "Error!");
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
}
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
log.Debug("Done. Bye");
|
logger?.LogDebug("Done. Bye");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Debug("Done. Press 'Enter' to end");
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
||||||
_ = Console.ReadLine();
|
_ = Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
||||||
if (args is not null)
|
if (args is not null)
|
||||||
Secondary(args.ToList());
|
Secondary(logger, args.ToList());
|
||||||
else
|
else
|
||||||
Secondary(new List<string>());
|
Secondary(logger, new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Move.By.Id.Models.Stateless;
|
|
||||||
|
|
||||||
public static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -39,10 +39,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Property\Property.csproj" />
|
<ProjectReference Include="..\Property\Property.csproj" />
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using ShellProgressBar;
|
using ShellProgressBar;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using View_by_Distance.Move.By.Id.Models;
|
using View_by_Distance.Move.By.Id.Models;
|
||||||
@ -20,7 +20,7 @@ public class MoveById
|
|||||||
private readonly IConfigurationRoot _ConfigurationRoot;
|
private readonly IConfigurationRoot _ConfigurationRoot;
|
||||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||||
|
|
||||||
public MoveById(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
public MoveById(List<string> args, ILogger<Program> logger, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
||||||
{
|
{
|
||||||
if (isSilent)
|
if (isSilent)
|
||||||
{ }
|
{ }
|
||||||
@ -30,7 +30,6 @@ public class MoveById
|
|||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
_WorkingDirectory = workingDirectory;
|
_WorkingDirectory = workingDirectory;
|
||||||
_ConfigurationRoot = configurationRoot;
|
_ConfigurationRoot = configurationRoot;
|
||||||
ILogger? log = Log.ForContext<MoveById>();
|
|
||||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
_PropertyConfiguration = propertyConfiguration;
|
_PropertyConfiguration = propertyConfiguration;
|
||||||
@ -39,7 +38,7 @@ public class MoveById
|
|||||||
string? comparePathRoot = Path.GetDirectoryName(appSettings.ComparePathsFile);
|
string? comparePathRoot = Path.GetDirectoryName(appSettings.ComparePathsFile);
|
||||||
if (comparePathRoot is null || comparePathRoot == propertyConfiguration.RootDirectory)
|
if (comparePathRoot is null || comparePathRoot == propertyConfiguration.RootDirectory)
|
||||||
throw new Exception("Nested isn't allowed!");
|
throw new Exception("Nested isn't allowed!");
|
||||||
log.Information(propertyConfiguration.RootDirectory);
|
logger?.LogInformation(propertyConfiguration.RootDirectory);
|
||||||
Property.Models.Configuration.Verify(propertyConfiguration, requireExist: false);
|
Property.Models.Configuration.Verify(propertyConfiguration, requireExist: false);
|
||||||
Verify();
|
Verify();
|
||||||
string json = File.ReadAllText(appSettings.ComparePathsFile);
|
string json = File.ReadAllText(appSettings.ComparePathsFile);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Move.By.Id.Models;
|
using View_by_Distance.Move.By.Id.Models;
|
||||||
@ -11,9 +13,8 @@ namespace View_by_Distance.Move.By.Id;
|
|||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Secondary(List<string> args)
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
||||||
{
|
{
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -28,9 +29,6 @@ public class Program
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
ILogger log = Log.ForContext<Program>();
|
|
||||||
int silentIndex = args.IndexOf("s");
|
int silentIndex = args.IndexOf("s");
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
args.RemoveAt(silentIndex);
|
args.RemoveAt(silentIndex);
|
||||||
@ -39,31 +37,28 @@ public class Program
|
|||||||
if (args is null)
|
if (args is null)
|
||||||
throw new Exception("args is null!");
|
throw new Exception("args is null!");
|
||||||
Shared.Models.Console console = new();
|
Shared.Models.Console console = new();
|
||||||
_ = new MoveById(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
_ = new MoveById(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
logger?.LogError(ex, "Error!");
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
}
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
log.Debug("Done. Bye");
|
logger?.LogDebug("Done. Bye");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Debug("Done. Press 'Enter' to end");
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
||||||
_ = Console.ReadLine();
|
_ = Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
||||||
if (args is not null)
|
if (args is not null)
|
||||||
Secondary(args.ToList());
|
Secondary(logger, args.ToList());
|
||||||
else
|
else
|
||||||
Secondary(new List<string>());
|
Secondary(logger, new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Offset.Date.Time.Original.Models.Stateless;
|
|
||||||
|
|
||||||
public static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -39,10 +39,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using ShellProgressBar;
|
using ShellProgressBar;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
@ -30,7 +30,7 @@ public class OffsetDateTimeOriginal
|
|||||||
private readonly IConfigurationRoot _ConfigurationRoot;
|
private readonly IConfigurationRoot _ConfigurationRoot;
|
||||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||||
|
|
||||||
public OffsetDateTimeOriginal(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
public OffsetDateTimeOriginal(List<string> args, ILogger<Program> logger, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
||||||
{
|
{
|
||||||
if (isSilent)
|
if (isSilent)
|
||||||
{ }
|
{ }
|
||||||
@ -40,14 +40,13 @@ public class OffsetDateTimeOriginal
|
|||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
_WorkingDirectory = workingDirectory;
|
_WorkingDirectory = workingDirectory;
|
||||||
_ConfigurationRoot = configurationRoot;
|
_ConfigurationRoot = configurationRoot;
|
||||||
ILogger? log = Log.ForContext<OffsetDateTimeOriginal>();
|
|
||||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
_PropertyConfiguration = propertyConfiguration;
|
_PropertyConfiguration = propertyConfiguration;
|
||||||
_Configuration = configuration;
|
_Configuration = configuration;
|
||||||
log.Information(propertyConfiguration.RootDirectory);
|
logger?.LogInformation(propertyConfiguration.RootDirectory);
|
||||||
Verify();
|
Verify();
|
||||||
List<string> lines = OffsetDateTimeOriginalFilesInDirectories(log);
|
List<string> lines = OffsetDateTimeOriginalFilesInDirectories(logger);
|
||||||
if (lines.Any())
|
if (lines.Any())
|
||||||
File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", lines);
|
File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", lines);
|
||||||
}
|
}
|
||||||
@ -154,7 +153,7 @@ public class OffsetDateTimeOriginal
|
|||||||
|
|
||||||
#pragma warning restore CA1416
|
#pragma warning restore CA1416
|
||||||
|
|
||||||
private void DateFix(ILogger log, string sourceDirectory)
|
private void DateFix(ILogger<Program>? logger, string sourceDirectory)
|
||||||
{
|
{
|
||||||
string checkDirectory;
|
string checkDirectory;
|
||||||
ASCIIEncoding asciiEncoding = new();
|
ASCIIEncoding asciiEncoding = new();
|
||||||
@ -166,14 +165,14 @@ public class OffsetDateTimeOriginal
|
|||||||
{
|
{
|
||||||
checkDirectory = Path.Combine(sourceDirectory, "1");
|
checkDirectory = Path.Combine(sourceDirectory, "1");
|
||||||
if (!Directory.Exists(checkDirectory))
|
if (!Directory.Exists(checkDirectory))
|
||||||
log.Error($"<{checkDirectory}> doesn't exist!");
|
logger?.LogError($"<{checkDirectory}> doesn't exist!");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string badDirectory = Path.Combine(sourceDirectory, "Bad");
|
string badDirectory = Path.Combine(sourceDirectory, "Bad");
|
||||||
string targetDirectory = Path.Combine(sourceDirectory, "Target");
|
string targetDirectory = Path.Combine(sourceDirectory, "Target");
|
||||||
string[] minimumDirectory = Directory.GetDirectories(targetDirectory, "*", SearchOption.TopDirectoryOnly);
|
string[] minimumDirectory = Directory.GetDirectories(targetDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||||
if (minimumDirectory.Length != 1)
|
if (minimumDirectory.Length != 1)
|
||||||
log.Error($"<{checkDirectory}> doesn't exist!");
|
logger?.LogError($"<{checkDirectory}> doesn't exist!");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string format = "yyyy-MM-dd";
|
string format = "yyyy-MM-dd";
|
||||||
@ -181,7 +180,7 @@ public class OffsetDateTimeOriginal
|
|||||||
string[] badFiles = !Directory.Exists(badDirectory) ? Array.Empty<string>() : Directory.GetFiles(badDirectory, "*", SearchOption.TopDirectoryOnly);
|
string[] badFiles = !Directory.Exists(badDirectory) ? Array.Empty<string>() : Directory.GetFiles(badDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||||
string[] targetFiles = !Directory.Exists(targetDirectory) ? Array.Empty<string>() : Directory.GetFiles(targetDirectory, "*", SearchOption.TopDirectoryOnly);
|
string[] targetFiles = !Directory.Exists(targetDirectory) ? Array.Empty<string>() : Directory.GetFiles(targetDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||||
if (badFiles.Length != 1 || targetFiles.Length != 1 || maximumDirectory.Length != 1)
|
if (badFiles.Length != 1 || targetFiles.Length != 1 || maximumDirectory.Length != 1)
|
||||||
log.Error("bad file(s) or target file(s) or maximum directory doesn't equal 1!");
|
logger?.LogError("bad file(s) or target file(s) or maximum directory doesn't equal 1!");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int? badId;
|
int? badId;
|
||||||
@ -213,7 +212,7 @@ public class OffsetDateTimeOriginal
|
|||||||
if (!targetDateTimes.Any() || targetId is null)
|
if (!targetDateTimes.Any() || targetId is null)
|
||||||
throw new Exception(targetMessage);
|
throw new Exception(targetMessage);
|
||||||
if (badDateTimeOriginal is null || targetDateTimeOriginal is null)
|
if (badDateTimeOriginal is null || targetDateTimeOriginal is null)
|
||||||
log.Error("Date is null!");
|
logger?.LogError("Date is null!");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TimeSpan timeSpan = new(targetDateTimeOriginal.Value.Ticks - badDateTimeOriginal.Value.Ticks);
|
TimeSpan timeSpan = new(targetDateTimeOriginal.Value.Ticks - badDateTimeOriginal.Value.Ticks);
|
||||||
@ -225,10 +224,10 @@ public class OffsetDateTimeOriginal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<string> OffsetDateTimeOriginalFilesInDirectories(ILogger log)
|
private List<string> OffsetDateTimeOriginalFilesInDirectories(ILogger<Program>? logger)
|
||||||
{
|
{
|
||||||
List<string> results = new();
|
List<string> results = new();
|
||||||
DateFix(log, _PropertyConfiguration.RootDirectory);
|
DateFix(logger, _PropertyConfiguration.RootDirectory);
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Offset.Date.Time.Original.Models;
|
using View_by_Distance.Offset.Date.Time.Original.Models;
|
||||||
@ -11,9 +13,8 @@ namespace View_by_Distance.Offset.Date.Time.Original;
|
|||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Secondary(List<string> args)
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
||||||
{
|
{
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -30,9 +31,6 @@ public class Program
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
ILogger log = Log.ForContext<Program>();
|
|
||||||
int silentIndex = args.IndexOf("s");
|
int silentIndex = args.IndexOf("s");
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
args.RemoveAt(silentIndex);
|
args.RemoveAt(silentIndex);
|
||||||
@ -41,31 +39,28 @@ public class Program
|
|||||||
if (args is null)
|
if (args is null)
|
||||||
throw new Exception("args is null!");
|
throw new Exception("args is null!");
|
||||||
Shared.Models.Console console = new();
|
Shared.Models.Console console = new();
|
||||||
_ = new OffsetDateTimeOriginal(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
_ = new OffsetDateTimeOriginal(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
logger?.LogError(ex, "Error!");
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
}
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
log.Debug("Done. Bye");
|
logger?.LogDebug("Done. Bye");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Debug("Done. Press 'Enter' to end");
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
||||||
_ = Console.ReadLine();
|
_ = Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
||||||
if (args is not null)
|
if (args is not null)
|
||||||
Secondary(args.ToList());
|
Secondary(logger, args.ToList());
|
||||||
else
|
else
|
||||||
Secondary(new List<string>());
|
Secondary(logger, new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.PhotoPrism.Models.Stateless;
|
|
||||||
|
|
||||||
internal static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -35,7 +35,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
|
||||||
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||||
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
<PackageReference Include="WindowsShortcutFactory" Version="1.1.0" />
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.PrepareForOld.Models.Stateless;
|
|
||||||
|
|
||||||
public static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -35,10 +35,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.PrepareForOld.Models;
|
using View_by_Distance.PrepareForOld.Models;
|
||||||
@ -11,9 +13,8 @@ namespace View_by_Distance.PrepareForOld;
|
|||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Secondary(List<string> args)
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
||||||
{
|
{
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -30,9 +31,6 @@ public class Program
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
ILogger log = Log.ForContext<Program>();
|
|
||||||
int silentIndex = args.IndexOf("s");
|
int silentIndex = args.IndexOf("s");
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
args.RemoveAt(silentIndex);
|
args.RemoveAt(silentIndex);
|
||||||
@ -43,27 +41,24 @@ public class Program
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
logger?.LogError(ex, "Error!");
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
}
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
log.Debug("Done. Bye");
|
logger?.LogDebug("Done. Bye");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Debug("Done. Press 'Enter' to end");
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
||||||
_ = Console.ReadLine();
|
_ = Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
||||||
if (args is not null)
|
if (args is not null)
|
||||||
Secondary(args.ToList());
|
Secondary(logger, args.ToList());
|
||||||
else
|
else
|
||||||
Secondary(new List<string>());
|
Secondary(logger, new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.PropertyCompare.Models.Stateless;
|
|
||||||
|
|
||||||
internal static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -34,7 +34,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -15,7 +15,6 @@ public class A_Property
|
|||||||
public bool Reverse { get; }
|
public bool Reverse { get; }
|
||||||
public List<string> ExceptionsDirectories => _ExceptionsDirectories;
|
public List<string> ExceptionsDirectories => _ExceptionsDirectories;
|
||||||
|
|
||||||
private readonly Serilog.ILogger? _Log;
|
|
||||||
private readonly string _OutputExtension;
|
private readonly string _OutputExtension;
|
||||||
private readonly int _MaxDegreeOfParallelism;
|
private readonly int _MaxDegreeOfParallelism;
|
||||||
private readonly ASCIIEncoding _ASCIIEncoding;
|
private readonly ASCIIEncoding _ASCIIEncoding;
|
||||||
@ -31,7 +30,6 @@ public class A_Property
|
|||||||
_OutputExtension = outputExtension;
|
_OutputExtension = outputExtension;
|
||||||
_ASCIIEncoding = new ASCIIEncoding();
|
_ASCIIEncoding = new ASCIIEncoding();
|
||||||
_Configuration = propertyConfiguration;
|
_Configuration = propertyConfiguration;
|
||||||
_Log = Serilog.Log.ForContext<A_Property>();
|
|
||||||
_AngleBracketCollection = new List<string>();
|
_AngleBracketCollection = new List<string>();
|
||||||
_PropertyConfiguration = propertyConfiguration;
|
_PropertyConfiguration = propertyConfiguration;
|
||||||
_MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
_MaxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||||
@ -44,17 +42,6 @@ public class A_Property
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Shared.Models.Property GetImageProperty(Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, Item item, List<Tuple<string, DateTime>> sourceDirectoryFileTuples, List<string> parseExceptions, bool isIgnoreExtension)
|
private Shared.Models.Property GetImageProperty(Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, Item item, List<Tuple<string, DateTime>> sourceDirectoryFileTuples, List<string> parseExceptions, bool isIgnoreExtension)
|
||||||
{
|
{
|
||||||
Shared.Models.Property? result;
|
Shared.Models.Property? result;
|
||||||
@ -252,8 +239,6 @@ public class A_Property
|
|||||||
|
|
||||||
public void SavePropertyParallelWork(long ticks, Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, int t, Container[] containers)
|
public void SavePropertyParallelWork(long ticks, Shared.Models.Methods.IMetadata<MetadataExtractor.Directory> metadata, int t, Container[] containers)
|
||||||
{
|
{
|
||||||
if (_Log is null)
|
|
||||||
throw new NullReferenceException(nameof(_Log));
|
|
||||||
int total = 0;
|
int total = 0;
|
||||||
string message;
|
string message;
|
||||||
int totalSeconds;
|
int totalSeconds;
|
||||||
@ -277,22 +262,10 @@ public class A_Property
|
|||||||
totalSeconds = (int)Math.Truncate(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
totalSeconds = (int)Math.Truncate(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds);
|
||||||
message = $"{i + 1:000} [{container.Items.Count:000}] / {containersLength:000} - {total} / {t} total - {totalSeconds} total second(s) - {outputResolution} - {container.SourceDirectory}";
|
message = $"{i + 1:000} [{container.Items.Count:000}] / {containersLength:000} - {total} / {t} total - {totalSeconds} total second(s) - {outputResolution} - {container.SourceDirectory}";
|
||||||
SavePropertyParallelWork(_MaxDegreeOfParallelism, metadata, exceptions, sourceDirectoryChanges, container, container.Items, message);
|
SavePropertyParallelWork(_MaxDegreeOfParallelism, metadata, exceptions, sourceDirectoryChanges, container, container.Items, message);
|
||||||
foreach (Exception exception in exceptions)
|
|
||||||
_Log.Error(string.Concat(container.SourceDirectory, Environment.NewLine, exception.Message, Environment.NewLine, exception.StackTrace), exception);
|
|
||||||
if (exceptions.Count == container.Items.Count)
|
if (exceptions.Count == container.Items.Count)
|
||||||
throw new Exception(string.Concat("All in [", container.SourceDirectory, "]failed!"));
|
throw new Exception(string.Concat("All in [", container.SourceDirectory, "]failed!"));
|
||||||
if (exceptions.Count != 0)
|
if (exceptions.Count != 0)
|
||||||
_ExceptionsDirectories.Add(container.SourceDirectory);
|
_ExceptionsDirectories.Add(container.SourceDirectory);
|
||||||
if (Directory.GetFiles(propertyRoot, "*.txt", SearchOption.TopDirectoryOnly).Any())
|
|
||||||
{
|
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
|
||||||
{
|
|
||||||
_Log.Information("Press \"Y\" key when ready to continue or close console");
|
|
||||||
if (System.Console.ReadKey().Key == ConsoleKey.Y)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_Log.Information(". . .");
|
|
||||||
}
|
|
||||||
total += container.Items.Count;
|
total += container.Items.Count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Property.Models.Stateless;
|
|
||||||
|
|
||||||
internal static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -40,9 +40,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Rename.Models.Stateless;
|
|
||||||
|
|
||||||
public static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Rename.Models;
|
using View_by_Distance.Rename.Models;
|
||||||
@ -11,9 +13,8 @@ namespace View_by_Distance.Rename;
|
|||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Secondary(List<string> args)
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
||||||
{
|
{
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -28,9 +29,6 @@ public class Program
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
ILogger log = Log.ForContext<Program>();
|
|
||||||
int silentIndex = args.IndexOf("s");
|
int silentIndex = args.IndexOf("s");
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
args.RemoveAt(silentIndex);
|
args.RemoveAt(silentIndex);
|
||||||
@ -39,31 +37,28 @@ public class Program
|
|||||||
if (args is null)
|
if (args is null)
|
||||||
throw new Exception("args is null!");
|
throw new Exception("args is null!");
|
||||||
Shared.Models.Console console = new();
|
Shared.Models.Console console = new();
|
||||||
_ = new Rename(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
_ = new Rename(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
logger?.LogError(ex, "Error!");
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
}
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
log.Debug("Done. Bye");
|
logger?.LogDebug("Done. Bye");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Debug("Done. Press 'Enter' to end");
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
||||||
_ = Console.ReadLine();
|
_ = Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
||||||
if (args is not null)
|
if (args is not null)
|
||||||
Secondary(args.ToList());
|
Secondary(logger, args.ToList());
|
||||||
else
|
else
|
||||||
Secondary(new List<string>());
|
Secondary(logger, new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
using CliWrap;
|
using CliWrap;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using ShellProgressBar;
|
using ShellProgressBar;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using View_by_Distance.Metadata.Models;
|
using View_by_Distance.Metadata.Models;
|
||||||
@ -31,7 +31,7 @@ public class Rename
|
|||||||
private readonly IConfigurationRoot _ConfigurationRoot;
|
private readonly IConfigurationRoot _ConfigurationRoot;
|
||||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||||
|
|
||||||
public Rename(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
public Rename(List<string> args, ILogger<Program>? logger, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
||||||
{
|
{
|
||||||
if (isSilent)
|
if (isSilent)
|
||||||
{ }
|
{ }
|
||||||
@ -41,15 +41,14 @@ public class Rename
|
|||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
_WorkingDirectory = workingDirectory;
|
_WorkingDirectory = workingDirectory;
|
||||||
_ConfigurationRoot = configurationRoot;
|
_ConfigurationRoot = configurationRoot;
|
||||||
ILogger? log = Log.ForContext<Rename>();
|
|
||||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
_PropertyConfiguration = propertyConfiguration;
|
_PropertyConfiguration = propertyConfiguration;
|
||||||
_Configuration = configuration;
|
_Configuration = configuration;
|
||||||
log.Information(propertyConfiguration.RootDirectory);
|
logger?.LogInformation(propertyConfiguration.RootDirectory);
|
||||||
Property.Models.Configuration.Verify(propertyConfiguration, requireExist: false);
|
Property.Models.Configuration.Verify(propertyConfiguration, requireExist: false);
|
||||||
Verify();
|
Verify();
|
||||||
List<string> lines = RenameFilesInDirectories(log);
|
List<string> lines = RenameFilesInDirectories(logger);
|
||||||
if (lines.Any())
|
if (lines.Any())
|
||||||
{
|
{
|
||||||
File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", lines);
|
File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", lines);
|
||||||
@ -73,7 +72,7 @@ public class Rename
|
|||||||
throw new NullReferenceException(nameof(_PropertyConfiguration));
|
throw new NullReferenceException(nameof(_PropertyConfiguration));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<string> RenameFilesInDirectories(ILogger log)
|
private List<string> RenameFilesInDirectories(ILogger? logger)
|
||||||
{
|
{
|
||||||
List<string> results = new();
|
List<string> results = new();
|
||||||
string message;
|
string message;
|
||||||
@ -159,24 +158,24 @@ public class Rename
|
|||||||
File.WriteAllText($"{to}.paddedId", $"{to}{Environment.NewLine}{fileHolder.FullName}");
|
File.WriteAllText($"{to}.paddedId", $"{to}{Environment.NewLine}{fileHolder.FullName}");
|
||||||
}
|
}
|
||||||
ConsoleKey? consoleKey = null;
|
ConsoleKey? consoleKey = null;
|
||||||
log.Information($"Ready to Move {verifiedToDoCollection.Count} files[i](s)?");
|
logger?.LogInformation($"Ready to Move {verifiedToDoCollection.Count} files[i](s)?");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
log.Information("Press \"Y\" key to move files[i](s), \"N\" key to log files[i](s) or close console to not move files");
|
logger?.LogInformation("Press \"Y\" key to move files[i](s), \"N\" key to log files[i](s) or close console to not move files");
|
||||||
consoleKey = System.Console.ReadKey().Key;
|
consoleKey = System.Console.ReadKey().Key;
|
||||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log.Information(". . .");
|
logger?.LogInformation(". . .");
|
||||||
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
|
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
|
||||||
log.Information("Nothing moved!");
|
logger?.LogInformation("Nothing moved!");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
message = ") Renaming files";
|
message = ") Renaming files";
|
||||||
progressBar = new(count, message, options);
|
progressBar = new(count, message, options);
|
||||||
results.AddRange(Move(progressBar, verifiedToDoCollection));
|
results.AddRange(Move(progressBar, verifiedToDoCollection));
|
||||||
progressBar.Dispose();
|
progressBar.Dispose();
|
||||||
log.Information("Done Moving");
|
logger?.LogInformation("Done Moving");
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
@ -40,10 +40,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Resize.Models.Stateless;
|
|
||||||
|
|
||||||
internal static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -33,7 +33,6 @@
|
|||||||
<SupportedPlatform Include="browser" />
|
<SupportedPlatform Include="browser" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
<PackageReference Include="MetadataExtractor" Version="2.8.0" />
|
||||||
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
namespace View_by_Distance.Set.Created.Date.Models.Stateless;
|
|
||||||
|
|
||||||
public static class SerilogExtensionMethods
|
|
||||||
{
|
|
||||||
|
|
||||||
internal static void Warn(this Serilog.ILogger log, string messageTemplate) => log.Warning(messageTemplate);
|
|
||||||
|
|
||||||
internal static void Info(this Serilog.ILogger log, string messageTemplate) => log.Information(messageTemplate);
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Set.Created.Date.Models;
|
using View_by_Distance.Set.Created.Date.Models;
|
||||||
@ -11,9 +13,8 @@ namespace View_by_Distance.Set.Created.Date;
|
|||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
||||||
public static void Secondary(List<string> args)
|
public static void Secondary(ILogger<Program> logger, List<string> args)
|
||||||
{
|
{
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||||
@ -30,9 +31,6 @@ public class Program
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
string workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
ILogger log = Log.ForContext<Program>();
|
|
||||||
int silentIndex = args.IndexOf("s");
|
int silentIndex = args.IndexOf("s");
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
args.RemoveAt(silentIndex);
|
args.RemoveAt(silentIndex);
|
||||||
@ -41,31 +39,28 @@ public class Program
|
|||||||
if (args is null)
|
if (args is null)
|
||||||
throw new Exception("args is null!");
|
throw new Exception("args is null!");
|
||||||
Shared.Models.Console console = new();
|
Shared.Models.Console console = new();
|
||||||
_ = new SetCreatedDate(args, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
_ = new SetCreatedDate(args, logger, isEnvironment, configurationRoot, appSettings, workingDirectory, silentIndex > -1, console);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
log.Fatal(string.Concat(ex.Message, Environment.NewLine, ex.StackTrace));
|
logger?.LogError(ex, "Error!");
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Log.CloseAndFlush();
|
|
||||||
}
|
}
|
||||||
if (silentIndex > -1)
|
if (silentIndex > -1)
|
||||||
log.Debug("Done. Bye");
|
logger?.LogDebug("Done. Bye");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log.Debug("Done. Press 'Enter' to end");
|
logger?.LogDebug("Done. Press 'Enter' to end");
|
||||||
_ = Console.ReadLine();
|
_ = Console.ReadLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
ILogger<Program>? logger = Host.CreateDefaultBuilder(args).Build().Services.GetRequiredService<ILogger<Program>>();
|
||||||
if (args is not null)
|
if (args is not null)
|
||||||
Secondary(args.ToList());
|
Secondary(logger, args.ToList());
|
||||||
else
|
else
|
||||||
Secondary(new List<string>());
|
Secondary(logger, new List<string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -39,10 +39,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
<ProjectReference Include="..\Metadata\Metadata.csproj" />
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using ShellProgressBar;
|
using ShellProgressBar;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using View_by_Distance.Metadata.Models;
|
using View_by_Distance.Metadata.Models;
|
||||||
@ -23,7 +23,7 @@ public class SetCreatedDate
|
|||||||
private readonly IReadOnlyDictionary<string, string[]> _FileGroups;
|
private readonly IReadOnlyDictionary<string, string[]> _FileGroups;
|
||||||
private readonly Property.Models.Configuration _PropertyConfiguration;
|
private readonly Property.Models.Configuration _PropertyConfiguration;
|
||||||
|
|
||||||
public SetCreatedDate(List<string> args, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
public SetCreatedDate(List<string> args, ILogger<Program> logger, IsEnvironment isEnvironment, IConfigurationRoot configurationRoot, AppSettings appSettings, string workingDirectory, bool isSilent, IConsole console)
|
||||||
{
|
{
|
||||||
if (isSilent)
|
if (isSilent)
|
||||||
{ }
|
{ }
|
||||||
@ -33,16 +33,15 @@ public class SetCreatedDate
|
|||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
_WorkingDirectory = workingDirectory;
|
_WorkingDirectory = workingDirectory;
|
||||||
_ConfigurationRoot = configurationRoot;
|
_ConfigurationRoot = configurationRoot;
|
||||||
ILogger? log = Log.ForContext<SetCreatedDate>();
|
|
||||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
string[] directories = new string[] { propertyConfiguration.ResultContent };
|
string[] directories = new string[] { propertyConfiguration.ResultContent };
|
||||||
_FileGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, appSettings.CopyTo, directories);
|
_FileGroups = Shared.Models.Stateless.Methods.IPath.GetKeyValuePairs(propertyConfiguration, appSettings.CopyTo, directories);
|
||||||
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
_PropertyConfiguration = propertyConfiguration;
|
_PropertyConfiguration = propertyConfiguration;
|
||||||
_Configuration = configuration;
|
_Configuration = configuration;
|
||||||
log.Information(propertyConfiguration.RootDirectory);
|
logger?.LogInformation(propertyConfiguration.RootDirectory);
|
||||||
Verify();
|
Verify();
|
||||||
List<string> lines = SetCreatedDateFilesInDirectories(log);
|
List<string> lines = SetCreatedDateFilesInDirectories(logger);
|
||||||
File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", lines);
|
File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", lines);
|
||||||
if (lines.Count == 0)
|
if (lines.Count == 0)
|
||||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||||
@ -139,7 +138,7 @@ public class SetCreatedDate
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<string> SetCreatedDateFilesInDirectories(ILogger log)
|
private List<string> SetCreatedDateFilesInDirectories(ILogger<Program>? logger)
|
||||||
{
|
{
|
||||||
List<string> results = new();
|
List<string> results = new();
|
||||||
ProgressBar progressBar;
|
ProgressBar progressBar;
|
||||||
@ -154,23 +153,23 @@ public class SetCreatedDate
|
|||||||
progressBar = new(count, message, options);
|
progressBar = new(count, message, options);
|
||||||
List<Record> toDoCollection = GetToDoCollection(progressBar, filesCollection);
|
List<Record> toDoCollection = GetToDoCollection(progressBar, filesCollection);
|
||||||
progressBar.Dispose();
|
progressBar.Dispose();
|
||||||
log.Information($"Ready to set created date {toDoCollection.Count} file(s)?");
|
logger?.LogInformation($"Ready to set created date {toDoCollection.Count} file(s)?");
|
||||||
for (int y = 0; y < int.MaxValue; y++)
|
for (int y = 0; y < int.MaxValue; y++)
|
||||||
{
|
{
|
||||||
log.Information("Press \"Y\" key to set created date file(s), \"N\" key to log file(s) or close console to not set created date files");
|
logger?.LogInformation("Press \"Y\" key to set created date file(s), \"N\" key to log file(s) or close console to not set created date files");
|
||||||
consoleKey = System.Console.ReadKey().Key;
|
consoleKey = System.Console.ReadKey().Key;
|
||||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log.Information(". . .");
|
logger?.LogInformation(". . .");
|
||||||
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
|
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
|
||||||
log.Information("Nothing set!");
|
logger?.LogInformation("Nothing set!");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
progressBar = new(count, message, options);
|
progressBar = new(count, message, options);
|
||||||
results.AddRange(SetCreatedDateForeach(progressBar, toDoCollection));
|
results.AddRange(SetCreatedDateForeach(progressBar, toDoCollection));
|
||||||
progressBar.Dispose();
|
progressBar.Dispose();
|
||||||
log.Information("Done setting created date");
|
logger?.LogInformation("Done setting created date");
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,6 @@
|
|||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
||||||
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
|
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
|
||||||
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
|
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\BlurHash\BlurHash.csproj" />
|
<ProjectReference Include="..\BlurHash\BlurHash.csproj" />
|
||||||
|
@ -2,7 +2,6 @@ using Humanizer;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@ -16,7 +15,6 @@ namespace View_by_Distance.Tests;
|
|||||||
public partial class UnitTestCalculations
|
public partial class UnitTestCalculations
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly ILogger _Logger;
|
|
||||||
private readonly AppSettings _AppSettings;
|
private readonly AppSettings _AppSettings;
|
||||||
private readonly string _WorkingDirectory;
|
private readonly string _WorkingDirectory;
|
||||||
private readonly Configuration _Configuration;
|
private readonly Configuration _Configuration;
|
||||||
@ -26,13 +24,11 @@ public partial class UnitTestCalculations
|
|||||||
|
|
||||||
public UnitTestCalculations()
|
public UnitTestCalculations()
|
||||||
{
|
{
|
||||||
ILogger logger;
|
|
||||||
AppSettings appSettings;
|
AppSettings appSettings;
|
||||||
string workingDirectory;
|
string workingDirectory;
|
||||||
Configuration configuration;
|
Configuration configuration;
|
||||||
IsEnvironment isEnvironment;
|
IsEnvironment isEnvironment;
|
||||||
IConfigurationRoot configurationRoot;
|
IConfigurationRoot configurationRoot;
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Property.Models.Configuration propertyConfiguration;
|
Property.Models.Configuration propertyConfiguration;
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
@ -46,13 +42,8 @@ public partial class UnitTestCalculations
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
logger = Log.ForContext<UnitTestCalculations>();
|
|
||||||
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
logger.Information("Complete");
|
|
||||||
_Logger = logger;
|
|
||||||
_AppSettings = appSettings;
|
_AppSettings = appSettings;
|
||||||
_Configuration = configuration;
|
_Configuration = configuration;
|
||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
@ -71,7 +62,6 @@ public partial class UnitTestCalculations
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestMethodNull()
|
public void TestMethodNull()
|
||||||
{
|
{
|
||||||
Assert.IsFalse(_Logger is null);
|
|
||||||
Assert.IsFalse(_AppSettings is null);
|
Assert.IsFalse(_AppSettings is null);
|
||||||
Assert.IsFalse(_Configuration is null);
|
Assert.IsFalse(_Configuration is null);
|
||||||
Assert.IsFalse(_IsEnvironment is null);
|
Assert.IsFalse(_IsEnvironment is null);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||||
@ -13,7 +12,6 @@ namespace View_by_Distance.Tests;
|
|||||||
public class UnitTestExample
|
public class UnitTestExample
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly ILogger _Logger;
|
|
||||||
private readonly AppSettings _AppSettings;
|
private readonly AppSettings _AppSettings;
|
||||||
private readonly string _WorkingDirectory;
|
private readonly string _WorkingDirectory;
|
||||||
private readonly Configuration _Configuration;
|
private readonly Configuration _Configuration;
|
||||||
@ -23,13 +21,11 @@ public class UnitTestExample
|
|||||||
|
|
||||||
public UnitTestExample()
|
public UnitTestExample()
|
||||||
{
|
{
|
||||||
ILogger logger;
|
|
||||||
AppSettings appSettings;
|
AppSettings appSettings;
|
||||||
string workingDirectory;
|
string workingDirectory;
|
||||||
Configuration configuration;
|
Configuration configuration;
|
||||||
IsEnvironment isEnvironment;
|
IsEnvironment isEnvironment;
|
||||||
IConfigurationRoot configurationRoot;
|
IConfigurationRoot configurationRoot;
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Property.Models.Configuration propertyConfiguration;
|
Property.Models.Configuration propertyConfiguration;
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
@ -43,13 +39,8 @@ public class UnitTestExample
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
logger = Log.ForContext<UnitTestExample>();
|
|
||||||
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
logger.Information("Complete");
|
|
||||||
_Logger = logger;
|
|
||||||
_AppSettings = appSettings;
|
_AppSettings = appSettings;
|
||||||
_Configuration = configuration;
|
_Configuration = configuration;
|
||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
@ -61,7 +52,6 @@ public class UnitTestExample
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestMethodNull()
|
public void TestMethodNull()
|
||||||
{
|
{
|
||||||
Assert.IsFalse(_Logger is null);
|
|
||||||
Assert.IsFalse(_AppSettings is null);
|
Assert.IsFalse(_AppSettings is null);
|
||||||
Assert.IsFalse(_Configuration is null);
|
Assert.IsFalse(_Configuration is null);
|
||||||
Assert.IsFalse(_IsEnvironment is null);
|
Assert.IsFalse(_IsEnvironment is null);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@ -15,7 +14,6 @@ namespace View_by_Distance.Tests;
|
|||||||
public partial class UnitTestHardCoded
|
public partial class UnitTestHardCoded
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly ILogger _Logger;
|
|
||||||
private readonly AppSettings _AppSettings;
|
private readonly AppSettings _AppSettings;
|
||||||
private readonly string _WorkingDirectory;
|
private readonly string _WorkingDirectory;
|
||||||
private readonly Configuration _Configuration;
|
private readonly Configuration _Configuration;
|
||||||
@ -25,13 +23,11 @@ public partial class UnitTestHardCoded
|
|||||||
|
|
||||||
public UnitTestHardCoded()
|
public UnitTestHardCoded()
|
||||||
{
|
{
|
||||||
ILogger logger;
|
|
||||||
AppSettings appSettings;
|
AppSettings appSettings;
|
||||||
string workingDirectory;
|
string workingDirectory;
|
||||||
Configuration configuration;
|
Configuration configuration;
|
||||||
IsEnvironment isEnvironment;
|
IsEnvironment isEnvironment;
|
||||||
IConfigurationRoot configurationRoot;
|
IConfigurationRoot configurationRoot;
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Property.Models.Configuration propertyConfiguration;
|
Property.Models.Configuration propertyConfiguration;
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
@ -45,13 +41,8 @@ public partial class UnitTestHardCoded
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
logger = Log.ForContext<UnitTestHardCoded>();
|
|
||||||
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
logger.Information("Complete");
|
|
||||||
_Logger = logger;
|
|
||||||
_AppSettings = appSettings;
|
_AppSettings = appSettings;
|
||||||
_Configuration = configuration;
|
_Configuration = configuration;
|
||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
@ -70,7 +61,6 @@ public partial class UnitTestHardCoded
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestMethodNull()
|
public void TestMethodNull()
|
||||||
{
|
{
|
||||||
Assert.IsFalse(_Logger is null);
|
|
||||||
Assert.IsFalse(_AppSettings is null);
|
Assert.IsFalse(_AppSettings is null);
|
||||||
Assert.IsFalse(_Configuration is null);
|
Assert.IsFalse(_Configuration is null);
|
||||||
Assert.IsFalse(_IsEnvironment is null);
|
Assert.IsFalse(_IsEnvironment is null);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing.Imaging;
|
using System.Drawing.Imaging;
|
||||||
@ -20,7 +19,6 @@ namespace View_by_Distance.Tests;
|
|||||||
public class UnitTestResize
|
public class UnitTestResize
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly ILogger _Logger;
|
|
||||||
private readonly AppSettings _AppSettings;
|
private readonly AppSettings _AppSettings;
|
||||||
private readonly string _WorkingDirectory;
|
private readonly string _WorkingDirectory;
|
||||||
private readonly IsEnvironment _IsEnvironment;
|
private readonly IsEnvironment _IsEnvironment;
|
||||||
@ -30,13 +28,11 @@ public class UnitTestResize
|
|||||||
|
|
||||||
public UnitTestResize()
|
public UnitTestResize()
|
||||||
{
|
{
|
||||||
ILogger logger;
|
|
||||||
AppSettings appSettings;
|
AppSettings appSettings;
|
||||||
string workingDirectory;
|
string workingDirectory;
|
||||||
IsEnvironment isEnvironment;
|
IsEnvironment isEnvironment;
|
||||||
Models.Configuration configuration;
|
Models.Configuration configuration;
|
||||||
IConfigurationRoot configurationRoot;
|
IConfigurationRoot configurationRoot;
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Property.Models.Configuration propertyConfiguration;
|
Property.Models.Configuration propertyConfiguration;
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
@ -50,14 +46,9 @@ public class UnitTestResize
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
logger = Log.ForContext<UnitTestResize>();
|
|
||||||
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
Property.Models.Configuration.Verify(propertyConfiguration, requireExist: false);
|
Property.Models.Configuration.Verify(propertyConfiguration, requireExist: false);
|
||||||
logger.Information("Complete");
|
|
||||||
_Logger = logger;
|
|
||||||
_AppSettings = appSettings;
|
_AppSettings = appSettings;
|
||||||
_Configuration = configuration;
|
_Configuration = configuration;
|
||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
@ -76,7 +67,6 @@ public class UnitTestResize
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestMethodNull()
|
public void TestMethodNull()
|
||||||
{
|
{
|
||||||
Assert.IsFalse(_Logger is null);
|
|
||||||
Assert.IsFalse(_AppSettings is null);
|
Assert.IsFalse(_AppSettings is null);
|
||||||
Assert.IsFalse(_Configuration is null);
|
Assert.IsFalse(_Configuration is null);
|
||||||
Assert.IsFalse(_IsEnvironment is null);
|
Assert.IsFalse(_IsEnvironment is null);
|
||||||
@ -154,7 +144,6 @@ public class UnitTestResize
|
|||||||
(string cResultsFullGroupDirectory, _, _) = GetResultsFullGroupDirectories(outputResolution);
|
(string cResultsFullGroupDirectory, _, _) = GetResultsFullGroupDirectories(outputResolution);
|
||||||
(string aResultsFullGroupDirectory, string bResultsFullGroupDirectory) = GetResultsFullGroupDirectories();
|
(string aResultsFullGroupDirectory, string bResultsFullGroupDirectory) = GetResultsFullGroupDirectories();
|
||||||
Shared.Models.Methods.IBlurHasher blurHasher = new BlurHash.Models.C2_BlurHasher(_PropertyConfiguration);
|
Shared.Models.Methods.IBlurHasher blurHasher = new BlurHash.Models.C2_BlurHasher(_PropertyConfiguration);
|
||||||
_Logger.Information(_Configuration.ModelDirectory);
|
|
||||||
A_Property propertyLogic = GetPropertyLogic(reverse, aResultsFullGroupDirectory);
|
A_Property propertyLogic = GetPropertyLogic(reverse, aResultsFullGroupDirectory);
|
||||||
string aPropertySingletonDirectory = Path.Combine(aResultsFullGroupDirectory, "{}");
|
string aPropertySingletonDirectory = Path.Combine(aResultsFullGroupDirectory, "{}");
|
||||||
if (!Directory.Exists(aPropertySingletonDirectory))
|
if (!Directory.Exists(aPropertySingletonDirectory))
|
||||||
|
@ -34,10 +34,6 @@
|
|||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
||||||
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
|
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
|
||||||
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
|
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
|
||||||
<PackageReference Include="Serilog.Settings.Configuration" Version="7.0.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\BlurHash\BlurHash.csproj" />
|
<ProjectReference Include="..\BlurHash\BlurHash.csproj" />
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using Phares.Shared;
|
using Phares.Shared;
|
||||||
using Serilog;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||||
@ -13,7 +12,6 @@ namespace View_by_Distance.Tests;
|
|||||||
public class UnitTestExample
|
public class UnitTestExample
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly ILogger _Logger;
|
|
||||||
private readonly AppSettings _AppSettings;
|
private readonly AppSettings _AppSettings;
|
||||||
private readonly string _WorkingDirectory;
|
private readonly string _WorkingDirectory;
|
||||||
private readonly Configuration _Configuration;
|
private readonly Configuration _Configuration;
|
||||||
@ -23,13 +21,11 @@ public class UnitTestExample
|
|||||||
|
|
||||||
public UnitTestExample()
|
public UnitTestExample()
|
||||||
{
|
{
|
||||||
ILogger logger;
|
|
||||||
AppSettings appSettings;
|
AppSettings appSettings;
|
||||||
string workingDirectory;
|
string workingDirectory;
|
||||||
Configuration configuration;
|
Configuration configuration;
|
||||||
IsEnvironment isEnvironment;
|
IsEnvironment isEnvironment;
|
||||||
IConfigurationRoot configurationRoot;
|
IConfigurationRoot configurationRoot;
|
||||||
LoggerConfiguration loggerConfiguration = new();
|
|
||||||
Property.Models.Configuration propertyConfiguration;
|
Property.Models.Configuration propertyConfiguration;
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
|
||||||
@ -43,13 +39,8 @@ public class UnitTestExample
|
|||||||
throw new Exception("Working directory name must have a value!");
|
throw new Exception("Working directory name must have a value!");
|
||||||
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
|
||||||
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
|
||||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
|
||||||
Log.Logger = loggerConfiguration.CreateLogger();
|
|
||||||
logger = Log.ForContext<UnitTestExample>();
|
|
||||||
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||||
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||||
logger.Information("Complete");
|
|
||||||
_Logger = logger;
|
|
||||||
_AppSettings = appSettings;
|
_AppSettings = appSettings;
|
||||||
_Configuration = configuration;
|
_Configuration = configuration;
|
||||||
_IsEnvironment = isEnvironment;
|
_IsEnvironment = isEnvironment;
|
||||||
@ -61,7 +52,6 @@ public class UnitTestExample
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void TestMethodNull()
|
public void TestMethodNull()
|
||||||
{
|
{
|
||||||
Assert.IsFalse(_Logger is null);
|
|
||||||
Assert.IsFalse(_AppSettings is null);
|
Assert.IsFalse(_AppSettings is null);
|
||||||
Assert.IsFalse(_Configuration is null);
|
Assert.IsFalse(_Configuration is null);
|
||||||
Assert.IsFalse(_IsEnvironment is null);
|
Assert.IsFalse(_IsEnvironment is null);
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user