Serilog
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Phares.Shared;
|
||||
using Serilog;
|
||||
using ShellProgressBar;
|
||||
using View_by_Distance.Copy.Distinct.Models;
|
||||
using View_by_Distance.Shared.Models;
|
||||
@ -19,7 +19,7 @@ public class CopyDistinct
|
||||
private readonly IReadOnlyDictionary<string, string[]> _FileGroups;
|
||||
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)
|
||||
{ }
|
||||
@ -29,15 +29,14 @@ public class CopyDistinct
|
||||
_IsEnvironment = isEnvironment;
|
||||
_WorkingDirectory = workingDirectory;
|
||||
_ConfigurationRoot = configurationRoot;
|
||||
ILogger? log = Log.ForContext<CopyDistinct>();
|
||||
Property.Models.Configuration propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||
Configuration configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||
_PropertyConfiguration = propertyConfiguration;
|
||||
_Configuration = configuration;
|
||||
log.Information(propertyConfiguration.RootDirectory);
|
||||
logger?.LogInformation(propertyConfiguration.RootDirectory);
|
||||
(bool move, List<string[]> filesCollection, bool anyLenFiles, bool moveBack) = Verify();
|
||||
_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())
|
||||
File.WriteAllLines($"D:/Tmp/Phares/{DateTime.Now.Ticks}.tsv", lines);
|
||||
_ = Shared.Models.Stateless.Methods.IPath.DeleteEmptyDirectories(propertyConfiguration.RootDirectory);
|
||||
@ -154,7 +153,7 @@ public class CopyDistinct
|
||||
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();
|
||||
ProgressBar progressBar;
|
||||
@ -184,30 +183,30 @@ public class CopyDistinct
|
||||
_ = Directory.CreateDirectory(distinctDirectory);
|
||||
}
|
||||
if (move)
|
||||
log.Information($"Ready to Move {toDoCollection.Count} file(s)?");
|
||||
logger?.LogInformation($"Ready to Move {toDoCollection.Count} file(s)?");
|
||||
else if (!moveBack)
|
||||
log.Information($"Ready to Copy {toDoCollection.Count} file(s)?");
|
||||
logger?.LogInformation($"Ready to Copy {toDoCollection.Count} file(s)?");
|
||||
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++)
|
||||
{
|
||||
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)
|
||||
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
|
||||
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;
|
||||
if (consoleKey is ConsoleKey.Y or ConsoleKey.N)
|
||||
break;
|
||||
}
|
||||
log.Information(". . .");
|
||||
logger?.LogInformation(". . .");
|
||||
if (consoleKey is null || consoleKey.Value != ConsoleKey.Y)
|
||||
{
|
||||
if (move || moveBack)
|
||||
log.Information("Nothing moved!");
|
||||
logger?.LogInformation("Nothing moved!");
|
||||
else
|
||||
log.Information("Nothing copied!");
|
||||
logger?.LogInformation("Nothing copied!");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -215,9 +214,9 @@ public class CopyDistinct
|
||||
results.AddRange(Shared.Models.Stateless.Methods.IDirectory.CopyOrMove(toDoCollection, move, moveBack, () => progressBar.Tick()));
|
||||
progressBar.Dispose();
|
||||
if (move || moveBack)
|
||||
log.Information("Done moving");
|
||||
logger?.LogInformation("Done moving");
|
||||
else
|
||||
log.Information("Done copying");
|
||||
logger?.LogInformation("Done copying");
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
Reference in New Issue
Block a user