Move create Directory from OriginalFilenameFileOutputPathFormatter to Program
This commit is contained in:
parent
c6f1ec0a37
commit
f6de032d84
2 changed files with 17 additions and 7 deletions
|
@ -1,6 +1,8 @@
|
|||
using CommandLine;
|
||||
using System.IO;
|
||||
using CommandLine;
|
||||
using Image;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
// ReSharper disable ClassNeverInstantiated.Global
|
||||
|
@ -10,6 +12,8 @@ namespace ConsoleInterface
|
|||
{
|
||||
internal static class Program
|
||||
{
|
||||
private static readonly ILogger Logger = NullLogger.Instance;
|
||||
|
||||
/// <summary>
|
||||
/// The console interface for the project and the main entrypoint.
|
||||
/// </summary>
|
||||
|
@ -30,6 +34,7 @@ namespace ConsoleInterface
|
|||
OriginalFilenameFileOutputPathFormatter.Logger =
|
||||
loggerFactory.CreateLogger(nameof(OriginalFilenameFileOutputPathFormatter));
|
||||
|
||||
CreateDestinationDirectory(options.DestinationDirectory);
|
||||
var outputFormatter = OriginalFilenameFileOutputPathFormatter.Create(options.DestinationDirectory);
|
||||
var executor = TaskExecutor.Create(new TaskExecutorOptions
|
||||
{
|
||||
|
@ -42,6 +47,17 @@ namespace ConsoleInterface
|
|||
executor.ParallelCleanImages(filesRetriever.GetFilenamesFromPath(options.SourceDirectory));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the directory if it doesn't exist.
|
||||
/// </summary>
|
||||
/// <param name="destinationDirectory">The destination directory.</param>
|
||||
private static void CreateDestinationDirectory(string destinationDirectory)
|
||||
{
|
||||
if (Directory.Exists(destinationDirectory)) return;
|
||||
Logger.LogWarning("Output directory does not exist. Creating.");
|
||||
Directory.CreateDirectory(destinationDirectory);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Options is a class defining command line options supported by this program.
|
||||
/// </summary>
|
||||
|
|
|
@ -19,12 +19,6 @@ namespace Image
|
|||
/// <param name="outputDirectory">The output directory.</param>
|
||||
public OriginalFilenameFileOutputPathFormatter(string outputDirectory)
|
||||
{
|
||||
if (!Directory.Exists(outputDirectory))
|
||||
{
|
||||
Logger.LogWarning("Output directory does not exists. Creating.");
|
||||
Directory.CreateDirectory(outputDirectory);
|
||||
}
|
||||
|
||||
_outputDirectory = outputDirectory;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue