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
|
namespace ImageCore.Tests
|
||||||
{
|
{
|
||||||
public class TestOriginalFilenameFileOutputPathFormatter
|
public class TestSimpleOutputSink
|
||||||
{
|
{
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
@ -14,14 +14,14 @@ namespace ImageCore.Tests
|
||||||
[InlineData("dir", "asd", @"dir\asd.jpg")]
|
[InlineData("dir", "asd", @"dir\asd.jpg")]
|
||||||
public void TestGetOutputPath(string directory, string file, string expectedPath)
|
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));
|
Assert.Equal(expectedPath, outputPathFormatter.GetOutputPath(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestGetOutputPathNull()
|
public void TestGetOutputPathNull()
|
||||||
{
|
{
|
||||||
var outputPathFormatter = KeepFilenameFormatter.Create("directory");
|
var outputPathFormatter = SimpleOutputSink.Create("directory");
|
||||||
Assert.Throws<ArgumentException>(() => outputPathFormatter.GetOutputPath(""));
|
Assert.Throws<ArgumentException>(() => outputPathFormatter.GetOutputPath(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,11 @@ using Xunit;
|
||||||
|
|
||||||
namespace ImageCore.Tests
|
namespace ImageCore.Tests
|
||||||
{
|
{
|
||||||
public class TestLocalSystemFilesRetriever
|
public class TestLocalFileBrowser
|
||||||
{
|
{
|
||||||
private readonly string _testsProjectDirectory;
|
private readonly string _testsProjectDirectory;
|
||||||
|
|
||||||
public TestLocalSystemFilesRetriever()
|
public TestLocalFileBrowser()
|
||||||
{
|
{
|
||||||
_testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS");
|
_testsProjectDirectory = Environment.GetEnvironmentVariable("IMAGE_CORE_TESTS");
|
||||||
}
|
}
|
||||||
|
@ -19,14 +19,14 @@ namespace ImageCore.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestGetFilenamesFromPath_DirectoryNotFound()
|
public void TestGetFilenamesFromPath_DirectoryNotFound()
|
||||||
{
|
{
|
||||||
var filesRetriever = LocalSystemFilesRetriever.Create();
|
var filesRetriever = LocalFileBrowser.Create();
|
||||||
Assert.Throws<DirectoryNotFoundException>(() => filesRetriever.GetFilenamesFromPath("a"));
|
Assert.Throws<DirectoryNotFoundException>(() => filesRetriever.GetFilenamesFromPath("a"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestGetFilenamesFromPath()
|
public void TestGetFilenamesFromPath()
|
||||||
{
|
{
|
||||||
var filesRetriever = LocalSystemFilesRetriever.Create();
|
var filesRetriever = LocalFileBrowser.Create();
|
||||||
var filePaths = filesRetriever.GetFilenamesFromPath(Path.Join(_testsProjectDirectory, "test_pictures"));
|
var filePaths = filesRetriever.GetFilenamesFromPath(Path.Join(_testsProjectDirectory, "test_pictures"));
|
||||||
Assert.NotNull(filePaths);
|
Assert.NotNull(filePaths);
|
||||||
var filePathsList = filePaths.ToList();
|
var filePathsList = filePaths.ToList();
|
|
@ -13,7 +13,7 @@ namespace ImageCore.Tests
|
||||||
// Setup
|
// Setup
|
||||||
var magicImageMock = new Mock<IMagickImage>();
|
var magicImageMock = new Mock<IMagickImage>();
|
||||||
var compressorMock = new Mock<ICompressor>();
|
var compressorMock = new Mock<ICompressor>();
|
||||||
var metadataRemover = new ExifMetadataRemoverAndCompressor(magicImageMock.Object, compressorMock.Object);
|
var metadataRemover = new ExifRemoverAndCompressor(magicImageMock.Object, compressorMock.Object);
|
||||||
|
|
||||||
// Test
|
// Test
|
||||||
metadataRemover.CleanImage("path");
|
metadataRemover.CleanImage("path");
|
||||||
|
|
|
@ -3,19 +3,19 @@
|
||||||
namespace Image.Core
|
namespace Image.Core
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// MetadataRemover removes metadata from an image. The exif profile.
|
/// ExifRemoverAndCompressor removes exif metadata from an image.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ExifMetadataRemoverAndCompressor : IMetadataRemover
|
public class ExifRemoverAndCompressor : IMetadataRemover
|
||||||
{
|
{
|
||||||
private readonly ICompressor _compressor;
|
private readonly ICompressor _compressor;
|
||||||
private readonly IMagickImage _magickImage;
|
private readonly IMagickImage _magickImage;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs an instance of MetadataRemover.
|
/// Constructs an instance of ExifRemoverAndCompressor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="magickImage">MagicImage instance.</param>
|
/// <param name="magickImage">MagicImage instance.</param>
|
||||||
/// <param name="compressor">Compressor instance.</param>
|
/// <param name="compressor">Compressor instance.</param>
|
||||||
public ExifMetadataRemoverAndCompressor(IMagickImage magickImage, ICompressor compressor)
|
public ExifRemoverAndCompressor(IMagickImage magickImage, ICompressor compressor)
|
||||||
{
|
{
|
||||||
_magickImage = magickImage;
|
_magickImage = magickImage;
|
||||||
_compressor = compressor;
|
_compressor = compressor;
|
|
@ -3,9 +3,9 @@
|
||||||
namespace Image.Files
|
namespace Image.Files
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An to interface enabling implementation of filename retrievers.
|
/// An to interface enabling implementation of file browsers.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IFilesBrowser
|
public interface IFileBrowser
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns all filenames from given path.
|
/// Returns all filenames from given path.
|
|
@ -1,9 +1,9 @@
|
||||||
namespace Image.Files
|
namespace Image.Files
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public interface IFileOutputFormatter
|
public interface IOutputSink
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generates an absolute output path given the initial absolute file path.
|
/// Generates an absolute output path given the initial absolute file path.
|
|
@ -6,13 +6,13 @@ using Microsoft.Extensions.Logging.Abstractions;
|
||||||
namespace Image.Files
|
namespace Image.Files
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LocalSystemFileBrowser reads files from the provided directory on the local system.
|
/// LocalFileBrowser reads files from the provided directory on the local system.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LocalSystemFileBrowser : IFilesBrowser
|
public class LocalFileBrowser : IFileBrowser
|
||||||
{
|
{
|
||||||
public static ILogger Logger = NullLogger.Instance;
|
public static ILogger Logger = NullLogger.Instance;
|
||||||
|
|
||||||
private LocalSystemFileBrowser()
|
private LocalFileBrowser()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,9 +27,9 @@ namespace Image.Files
|
||||||
return Directory.GetFiles(directoryPath, "*.*");
|
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
|
namespace Image.Files
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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.
|
/// path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class KeepFilenameFormatter : IFileOutputFormatter
|
public class SimpleOutputSink : IOutputSink
|
||||||
{
|
{
|
||||||
public static ILogger Logger = NullLogger.Instance;
|
public static ILogger Logger = NullLogger.Instance;
|
||||||
private readonly string _outputDirectory;
|
private readonly string _outputDirectory;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an instance of OriginalFilenameFileOutputPathFormatter.
|
/// Creates an instance of SimpleOutputFormatter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="outputDirectory">The output directory.</param>
|
/// <param name="outputDirectory">The output directory.</param>
|
||||||
public KeepFilenameFormatter(string outputDirectory)
|
public SimpleOutputSink(string outputDirectory)
|
||||||
{
|
{
|
||||||
if (outputDirectory.Equals(""))
|
if (outputDirectory.Equals(""))
|
||||||
{
|
{
|
||||||
|
@ -46,9 +47,9 @@ namespace Image.Files
|
||||||
/// Creates an instance of OriginalFilenameFileOutputPathFormatter.
|
/// Creates an instance of OriginalFilenameFileOutputPathFormatter.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="outputDirectory">The output directory.</param>
|
/// <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;
|
if (_options.EnableCompression) compressor = LosslessCompressor.Instance;
|
||||||
|
|
||||||
Logger.LogDebug(
|
Logger.LogDebug(
|
||||||
$"Cleaning {filePath}, compression {_options.EnableCompression}, outputFormatter {nameof(_options.FileOutputFormatter)}.");
|
$"Cleaning {filePath}, compression {_options.EnableCompression}, outputFormatter {nameof(_options.OutputSink)}.");
|
||||||
IMetadataRemover metadataRemover = new ExifMetadataRemoverAndCompressor(imageMagick, compressor);
|
IMetadataRemover metadataRemover = new ExifRemoverAndCompressor(imageMagick, compressor);
|
||||||
metadataRemover.CleanImage(newFilePath);
|
metadataRemover.CleanImage(newFilePath);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ namespace Image.Tasks
|
||||||
foreach (var fileName in filenamesArray)
|
foreach (var fileName in filenamesArray)
|
||||||
{
|
{
|
||||||
var task = new Task<bool>(() =>
|
var task = new Task<bool>(() =>
|
||||||
CleanImage(fileName, _options.FileOutputFormatter.GetOutputPath(fileName)));
|
CleanImage(fileName, _options.OutputSink.GetOutputPath(fileName)));
|
||||||
tasks.Add(task);
|
tasks.Add(task);
|
||||||
task.Start();
|
task.Start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,16 +8,16 @@ namespace Image.Tasks
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TaskExecutorOptions
|
public class TaskExecutorOptions
|
||||||
{
|
{
|
||||||
private IFileOutputFormatter _fileOutputFormatter;
|
private IOutputSink _outputSink;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The file output path formatter. It cannot be null.
|
/// The file output path formatter. It cannot be null.
|
||||||
/// A implementation of <see cref="IFileOutputFormatter" />.
|
/// A implementation of <see cref="IOutputSink" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IFileOutputFormatter FileOutputFormatter
|
public IOutputSink OutputSink
|
||||||
{
|
{
|
||||||
get => _fileOutputFormatter;
|
get => _outputSink;
|
||||||
set => _fileOutputFormatter = value ?? throw new ArgumentException("Output formatter cannot be null!");
|
set => _outputSink = value ?? throw new ArgumentException("Output formatter cannot be null!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in a new issue