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 System.IO;
|
||||||
using CommandLine;
|
using CommandLine;
|
||||||
using Image;
|
using Image;
|
||||||
|
using Image.Files;
|
||||||
|
using Image.Output;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
||||||
|
@ -31,15 +33,15 @@ namespace ConsoleInterface
|
||||||
var loggerFactory = LoggerFactory.Create(b => b.AddConsole());
|
var loggerFactory = LoggerFactory.Create(b => b.AddConsole());
|
||||||
TaskExecutor.Logger = loggerFactory.CreateLogger(nameof(TaskExecutor));
|
TaskExecutor.Logger = loggerFactory.CreateLogger(nameof(TaskExecutor));
|
||||||
LocalSystemFilesRetriever.Logger = loggerFactory.CreateLogger(nameof(LocalSystemFilesRetriever));
|
LocalSystemFilesRetriever.Logger = loggerFactory.CreateLogger(nameof(LocalSystemFilesRetriever));
|
||||||
OriginalFilenameFileOutputPathFormatter.Logger =
|
KeepFilenameFormatter.Logger =
|
||||||
loggerFactory.CreateLogger(nameof(OriginalFilenameFileOutputPathFormatter));
|
loggerFactory.CreateLogger(nameof(KeepFilenameFormatter));
|
||||||
|
|
||||||
CreateDestinationDirectory(options.DestinationDirectory);
|
CreateDestinationDirectory(options.DestinationDirectory);
|
||||||
var outputFormatter = OriginalFilenameFileOutputPathFormatter.Create(options.DestinationDirectory);
|
var outputFormatter = KeepFilenameFormatter.Create(options.DestinationDirectory);
|
||||||
var executor = TaskExecutor.Create(new TaskExecutorOptions
|
var executor = TaskExecutor.Create(new TaskExecutorOptions
|
||||||
{
|
{
|
||||||
EnableCompression = options.CompressFiles is true,
|
EnableCompression = options.CompressFiles is true,
|
||||||
FileOutputPathFormatter = outputFormatter
|
FileOutputFormatter = outputFormatter
|
||||||
});
|
});
|
||||||
var filesRetriever = LocalSystemFilesRetriever.Create();
|
var filesRetriever = LocalSystemFilesRetriever.Create();
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
|
<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" Version="2.4.1" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.Cryptography;
|
|
||||||
using Image;
|
using Image;
|
||||||
|
using Image.Compressor;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace ImageCore.Tests
|
namespace ImageCore.Tests
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using Image;
|
using Image;
|
||||||
|
using Image.Output;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace ImageCore.Tests
|
namespace ImageCore.Tests
|
||||||
|
@ -14,14 +15,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 = OriginalFilenameFileOutputPathFormatter.Create(directory);
|
var outputPathFormatter = KeepFilenameFormatter.Create(directory);
|
||||||
Assert.Equal(expectedPath, outputPathFormatter.GetOutputPath(file));
|
Assert.Equal(expectedPath, outputPathFormatter.GetOutputPath(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestGetOutputPathNull()
|
public void TestGetOutputPathNull()
|
||||||
{
|
{
|
||||||
var outputPathFormatter = OriginalFilenameFileOutputPathFormatter.Create("directory");
|
var outputPathFormatter = KeepFilenameFormatter.Create("directory");
|
||||||
Assert.Throws<ArgumentException>(() => outputPathFormatter.GetOutputPath(""));
|
Assert.Throws<ArgumentException>(() => outputPathFormatter.GetOutputPath(""));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Image;
|
using Image;
|
||||||
|
using Image.Files;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace ImageCore.Tests
|
namespace ImageCore.Tests
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Image
|
namespace Image.Compressor
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// ICompressor is an interface for implementing image compressors.
|
/// ICompressor is an interface for implementing image compressors.
|
|
@ -1,6 +1,6 @@
|
||||||
using ImageMagick;
|
using ImageMagick;
|
||||||
|
|
||||||
namespace Image
|
namespace Image.Compressor
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LosslessCompressor compresses an image using lossless compression provided by ImageMagick.
|
/// LosslessCompressor compresses an image using lossless compression provided by ImageMagick.
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Image
|
namespace Image.Compressor
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Does nothing. Using this Compressor will have no effect.
|
/// Does nothing. Using this Compressor will have no effect.
|
|
@ -1,6 +1,6 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Image
|
namespace Image.Files
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// An to interface enabling implementation of filename retrievers.
|
/// An to interface enabling implementation of filename retrievers.
|
|
@ -3,7 +3,7 @@ using System.IO;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
||||||
namespace Image
|
namespace Image.Files
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LocalSystemFilesRetriever reads files from the provided directory on the local system.
|
/// LocalSystemFilesRetriever reads files from the provided directory on the local system.
|
|
@ -1,9 +1,9 @@
|
||||||
namespace Image
|
namespace Image.Output
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// IOutputFormatter is an interface for generating the output path and destination file name.
|
/// IOutputFormatter is an interface for generating the output path and destination file name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IFileOutputPathFormatter
|
public interface IFileOutputFormatter
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generates an absolute output path given the initial absolute file path.
|
/// 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;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
|
||||||
namespace Image
|
namespace Image.Output
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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.
|
/// path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OriginalFilenameFileOutputPathFormatter : IFileOutputPathFormatter
|
public class KeepFilenameFormatter : IFileOutputFormatter
|
||||||
{
|
{
|
||||||
public static ILogger Logger = NullLogger.Instance;
|
public static ILogger Logger = NullLogger.Instance;
|
||||||
private readonly string _outputDirectory;
|
private readonly string _outputDirectory;
|
||||||
|
@ -18,7 +18,7 @@ namespace Image
|
||||||
/// 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 OriginalFilenameFileOutputPathFormatter(string outputDirectory)
|
public KeepFilenameFormatter(string outputDirectory)
|
||||||
{
|
{
|
||||||
if (outputDirectory.Equals(""))
|
if (outputDirectory.Equals(""))
|
||||||
{
|
{
|
||||||
|
@ -44,9 +44,9 @@ namespace Image
|
||||||
/// 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 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>
|
/// <summary>
|
||||||
/// MetadataRemover removes metadata from an image. The exif profile.
|
/// MetadataRemover removes metadata from an image. The exif profile.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class MetadataRemover : IMetadataRemover
|
public class ExifMetadataRemoverAndCompressor : IMetadataRemover
|
||||||
{
|
{
|
||||||
private readonly ICompressor _compressor;
|
private readonly ICompressor _compressor;
|
||||||
private readonly IMagickImage _magickImage;
|
private readonly IMagickImage _magickImage;
|
||||||
|
@ -15,7 +16,7 @@ namespace Image
|
||||||
/// </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 MetadataRemover(IMagickImage magickImage, ICompressor compressor)
|
public ExifMetadataRemoverAndCompressor(IMagickImage magickImage, ICompressor compressor)
|
||||||
{
|
{
|
||||||
_magickImage = magickImage;
|
_magickImage = magickImage;
|
||||||
_compressor = compressor;
|
_compressor = compressor;
|
|
@ -1,4 +1,4 @@
|
||||||
namespace Image
|
namespace Image.Remover
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface for implementing metadata removers.
|
/// Interface for implementing metadata removers.
|
|
@ -2,6 +2,8 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Image.Compressor;
|
||||||
|
using Image.Remover;
|
||||||
using ImageMagick;
|
using ImageMagick;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
|
@ -50,8 +52,8 @@ namespace Image
|
||||||
if (_options.EnableCompression) compressor = LosslessCompressor.Instance;
|
if (_options.EnableCompression) compressor = LosslessCompressor.Instance;
|
||||||
|
|
||||||
Logger.LogDebug(
|
Logger.LogDebug(
|
||||||
$"Cleaning {fileName}, compression {_options.EnableCompression}, outputFormatter {nameof(_options.FileOutputPathFormatter)}.");
|
$"Cleaning {fileName}, compression {_options.EnableCompression}, outputFormatter {nameof(_options.FileOutputFormatter)}.");
|
||||||
IMetadataRemover metadataRemover = new MetadataRemover(imageMagick, compressor);
|
IMetadataRemover metadataRemover = new ExifMetadataRemoverAndCompressor(imageMagick, compressor);
|
||||||
metadataRemover.CleanImage(newFilename);
|
metadataRemover.CleanImage(newFilename);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +82,7 @@ namespace Image
|
||||||
foreach (var fileName in filenamesArray)
|
foreach (var fileName in filenamesArray)
|
||||||
{
|
{
|
||||||
var task = new Task<bool>(() =>
|
var task = new Task<bool>(() =>
|
||||||
CleanImage(fileName, _options.FileOutputPathFormatter.GetOutputPath(fileName)));
|
CleanImage(fileName, _options.FileOutputFormatter.GetOutputPath(fileName)));
|
||||||
tasks.Add(task);
|
tasks.Add(task);
|
||||||
task.Start();
|
task.Start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using Image.Output;
|
||||||
|
|
||||||
namespace Image
|
namespace Image
|
||||||
{
|
{
|
||||||
|
@ -7,16 +8,16 @@ namespace Image
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TaskExecutorOptions
|
public class TaskExecutorOptions
|
||||||
{
|
{
|
||||||
private IFileOutputPathFormatter _fileOutputPathFormatter;
|
private IFileOutputFormatter _fileOutputFormatter;
|
||||||
|
|
||||||
/// <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="IFileOutputPathFormatter" />.
|
/// A implementation of <see cref="IFileOutputFormatter" />.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IFileOutputPathFormatter FileOutputPathFormatter
|
public IFileOutputFormatter FileOutputFormatter
|
||||||
{
|
{
|
||||||
get => _fileOutputPathFormatter;
|
get => _fileOutputFormatter;
|
||||||
set => _fileOutputPathFormatter = value ?? throw new ArgumentException("Output formatter cannot be null!");
|
set => _fileOutputFormatter = value ?? throw new ArgumentException("Output formatter cannot be null!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in a new issue