Reformat project structure
This commit is contained in:
parent
6f74af0f1d
commit
4c90086ae1
16 changed files with 42 additions and 33 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
|
||||
<PackageReference Include="Moq" Version="4.16.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using Image;
|
||||
using Image.Compressor;
|
||||
using Xunit;
|
||||
|
||||
namespace ImageCore.Tests
|
||||
|
|
|
@ -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<ArgumentException>(() => outputPathFormatter.GetOutputPath(""));
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using Image;
|
||||
using Image.Files;
|
||||
using Xunit;
|
||||
|
||||
namespace ImageCore.Tests
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
namespace Image
|
||||
namespace Image.Compressor
|
||||
{
|
||||
/// <summary>
|
||||
/// ICompressor is an interface for implementing image compressors.
|
|
@ -1,6 +1,6 @@
|
|||
using ImageMagick;
|
||||
|
||||
namespace Image
|
||||
namespace Image.Compressor
|
||||
{
|
||||
/// <summary>
|
||||
/// LosslessCompressor compresses an image using lossless compression provided by ImageMagick.
|
|
@ -1,4 +1,4 @@
|
|||
namespace Image
|
||||
namespace Image.Compressor
|
||||
{
|
||||
/// <summary>
|
||||
/// Does nothing. Using this Compressor will have no effect.
|
|
@ -1,6 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace Image
|
||||
namespace Image.Files
|
||||
{
|
||||
/// <summary>
|
||||
/// An to interface enabling implementation of filename retrievers.
|
|
@ -3,7 +3,7 @@ using System.IO;
|
|||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace Image
|
||||
namespace Image.Files
|
||||
{
|
||||
/// <summary>
|
||||
/// LocalSystemFilesRetriever reads files from the provided directory on the local system.
|
|
@ -1,9 +1,9 @@
|
|||
namespace Image
|
||||
namespace Image.Output
|
||||
{
|
||||
/// <summary>
|
||||
/// IOutputFormatter is an interface for generating the output path and destination file name.
|
||||
/// </summary>
|
||||
public interface IFileOutputPathFormatter
|
||||
public interface IFileOutputFormatter
|
||||
{
|
||||
/// <summary>
|
||||
/// Generates an absolute output path given the initial absolute file path.
|
|
@ -3,13 +3,13 @@ using GuardNet;
|
|||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace Image
|
||||
namespace Image.Output
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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.
|
||||
/// </summary>
|
||||
/// <param name="outputDirectory">The output directory.</param>
|
||||
public OriginalFilenameFileOutputPathFormatter(string outputDirectory)
|
||||
public KeepFilenameFormatter(string outputDirectory)
|
||||
{
|
||||
if (outputDirectory.Equals(""))
|
||||
{
|
||||
|
@ -44,9 +44,9 @@ namespace Image
|
|||
/// Creates an instance of OriginalFilenameFileOutputPathFormatter.
|
||||
/// </summary>
|
||||
/// <param name="outputDirectory">The output directory.</param>
|
||||
public static OriginalFilenameFileOutputPathFormatter Create(string outputDirectory)
|
||||
public static KeepFilenameFormatter Create(string outputDirectory)
|
||||
{
|
||||
return new OriginalFilenameFileOutputPathFormatter(outputDirectory);
|
||||
return new KeepFilenameFormatter(outputDirectory);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,11 +1,12 @@
|
|||
using ImageMagick;
|
||||
using Image.Compressor;
|
||||
using ImageMagick;
|
||||
|
||||
namespace Image
|
||||
namespace Image.Remover
|
||||
{
|
||||
/// <summary>
|
||||
/// MetadataRemover removes metadata from an image. The exif profile.
|
||||
/// </summary>
|
||||
public class MetadataRemover : IMetadataRemover
|
||||
public class ExifMetadataRemoverAndCompressor : IMetadataRemover
|
||||
{
|
||||
private readonly ICompressor _compressor;
|
||||
private readonly IMagickImage _magickImage;
|
||||
|
@ -15,7 +16,7 @@ namespace Image
|
|||
/// </summary>
|
||||
/// <param name="magickImage">MagicImage instance.</param>
|
||||
/// <param name="compressor">Compressor instance.</param>
|
||||
public MetadataRemover(IMagickImage magickImage, ICompressor compressor)
|
||||
public ExifMetadataRemoverAndCompressor(IMagickImage magickImage, ICompressor compressor)
|
||||
{
|
||||
_magickImage = magickImage;
|
||||
_compressor = compressor;
|
|
@ -1,4 +1,4 @@
|
|||
namespace Image
|
||||
namespace Image.Remover
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for implementing metadata removers.
|
|
@ -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<bool>(() =>
|
||||
CleanImage(fileName, _options.FileOutputPathFormatter.GetOutputPath(fileName)));
|
||||
CleanImage(fileName, _options.FileOutputFormatter.GetOutputPath(fileName)));
|
||||
tasks.Add(task);
|
||||
task.Start();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using Image.Output;
|
||||
|
||||
namespace Image
|
||||
{
|
||||
|
@ -7,16 +8,16 @@ namespace Image
|
|||
/// </summary>
|
||||
public class TaskExecutorOptions
|
||||
{
|
||||
private IFileOutputPathFormatter _fileOutputPathFormatter;
|
||||
private IFileOutputFormatter _fileOutputFormatter;
|
||||
|
||||
/// <summary>
|
||||
/// The file output path formatter. It cannot be null.
|
||||
/// A implementation of <see cref="IFileOutputPathFormatter" />.
|
||||
/// A implementation of <see cref="IFileOutputFormatter" />.
|
||||
/// </summary>
|
||||
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!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in a new issue