Refactor project structure.
This commit is contained in:
parent
0b3398605d
commit
856fc63627
10 changed files with 36 additions and 35 deletions
|
@ -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<ArgumentException>(() => outputPathFormatter.GetOutputPath(""));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<DirectoryNotFoundException>(() => 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();
|
|
@ -13,7 +13,7 @@ namespace ImageCore.Tests
|
|||
// Setup
|
||||
var magicImageMock = new Mock<IMagickImage>();
|
||||
var compressorMock = new Mock<ICompressor>();
|
||||
var metadataRemover = new ExifMetadataRemoverAndCompressor(magicImageMock.Object, compressorMock.Object);
|
||||
var metadataRemover = new ExifRemoverAndCompressor(magicImageMock.Object, compressorMock.Object);
|
||||
|
||||
// Test
|
||||
metadataRemover.CleanImage("path");
|
||||
|
|
|
@ -3,19 +3,19 @@
|
|||
namespace Image.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// MetadataRemover removes metadata from an image. The exif profile.
|
||||
/// ExifRemoverAndCompressor removes exif metadata from an image.
|
||||
/// </summary>
|
||||
public class ExifMetadataRemoverAndCompressor : IMetadataRemover
|
||||
public class ExifRemoverAndCompressor : IMetadataRemover
|
||||
{
|
||||
private readonly ICompressor _compressor;
|
||||
private readonly IMagickImage _magickImage;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs an instance of MetadataRemover.
|
||||
/// Constructs an instance of ExifRemoverAndCompressor.
|
||||
/// </summary>
|
||||
/// <param name="magickImage">MagicImage instance.</param>
|
||||
/// <param name="compressor">Compressor instance.</param>
|
||||
public ExifMetadataRemoverAndCompressor(IMagickImage magickImage, ICompressor compressor)
|
||||
public ExifRemoverAndCompressor(IMagickImage magickImage, ICompressor compressor)
|
||||
{
|
||||
_magickImage = magickImage;
|
||||
_compressor = compressor;
|
|
@ -3,9 +3,9 @@
|
|||
namespace Image.Files
|
||||
{
|
||||
/// <summary>
|
||||
/// An to interface enabling implementation of filename retrievers.
|
||||
/// An to interface enabling implementation of file browsers.
|
||||
/// </summary>
|
||||
public interface IFilesBrowser
|
||||
public interface IFileBrowser
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns all filenames from given path.
|
|
@ -1,9 +1,9 @@
|
|||
namespace Image.Files
|
||||
{
|
||||
/// <summary>
|
||||
/// IOutputFormatter is an interface for generating the output path and destination file name.
|
||||
/// IOutputSink is an interface for generating saving the generated files..
|
||||
/// </summary>
|
||||
public interface IFileOutputFormatter
|
||||
public interface IOutputSink
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates an absolute output path given the initial absolute file path.
|
|
@ -6,13 +6,13 @@ using Microsoft.Extensions.Logging.Abstractions;
|
|||
namespace Image.Files
|
||||
{
|
||||
/// <summary>
|
||||
/// LocalSystemFileBrowser reads files from the provided directory on the local system.
|
||||
/// LocalFileBrowser reads files from the provided directory on the local system.
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,19 +6,20 @@ using Microsoft.Extensions.Logging.Abstractions;
|
|||
namespace Image.Files
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public class KeepFilenameFormatter : IFileOutputFormatter
|
||||
public class SimpleOutputSink : IOutputSink
|
||||
{
|
||||
public static ILogger Logger = NullLogger.Instance;
|
||||
private readonly string _outputDirectory;
|
||||
|
||||
/// <summary>
|
||||
/// Creates an instance of OriginalFilenameFileOutputPathFormatter.
|
||||
/// Creates an instance of SimpleOutputFormatter.
|
||||
/// </summary>
|
||||
/// <param name="outputDirectory">The output directory.</param>
|
||||
public KeepFilenameFormatter(string outputDirectory)
|
||||
public SimpleOutputSink(string outputDirectory)
|
||||
{
|
||||
if (outputDirectory.Equals(""))
|
||||
{
|
||||
|
@ -46,9 +47,9 @@ namespace Image.Files
|
|||
/// Creates an instance of OriginalFilenameFileOutputPathFormatter.
|
||||
/// </summary>
|
||||
/// <param name="outputDirectory">The output directory.</param>
|
||||
public static KeepFilenameFormatter Create(string outputDirectory)
|
||||
public static SimpleOutputSink Create(string outputDirectory)
|
||||
{
|
||||
return new KeepFilenameFormatter(outputDirectory);
|
||||
return new SimpleOutputSink(outputDirectory);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<bool>(() =>
|
||||
CleanImage(fileName, _options.FileOutputFormatter.GetOutputPath(fileName)));
|
||||
CleanImage(fileName, _options.OutputSink.GetOutputPath(fileName)));
|
||||
tasks.Add(task);
|
||||
task.Start();
|
||||
}
|
||||
|
|
|
@ -8,16 +8,16 @@ namespace Image.Tasks
|
|||
/// </summary>
|
||||
public class TaskExecutorOptions
|
||||
{
|
||||
private IFileOutputFormatter _fileOutputFormatter;
|
||||
private IOutputSink _outputSink;
|
||||
|
||||
/// <summary>
|
||||
/// The file output path formatter. It cannot be null.
|
||||
/// A implementation of <see cref="IFileOutputFormatter" />.
|
||||
/// A implementation of <see cref="IOutputSink" />.
|
||||
/// </summary>
|
||||
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!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in a new issue