From 856fc636277cc790c8990cc02f2bfb86f10d1a86 Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Sat, 12 Feb 2022 22:12:57 +0200 Subject: [PATCH] Refactor project structure. --- ImageCore.Tests/TestKeepFilenameFormatter.cs | 6 +++--- ...temFilesRetriever.cs => TestLocalFileBrowser.cs} | 8 ++++---- ImageCore.Tests/TestMetadataRemover.cs | 2 +- ...AndCompressor.cs => ExifRemoverAndCompressor.cs} | 8 ++++---- .../Files/{IFilesBrowser.cs => IFileBrowser.cs} | 4 ++-- .../{IFileOutputFormatter.cs => IOutputSink.cs} | 4 ++-- ...ocalSystemFileBrowser.cs => LocalFileBrowser.cs} | 10 +++++----- ...KeepFilenameFormatter.cs => SimpleOutputSink.cs} | 13 +++++++------ ImageCore/Tasks/TaskExecutor.cs | 6 +++--- ImageCore/Tasks/TaskExecutorOptions.cs | 10 +++++----- 10 files changed, 36 insertions(+), 35 deletions(-) rename ImageCore.Tests/{TestLocalSystemFilesRetriever.cs => TestLocalFileBrowser.cs} (83%) rename ImageCore/Core/{ExifMetadataRemoverAndCompressor.cs => ExifRemoverAndCompressor.cs} (74%) rename ImageCore/Files/{IFilesBrowser.cs => IFileBrowser.cs} (78%) rename ImageCore/Files/{IFileOutputFormatter.cs => IOutputSink.cs} (73%) rename ImageCore/Files/{LocalSystemFileBrowser.cs => LocalFileBrowser.cs} (73%) rename ImageCore/Files/{KeepFilenameFormatter.cs => SimpleOutputSink.cs} (76%) diff --git a/ImageCore.Tests/TestKeepFilenameFormatter.cs b/ImageCore.Tests/TestKeepFilenameFormatter.cs index 8ca40e2..c85cfd0 100644 --- a/ImageCore.Tests/TestKeepFilenameFormatter.cs +++ b/ImageCore.Tests/TestKeepFilenameFormatter.cs @@ -4,7 +4,7 @@ using Xunit; namespace ImageCore.Tests { - public class TestOriginalFilenameFileOutputPathFormatter + public class TestSimpleOutputSink { [Theory] @@ -14,14 +14,14 @@ namespace ImageCore.Tests [InlineData("dir", "asd", @"dir\asd.jpg")] public void TestGetOutputPath(string directory, string file, string expectedPath) { - var outputPathFormatter = KeepFilenameFormatter.Create(directory); + var outputPathFormatter = SimpleOutputSink.Create(directory); Assert.Equal(expectedPath, outputPathFormatter.GetOutputPath(file)); } [Fact] public void TestGetOutputPathNull() { - var outputPathFormatter = KeepFilenameFormatter.Create("directory"); + var outputPathFormatter = SimpleOutputSink.Create("directory"); Assert.Throws(() => outputPathFormatter.GetOutputPath("")); } } diff --git a/ImageCore.Tests/TestLocalSystemFilesRetriever.cs b/ImageCore.Tests/TestLocalFileBrowser.cs similarity index 83% rename from ImageCore.Tests/TestLocalSystemFilesRetriever.cs rename to ImageCore.Tests/TestLocalFileBrowser.cs index 1115342..f515bf4 100644 --- a/ImageCore.Tests/TestLocalSystemFilesRetriever.cs +++ b/ImageCore.Tests/TestLocalFileBrowser.cs @@ -7,11 +7,11 @@ using Xunit; namespace ImageCore.Tests { - public class TestLocalSystemFilesRetriever + public class TestLocalFileBrowser { private readonly string _testsProjectDirectory; - public TestLocalSystemFilesRetriever() + public TestLocalFileBrowser() { _testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS"); } @@ -19,14 +19,14 @@ namespace ImageCore.Tests [Fact] public void TestGetFilenamesFromPath_DirectoryNotFound() { - var filesRetriever = LocalSystemFilesRetriever.Create(); + var filesRetriever = LocalFileBrowser.Create(); Assert.Throws(() => filesRetriever.GetFilenamesFromPath("a")); } [Fact] public void TestGetFilenamesFromPath() { - var filesRetriever = LocalSystemFilesRetriever.Create(); + var filesRetriever = LocalFileBrowser.Create(); var filePaths = filesRetriever.GetFilenamesFromPath(Path.Join(_testsProjectDirectory, "test_pictures")); Assert.NotNull(filePaths); var filePathsList = filePaths.ToList(); diff --git a/ImageCore.Tests/TestMetadataRemover.cs b/ImageCore.Tests/TestMetadataRemover.cs index b36ae6a..6b15c6b 100644 --- a/ImageCore.Tests/TestMetadataRemover.cs +++ b/ImageCore.Tests/TestMetadataRemover.cs @@ -13,7 +13,7 @@ namespace ImageCore.Tests // Setup var magicImageMock = new Mock(); var compressorMock = new Mock(); - var metadataRemover = new ExifMetadataRemoverAndCompressor(magicImageMock.Object, compressorMock.Object); + var metadataRemover = new ExifRemoverAndCompressor(magicImageMock.Object, compressorMock.Object); // Test metadataRemover.CleanImage("path"); diff --git a/ImageCore/Core/ExifMetadataRemoverAndCompressor.cs b/ImageCore/Core/ExifRemoverAndCompressor.cs similarity index 74% rename from ImageCore/Core/ExifMetadataRemoverAndCompressor.cs rename to ImageCore/Core/ExifRemoverAndCompressor.cs index adf15dd..c22a6d2 100644 --- a/ImageCore/Core/ExifMetadataRemoverAndCompressor.cs +++ b/ImageCore/Core/ExifRemoverAndCompressor.cs @@ -3,19 +3,19 @@ namespace Image.Core { /// - /// MetadataRemover removes metadata from an image. The exif profile. + /// ExifRemoverAndCompressor removes exif metadata from an image. /// - public class ExifMetadataRemoverAndCompressor : IMetadataRemover + public class ExifRemoverAndCompressor : IMetadataRemover { private readonly ICompressor _compressor; private readonly IMagickImage _magickImage; /// - /// Constructs an instance of MetadataRemover. + /// Constructs an instance of ExifRemoverAndCompressor. /// /// MagicImage instance. /// Compressor instance. - public ExifMetadataRemoverAndCompressor(IMagickImage magickImage, ICompressor compressor) + public ExifRemoverAndCompressor(IMagickImage magickImage, ICompressor compressor) { _magickImage = magickImage; _compressor = compressor; diff --git a/ImageCore/Files/IFilesBrowser.cs b/ImageCore/Files/IFileBrowser.cs similarity index 78% rename from ImageCore/Files/IFilesBrowser.cs rename to ImageCore/Files/IFileBrowser.cs index 3dc8357..d1768e6 100644 --- a/ImageCore/Files/IFilesBrowser.cs +++ b/ImageCore/Files/IFileBrowser.cs @@ -3,9 +3,9 @@ namespace Image.Files { /// - /// An to interface enabling implementation of filename retrievers. + /// An to interface enabling implementation of file browsers. /// - public interface IFilesBrowser + public interface IFileBrowser { /// /// Returns all filenames from given path. diff --git a/ImageCore/Files/IFileOutputFormatter.cs b/ImageCore/Files/IOutputSink.cs similarity index 73% rename from ImageCore/Files/IFileOutputFormatter.cs rename to ImageCore/Files/IOutputSink.cs index d912f47..4dcbc3b 100644 --- a/ImageCore/Files/IFileOutputFormatter.cs +++ b/ImageCore/Files/IOutputSink.cs @@ -1,9 +1,9 @@ namespace Image.Files { /// - /// IOutputFormatter is an interface for generating the output path and destination file name. + /// IOutputSink is an interface for generating saving the generated files.. /// - public interface IFileOutputFormatter + public interface IOutputSink { /// /// Generates an absolute output path given the initial absolute file path. diff --git a/ImageCore/Files/LocalSystemFileBrowser.cs b/ImageCore/Files/LocalFileBrowser.cs similarity index 73% rename from ImageCore/Files/LocalSystemFileBrowser.cs rename to ImageCore/Files/LocalFileBrowser.cs index eb49e7d..1a281a9 100644 --- a/ImageCore/Files/LocalSystemFileBrowser.cs +++ b/ImageCore/Files/LocalFileBrowser.cs @@ -6,13 +6,13 @@ using Microsoft.Extensions.Logging.Abstractions; namespace Image.Files { /// - /// LocalSystemFileBrowser reads files from the provided directory on the local system. + /// LocalFileBrowser reads files from the provided directory on the local system. /// - public class LocalSystemFileBrowser : IFilesBrowser + public class LocalFileBrowser : IFileBrowser { public static ILogger Logger = NullLogger.Instance; - private LocalSystemFileBrowser() + private LocalFileBrowser() { } @@ -27,9 +27,9 @@ namespace Image.Files return Directory.GetFiles(directoryPath, "*.*"); } - public static LocalSystemFileBrowser Create() + public static LocalFileBrowser Create() { - return new LocalSystemFileBrowser(); + return new LocalFileBrowser(); } } } \ No newline at end of file diff --git a/ImageCore/Files/KeepFilenameFormatter.cs b/ImageCore/Files/SimpleOutputSink.cs similarity index 76% rename from ImageCore/Files/KeepFilenameFormatter.cs rename to ImageCore/Files/SimpleOutputSink.cs index ff6f36f..3da91e2 100644 --- a/ImageCore/Files/KeepFilenameFormatter.cs +++ b/ImageCore/Files/SimpleOutputSink.cs @@ -6,19 +6,20 @@ using Microsoft.Extensions.Logging.Abstractions; namespace Image.Files { /// - /// KeepFilenameFormatter keeps the original file name of the image when formatting the new output + /// SimpleOutputFormatter keeps the original file name of the image when formatting it. + /// SimpleOutputFormatter also saves all the file names into a new directory. /// path. /// - public class KeepFilenameFormatter : IFileOutputFormatter + public class SimpleOutputSink : IOutputSink { public static ILogger Logger = NullLogger.Instance; private readonly string _outputDirectory; /// - /// Creates an instance of OriginalFilenameFileOutputPathFormatter. + /// Creates an instance of SimpleOutputFormatter. /// /// The output directory. - public KeepFilenameFormatter(string outputDirectory) + public SimpleOutputSink(string outputDirectory) { if (outputDirectory.Equals("")) { @@ -46,9 +47,9 @@ namespace Image.Files /// Creates an instance of OriginalFilenameFileOutputPathFormatter. /// /// The output directory. - public static KeepFilenameFormatter Create(string outputDirectory) + public static SimpleOutputSink Create(string outputDirectory) { - return new KeepFilenameFormatter(outputDirectory); + return new SimpleOutputSink(outputDirectory); } } } \ No newline at end of file diff --git a/ImageCore/Tasks/TaskExecutor.cs b/ImageCore/Tasks/TaskExecutor.cs index 8dbcfb7..c18a95f 100644 --- a/ImageCore/Tasks/TaskExecutor.cs +++ b/ImageCore/Tasks/TaskExecutor.cs @@ -58,8 +58,8 @@ namespace Image.Tasks if (_options.EnableCompression) compressor = LosslessCompressor.Instance; Logger.LogDebug( - $"Cleaning {filePath}, compression {_options.EnableCompression}, outputFormatter {nameof(_options.FileOutputFormatter)}."); - IMetadataRemover metadataRemover = new ExifMetadataRemoverAndCompressor(imageMagick, compressor); + $"Cleaning {filePath}, compression {_options.EnableCompression}, outputFormatter {nameof(_options.OutputSink)}."); + IMetadataRemover metadataRemover = new ExifRemoverAndCompressor(imageMagick, compressor); metadataRemover.CleanImage(newFilePath); return true; } @@ -88,7 +88,7 @@ namespace Image.Tasks foreach (var fileName in filenamesArray) { var task = new Task(() => - CleanImage(fileName, _options.FileOutputFormatter.GetOutputPath(fileName))); + CleanImage(fileName, _options.OutputSink.GetOutputPath(fileName))); tasks.Add(task); task.Start(); } diff --git a/ImageCore/Tasks/TaskExecutorOptions.cs b/ImageCore/Tasks/TaskExecutorOptions.cs index 7f41816..2e1cf2d 100644 --- a/ImageCore/Tasks/TaskExecutorOptions.cs +++ b/ImageCore/Tasks/TaskExecutorOptions.cs @@ -8,16 +8,16 @@ namespace Image.Tasks /// public class TaskExecutorOptions { - private IFileOutputFormatter _fileOutputFormatter; + private IOutputSink _outputSink; /// /// The file output path formatter. It cannot be null. - /// A implementation of . + /// A implementation of . /// - public IFileOutputFormatter FileOutputFormatter + public IOutputSink OutputSink { - get => _fileOutputFormatter; - set => _fileOutputFormatter = value ?? throw new ArgumentException("Output formatter cannot be null!"); + get => _outputSink; + set => _outputSink = value ?? throw new ArgumentException("Output formatter cannot be null!"); } ///