Move create Directory from OriginalFilenameFileOutputPathFormatter to Program

This commit is contained in:
Denis-Cosmin Nutiu 2022-01-25 22:27:39 +02:00
parent c6f1ec0a37
commit f6de032d84
2 changed files with 17 additions and 7 deletions

View file

@ -1,6 +1,8 @@
using CommandLine; using System.IO;
using CommandLine;
using Image; using Image;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable ClassNeverInstantiated.Global // ReSharper disable ClassNeverInstantiated.Global
@ -10,6 +12,8 @@ namespace ConsoleInterface
{ {
internal static class Program internal static class Program
{ {
private static readonly ILogger Logger = NullLogger.Instance;
/// <summary> /// <summary>
/// The console interface for the project and the main entrypoint. /// The console interface for the project and the main entrypoint.
/// </summary> /// </summary>
@ -30,6 +34,7 @@ namespace ConsoleInterface
OriginalFilenameFileOutputPathFormatter.Logger = OriginalFilenameFileOutputPathFormatter.Logger =
loggerFactory.CreateLogger(nameof(OriginalFilenameFileOutputPathFormatter)); loggerFactory.CreateLogger(nameof(OriginalFilenameFileOutputPathFormatter));
CreateDestinationDirectory(options.DestinationDirectory);
var outputFormatter = OriginalFilenameFileOutputPathFormatter.Create(options.DestinationDirectory); var outputFormatter = OriginalFilenameFileOutputPathFormatter.Create(options.DestinationDirectory);
var executor = TaskExecutor.Create(new TaskExecutorOptions var executor = TaskExecutor.Create(new TaskExecutorOptions
{ {
@ -42,6 +47,17 @@ namespace ConsoleInterface
executor.ParallelCleanImages(filesRetriever.GetFilenamesFromPath(options.SourceDirectory)); 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> /// <summary>
/// Options is a class defining command line options supported by this program. /// Options is a class defining command line options supported by this program.
/// </summary> /// </summary>

View file

@ -19,12 +19,6 @@ namespace Image
/// <param name="outputDirectory">The output directory.</param> /// <param name="outputDirectory">The output directory.</param>
public OriginalFilenameFileOutputPathFormatter(string outputDirectory) public OriginalFilenameFileOutputPathFormatter(string outputDirectory)
{ {
if (!Directory.Exists(outputDirectory))
{
Logger.LogWarning("Output directory does not exists. Creating.");
Directory.CreateDirectory(outputDirectory);
}
_outputDirectory = outputDirectory; _outputDirectory = outputDirectory;
} }