From 4c90086ae1afe7483751c4b2f3fe614022634cfa Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Tue, 25 Jan 2022 22:57:22 +0200 Subject: [PATCH] Reformat project structure --- ConsoleInterface/Program.cs | 10 ++++++---- ImageCore.Tests/ImageCore.Tests.csproj | 1 + ImageCore.Tests/TestCompressor.cs | 2 +- ...PathFormatter.cs => TestKeepFilenameFormatter.cs} | 5 +++-- ImageCore.Tests/TestLocalSystemFilesRetriever.cs | 1 + ImageCore/{ => Compressor}/ICompressor.cs | 2 +- ImageCore/{ => Compressor}/LosslessCompressor.cs | 2 +- ImageCore/{ => Compressor}/NullCompressor.cs | 2 +- ImageCore/{ => Files}/IFilesRetriever.cs | 2 +- ImageCore/{ => Files}/LocalSystemFilesRetriever.cs | 2 +- .../IFileOutputFormatter.cs} | 4 ++-- .../KeepFilenameFormatter.cs} | 12 ++++++------ .../ExifMetadataRemoverAndCompressor.cs} | 9 +++++---- ImageCore/{ => Remover}/IMetadataRemover.cs | 2 +- ImageCore/TaskExecutor.cs | 8 +++++--- ImageCore/TaskExecutorOptions.cs | 11 ++++++----- 16 files changed, 42 insertions(+), 33 deletions(-) rename ImageCore.Tests/{TestOriginalFilenameFileOutputPathFormatter.cs => TestKeepFilenameFormatter.cs} (78%) rename ImageCore/{ => Compressor}/ICompressor.cs (92%) rename ImageCore/{ => Compressor}/LosslessCompressor.cs (96%) rename ImageCore/{ => Compressor}/NullCompressor.cs (92%) rename ImageCore/{ => Files}/IFilesRetriever.cs (95%) rename ImageCore/{ => Files}/LocalSystemFilesRetriever.cs (98%) rename ImageCore/{IFileOutputPathFormatter.cs => Output/IFileOutputFormatter.cs} (87%) rename ImageCore/{OriginalFilenameFileOutputPathFormatter.cs => Output/KeepFilenameFormatter.cs} (76%) rename ImageCore/{MetadataRemover.cs => Remover/ExifMetadataRemoverAndCompressor.cs} (80%) rename ImageCore/{ => Remover}/IMetadataRemover.cs (93%) diff --git a/ConsoleInterface/Program.cs b/ConsoleInterface/Program.cs index c8aa8d4..bb72c00 100644 --- a/ConsoleInterface/Program.cs +++ b/ConsoleInterface/Program.cs @@ -1,6 +1,8 @@ using System.IO; using CommandLine; using Image; +using Image.Files; +using Image.Output; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -31,15 +33,15 @@ namespace ConsoleInterface var loggerFactory = LoggerFactory.Create(b => b.AddConsole()); TaskExecutor.Logger = loggerFactory.CreateLogger(nameof(TaskExecutor)); LocalSystemFilesRetriever.Logger = loggerFactory.CreateLogger(nameof(LocalSystemFilesRetriever)); - OriginalFilenameFileOutputPathFormatter.Logger = - loggerFactory.CreateLogger(nameof(OriginalFilenameFileOutputPathFormatter)); + KeepFilenameFormatter.Logger = + loggerFactory.CreateLogger(nameof(KeepFilenameFormatter)); CreateDestinationDirectory(options.DestinationDirectory); - var outputFormatter = OriginalFilenameFileOutputPathFormatter.Create(options.DestinationDirectory); + var outputFormatter = KeepFilenameFormatter.Create(options.DestinationDirectory); var executor = TaskExecutor.Create(new TaskExecutorOptions { EnableCompression = options.CompressFiles is true, - FileOutputPathFormatter = outputFormatter + FileOutputFormatter = outputFormatter }); var filesRetriever = LocalSystemFilesRetriever.Create(); diff --git a/ImageCore.Tests/ImageCore.Tests.csproj b/ImageCore.Tests/ImageCore.Tests.csproj index 586e233..5481d75 100644 --- a/ImageCore.Tests/ImageCore.Tests.csproj +++ b/ImageCore.Tests/ImageCore.Tests.csproj @@ -8,6 +8,7 @@ + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/ImageCore.Tests/TestCompressor.cs b/ImageCore.Tests/TestCompressor.cs index c9beda7..11dcba1 100644 --- a/ImageCore.Tests/TestCompressor.cs +++ b/ImageCore.Tests/TestCompressor.cs @@ -1,7 +1,7 @@ using System; using System.IO; -using System.Security.Cryptography; using Image; +using Image.Compressor; using Xunit; namespace ImageCore.Tests diff --git a/ImageCore.Tests/TestOriginalFilenameFileOutputPathFormatter.cs b/ImageCore.Tests/TestKeepFilenameFormatter.cs similarity index 78% rename from ImageCore.Tests/TestOriginalFilenameFileOutputPathFormatter.cs rename to ImageCore.Tests/TestKeepFilenameFormatter.cs index 8fa5e7b..a109882 100644 --- a/ImageCore.Tests/TestOriginalFilenameFileOutputPathFormatter.cs +++ b/ImageCore.Tests/TestKeepFilenameFormatter.cs @@ -1,5 +1,6 @@ using System; using Image; +using Image.Output; using Xunit; namespace ImageCore.Tests @@ -14,14 +15,14 @@ namespace ImageCore.Tests [InlineData("dir", "asd", @"dir\asd.jpg")] public void TestGetOutputPath(string directory, string file, string expectedPath) { - var outputPathFormatter = OriginalFilenameFileOutputPathFormatter.Create(directory); + var outputPathFormatter = KeepFilenameFormatter.Create(directory); Assert.Equal(expectedPath, outputPathFormatter.GetOutputPath(file)); } [Fact] public void TestGetOutputPathNull() { - var outputPathFormatter = OriginalFilenameFileOutputPathFormatter.Create("directory"); + var outputPathFormatter = KeepFilenameFormatter.Create("directory"); Assert.Throws(() => outputPathFormatter.GetOutputPath("")); } } diff --git a/ImageCore.Tests/TestLocalSystemFilesRetriever.cs b/ImageCore.Tests/TestLocalSystemFilesRetriever.cs index bff9758..a181c40 100644 --- a/ImageCore.Tests/TestLocalSystemFilesRetriever.cs +++ b/ImageCore.Tests/TestLocalSystemFilesRetriever.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using Image; +using Image.Files; using Xunit; namespace ImageCore.Tests diff --git a/ImageCore/ICompressor.cs b/ImageCore/Compressor/ICompressor.cs similarity index 92% rename from ImageCore/ICompressor.cs rename to ImageCore/Compressor/ICompressor.cs index 8750779..a729151 100644 --- a/ImageCore/ICompressor.cs +++ b/ImageCore/Compressor/ICompressor.cs @@ -1,4 +1,4 @@ -namespace Image +namespace Image.Compressor { /// /// ICompressor is an interface for implementing image compressors. diff --git a/ImageCore/LosslessCompressor.cs b/ImageCore/Compressor/LosslessCompressor.cs similarity index 96% rename from ImageCore/LosslessCompressor.cs rename to ImageCore/Compressor/LosslessCompressor.cs index 11e26af..c1d9c6e 100644 --- a/ImageCore/LosslessCompressor.cs +++ b/ImageCore/Compressor/LosslessCompressor.cs @@ -1,6 +1,6 @@ using ImageMagick; -namespace Image +namespace Image.Compressor { /// /// LosslessCompressor compresses an image using lossless compression provided by ImageMagick. diff --git a/ImageCore/NullCompressor.cs b/ImageCore/Compressor/NullCompressor.cs similarity index 92% rename from ImageCore/NullCompressor.cs rename to ImageCore/Compressor/NullCompressor.cs index 2db8169..b3f52ba 100644 --- a/ImageCore/NullCompressor.cs +++ b/ImageCore/Compressor/NullCompressor.cs @@ -1,4 +1,4 @@ -namespace Image +namespace Image.Compressor { /// /// Does nothing. Using this Compressor will have no effect. diff --git a/ImageCore/IFilesRetriever.cs b/ImageCore/Files/IFilesRetriever.cs similarity index 95% rename from ImageCore/IFilesRetriever.cs rename to ImageCore/Files/IFilesRetriever.cs index d04a732..7f89e0d 100644 --- a/ImageCore/IFilesRetriever.cs +++ b/ImageCore/Files/IFilesRetriever.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; -namespace Image +namespace Image.Files { /// /// An to interface enabling implementation of filename retrievers. diff --git a/ImageCore/LocalSystemFilesRetriever.cs b/ImageCore/Files/LocalSystemFilesRetriever.cs similarity index 98% rename from ImageCore/LocalSystemFilesRetriever.cs rename to ImageCore/Files/LocalSystemFilesRetriever.cs index 55d47ac..07fa5f4 100644 --- a/ImageCore/LocalSystemFilesRetriever.cs +++ b/ImageCore/Files/LocalSystemFilesRetriever.cs @@ -3,7 +3,7 @@ using System.IO; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -namespace Image +namespace Image.Files { /// /// LocalSystemFilesRetriever reads files from the provided directory on the local system. diff --git a/ImageCore/IFileOutputPathFormatter.cs b/ImageCore/Output/IFileOutputFormatter.cs similarity index 87% rename from ImageCore/IFileOutputPathFormatter.cs rename to ImageCore/Output/IFileOutputFormatter.cs index 8c1eae7..353ce86 100644 --- a/ImageCore/IFileOutputPathFormatter.cs +++ b/ImageCore/Output/IFileOutputFormatter.cs @@ -1,9 +1,9 @@ -namespace Image +namespace Image.Output { /// /// IOutputFormatter is an interface for generating the output path and destination file name. /// - public interface IFileOutputPathFormatter + public interface IFileOutputFormatter { /// /// Generates an absolute output path given the initial absolute file path. diff --git a/ImageCore/OriginalFilenameFileOutputPathFormatter.cs b/ImageCore/Output/KeepFilenameFormatter.cs similarity index 76% rename from ImageCore/OriginalFilenameFileOutputPathFormatter.cs rename to ImageCore/Output/KeepFilenameFormatter.cs index b3a060e..2c603aa 100644 --- a/ImageCore/OriginalFilenameFileOutputPathFormatter.cs +++ b/ImageCore/Output/KeepFilenameFormatter.cs @@ -3,13 +3,13 @@ using GuardNet; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; -namespace Image +namespace Image.Output { /// - /// OriginalFilenameFileOutputPathFormatter keeps the original file name of the image when formatting the new output + /// KeepFilenameFormatter keeps the original file name of the image when formatting the new output /// path. /// - public class OriginalFilenameFileOutputPathFormatter : IFileOutputPathFormatter + public class KeepFilenameFormatter : IFileOutputFormatter { public static ILogger Logger = NullLogger.Instance; private readonly string _outputDirectory; @@ -18,7 +18,7 @@ namespace Image /// Creates an instance of OriginalFilenameFileOutputPathFormatter. /// /// The output directory. - public OriginalFilenameFileOutputPathFormatter(string outputDirectory) + public KeepFilenameFormatter(string outputDirectory) { if (outputDirectory.Equals("")) { @@ -44,9 +44,9 @@ namespace Image /// Creates an instance of OriginalFilenameFileOutputPathFormatter. /// /// The output directory. - public static OriginalFilenameFileOutputPathFormatter Create(string outputDirectory) + public static KeepFilenameFormatter Create(string outputDirectory) { - return new OriginalFilenameFileOutputPathFormatter(outputDirectory); + return new KeepFilenameFormatter(outputDirectory); } } } \ No newline at end of file diff --git a/ImageCore/MetadataRemover.cs b/ImageCore/Remover/ExifMetadataRemoverAndCompressor.cs similarity index 80% rename from ImageCore/MetadataRemover.cs rename to ImageCore/Remover/ExifMetadataRemoverAndCompressor.cs index 0f1716f..2b5a1c9 100644 --- a/ImageCore/MetadataRemover.cs +++ b/ImageCore/Remover/ExifMetadataRemoverAndCompressor.cs @@ -1,11 +1,12 @@ -using ImageMagick; +using Image.Compressor; +using ImageMagick; -namespace Image +namespace Image.Remover { /// /// MetadataRemover removes metadata from an image. The exif profile. /// - public class MetadataRemover : IMetadataRemover + public class ExifMetadataRemoverAndCompressor : IMetadataRemover { private readonly ICompressor _compressor; private readonly IMagickImage _magickImage; @@ -15,7 +16,7 @@ namespace Image /// /// MagicImage instance. /// Compressor instance. - public MetadataRemover(IMagickImage magickImage, ICompressor compressor) + public ExifMetadataRemoverAndCompressor(IMagickImage magickImage, ICompressor compressor) { _magickImage = magickImage; _compressor = compressor; diff --git a/ImageCore/IMetadataRemover.cs b/ImageCore/Remover/IMetadataRemover.cs similarity index 93% rename from ImageCore/IMetadataRemover.cs rename to ImageCore/Remover/IMetadataRemover.cs index 8d3fa27..4121692 100644 --- a/ImageCore/IMetadataRemover.cs +++ b/ImageCore/Remover/IMetadataRemover.cs @@ -1,4 +1,4 @@ -namespace Image +namespace Image.Remover { /// /// Interface for implementing metadata removers. diff --git a/ImageCore/TaskExecutor.cs b/ImageCore/TaskExecutor.cs index e64e521..8d0fe7b 100644 --- a/ImageCore/TaskExecutor.cs +++ b/ImageCore/TaskExecutor.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Image.Compressor; +using Image.Remover; using ImageMagick; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; @@ -50,8 +52,8 @@ namespace Image if (_options.EnableCompression) compressor = LosslessCompressor.Instance; Logger.LogDebug( - $"Cleaning {fileName}, compression {_options.EnableCompression}, outputFormatter {nameof(_options.FileOutputPathFormatter)}."); - IMetadataRemover metadataRemover = new MetadataRemover(imageMagick, compressor); + $"Cleaning {fileName}, compression {_options.EnableCompression}, outputFormatter {nameof(_options.FileOutputFormatter)}."); + IMetadataRemover metadataRemover = new ExifMetadataRemoverAndCompressor(imageMagick, compressor); metadataRemover.CleanImage(newFilename); return true; } @@ -80,7 +82,7 @@ namespace Image foreach (var fileName in filenamesArray) { var task = new Task(() => - CleanImage(fileName, _options.FileOutputPathFormatter.GetOutputPath(fileName))); + CleanImage(fileName, _options.FileOutputFormatter.GetOutputPath(fileName))); tasks.Add(task); task.Start(); } diff --git a/ImageCore/TaskExecutorOptions.cs b/ImageCore/TaskExecutorOptions.cs index 5c514f5..70f8c96 100644 --- a/ImageCore/TaskExecutorOptions.cs +++ b/ImageCore/TaskExecutorOptions.cs @@ -1,4 +1,5 @@ using System; +using Image.Output; namespace Image { @@ -7,16 +8,16 @@ namespace Image /// public class TaskExecutorOptions { - private IFileOutputPathFormatter _fileOutputPathFormatter; + private IFileOutputFormatter _fileOutputFormatter; /// /// The file output path formatter. It cannot be null. - /// A implementation of . + /// A implementation of . /// - public IFileOutputPathFormatter FileOutputPathFormatter + public IFileOutputFormatter FileOutputFormatter { - get => _fileOutputPathFormatter; - set => _fileOutputPathFormatter = value ?? throw new ArgumentException("Output formatter cannot be null!"); + get => _fileOutputFormatter; + set => _fileOutputFormatter = value ?? throw new ArgumentException("Output formatter cannot be null!"); } ///