Skip to content

Commit

Permalink
Merge pull request #7 from plainerman/feature-genius-integration
Browse files Browse the repository at this point in the history
Feature genius integration
  • Loading branch information
plainerman authored Dec 12, 2017
2 parents 2484096 + f5577a6 commit a580bf4
Show file tree
Hide file tree
Showing 20 changed files with 292 additions and 114 deletions.
10 changes: 10 additions & 0 deletions TicTacTube.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
- <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_FOR/@EntryValue">Required</s:String>
- <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_FOREACH/@EntryValue">Required</s:String>
- <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_WHILE/@EntryValue">Required</s:String>
- <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/LOCAL_FUNCTION_BODY/@EntryValue">ExpressionBody</s:String>
- <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/METHOD_OR_OPERATOR_BODY/@EntryValue">ExpressionBody</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_ARRAY_RANK_EMPTY_BRACKETS/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_WITHIN_SINGLE_LINE_ARRAY_INITIALIZER_BRACES/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CSharpVarKeywordUsage/ForBuiltInTypes/@EntryValue">UseExplicitType</s:String>
<s:String x:Key="/Default/Environment/Hierarchy/PsiConfigurationSettingsKey/CustomLocation/@EntryValue">C:\Users\plain\AppData\Local\JetBrains\Transient\ReSharperPlatformVs15\v09_cf031b4e\SolutionCaches</s:String></wpf:ResourceDictionary>
17 changes: 8 additions & 9 deletions TicTacTubeCore/Processors/Filesystem/SourceMover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ namespace TicTacTubeCore.Processors.Filesystem
public class SourceMover : BaseDataProcessor
{
/// <summary>
/// The destination path or folder.
/// The destination path or folder.
/// </summary>
protected readonly string DestinationPath;

/// <summary>
/// <c>True</c>, if an existing destination should be overriden.
/// Whether the name should be kept (<see cref="DestinationPath" /> is a folder) or one is specified (
/// <see cref="DestinationPath" /> is a file).
/// </summary>
protected readonly bool Override;
protected readonly bool KeepName;

/// <summary>
/// Whether the name should be kept (<see cref="DestinationPath"/> is a folder) or one is specified (<see cref="DestinationPath"/> is a file).
/// <c>True</c>, if an existing destination should be overriden.
/// </summary>
protected readonly bool KeepName;
protected readonly bool Override;

/// <summary>
/// Create a source mover that moves a source to a complete path (also rename the file).
Expand Down Expand Up @@ -54,14 +57,10 @@ public override IFileSource Execute(IFileSource fileSoure)

string directory = Path.GetDirectoryName(dest);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}

if (Override && File.Exists(dest))
{
File.Delete(dest);
}

fileSoure.FileInfo.MoveTo(dest);

Expand Down
18 changes: 7 additions & 11 deletions TicTacTubeCore/Processors/Filesystem/SourceRenamer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ namespace TicTacTubeCore.Processors.Filesystem
public class SourceRenamer : BaseDataProcessor
{
/// <summary>
/// Whether an existing file will be overriden or not.
/// Whether an existing file will be overriden or not.
/// </summary>
protected readonly bool Override;

/// <summary>
/// A function that is capable of producing a new file name (with file extension) for a given file source. May not be
/// <c>null</c>.
/// </summary>
public Func<IFileSource, string> NameProducer { get; protected set; }

/// <summary>
/// Create a new source renamer, that renames files with a given renamer.
/// </summary>
Expand All @@ -46,6 +40,12 @@ protected SourceRenamer(bool @override = true)
Override = @override;
}

/// <summary>
/// A function that is capable of producing a new file name (with file extension) for a given file source. May not be
/// <c>null</c>.
/// </summary>
public Func<IFileSource, string> NameProducer { get; protected set; }

/// <inheritdoc />
public override IFileSource Execute(IFileSource fileSoure)
{
Expand All @@ -58,15 +58,11 @@ public override IFileSource Execute(IFileSource fileSoure)
string newFolderFullPath = Path.Combine(Path.Combine(fileSoure.FileInfo.DirectoryName), newFolder);

if (!Directory.Exists(newFolderFullPath))
{
Directory.CreateDirectory(newFolderFullPath);
}
}

if (Override && File.Exists(fullPath))
{
File.Delete(fullPath);
}

fileSoure.FileInfo.MoveTo(fullPath);

Expand Down
36 changes: 18 additions & 18 deletions TicTacTubeCore/Processors/Logical/DebugProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@
namespace TicTacTubeCore.Processors.Logical
{
/// <summary>
/// A debug processor that wraps any given processor and may make debugging easier.
/// A debug processor that wraps any given processor and may make debugging easier.
/// </summary>
public class DebugProcessor : BaseDataProcessor
{
public class DebugProcessor : BaseDataProcessor
{
/// <summary>
/// The internally wrapped data processor.
/// Create a new debug processor that wraps the given data processor.
/// </summary>
public IDataProcessorOrBuilder DataProcessor { get; }
/// <param name="dataProcessor">The data processor that will actually be executed.</param>
public DebugProcessor(IDataProcessorOrBuilder dataProcessor)
{
DataProcessor = dataProcessor ?? throw new ArgumentNullException(nameof(dataProcessor));
}

/// <summary>
/// The amount of calls on execute.
/// <summary>
/// The internally wrapped data processor.
/// </summary>
public int ExecutionCount { get; protected set; }
public IDataProcessorOrBuilder DataProcessor { get; }

/// <summary>
/// Create a new debug processor that wraps the given data processor.
/// The amount of calls on execute.
/// </summary>
/// <param name="dataProcessor">The data processor that will actually be executed.</param>
public DebugProcessor(IDataProcessorOrBuilder dataProcessor)
{
DataProcessor = dataProcessor ?? throw new ArgumentNullException(nameof(dataProcessor));
}
public int ExecutionCount { get; protected set; }

/// <inheritdoc/>
public override IFileSource Execute(IFileSource fileSoure)
/// <inheritdoc />
public override IFileSource Execute(IFileSource fileSoure)
{
var newFileSource = DataProcessor.Build().Execute(fileSoure);
ExecutionCount++;

return newFileSource;
}
}
}
}
}
2 changes: 2 additions & 0 deletions TicTacTubeCore/Processors/Logical/SourceSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public SourceSplitter(IEnumerable<IDataProcessorOrBuilder> processors)
public override IFileSource Execute(IFileSource fileSoure)
{
foreach (var dataProcessorOrBuilder in Processors)
{
dataProcessorOrBuilder.Build().Execute(fileSoure);
}

return fileSoure;
}
Expand Down
4 changes: 2 additions & 2 deletions TicTacTubeCore/Processors/Media/IMediaInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
public interface IMediaInfo
{
/// <summary>
/// Write the given media info as tags to the file. Previously stored information will be overriden.
/// If the format does not support tags, throw an exception.
/// Write the given media info as tags to the file. Previously stored information will be overriden.
/// If the format does not support tags, throw an exception.
/// </summary>
/// <param name="path">The path to the file where the tags will be written to.</param>
void WriteToFile(string path);
Expand Down
9 changes: 5 additions & 4 deletions TicTacTubeCore/Processors/Media/IMediaInfoExtractor.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
using TicTacTubeCore.Sources.Files;
using System.Threading.Tasks;
using TicTacTubeCore.Sources.Files;

namespace TicTacTubeCore.Processors.Media
{
/// <summary>
/// An extractor that is capable of generating MediaInfo from a given <see cref="IFileSource" />.
/// </summary>
public interface IMediaInfoExtractor<out T> where T : IMediaInfo
public interface IMediaInfoExtractor<T> where T : IMediaInfo
{
/// <summary>
/// Extract a given <see cref="IMediaInfo" /> from a given file source.
/// Extract a given <see cref="IMediaInfo" /> from a given file source asynchronously..
/// </summary>
/// <param name="source">The file source that will be analyzed.</param>
/// <returns>The newly created <see cref="IMediaInfo" />.</returns>
T Extract(IFileSource source);
Task<T> ExtractAsyncTask(IFileSource source);
}
}
7 changes: 4 additions & 3 deletions TicTacTubeCore/Processors/Media/MediaRenamer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class MediaRenamer<T> : SourceRenamer where T : IMediaInfo
/// <param name="nameGenerator">The name generator that generates the new file names.</param>
/// <param name="extractor">The extractor that extracts a media info from the file source.</param>
/// <param name="override"><c>True</c>, if an existing destination should be overriden.</param>
public MediaRenamer(IMediaNameGenerator<T> nameGenerator, IMediaInfoExtractor<T> extractor, bool @override = true) : base(@override)
public MediaRenamer(IMediaNameGenerator<T> nameGenerator, IMediaInfoExtractor<T> extractor, bool @override = true) :
base(@override)
{
NameGenerator = nameGenerator ?? throw new ArgumentNullException(nameof(nameGenerator));
MediaInfoExtractor = extractor ?? throw new ArgumentNullException(nameof(extractor));
Expand Down Expand Up @@ -57,7 +58,7 @@ public MediaRenamer(string pattern, IMediaInfoExtractor<T> extractor, bool @over
/// </summary>
/// <param name="source">The file source that will be parsed.</param>
/// <returns>The new filename for the file source (with the file extension).</returns>
protected virtual string ProduceName(IFileSource source) => NameGenerator.Parse(MediaInfoExtractor.Extract(source)) +
source.FileExtension;
protected virtual string ProduceName(IFileSource source) =>
NameGenerator.Parse(MediaInfoExtractor.ExtractAsyncTask(source).GetAwaiter().GetResult()) + source.FileExtension;
}
}
12 changes: 1 addition & 11 deletions TicTacTubeCore/Processors/Media/PatternMediaNameGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,9 @@ public string Parse(T info)

string currentAsString;
if (current is Array)
{
currentAsString = string.Join(", ", ((IEnumerable) current).Cast<object>().Select(o => o.ToString()));
}
else
{
currentAsString = current.ToString();
}
currentAsString = current?.ToString();
//= current is Array ? string.Join(", ", current) : current.ToString();

name = name.Replace($"{OpenBracket}{i}{CloseBracket}", currentAsString);
Expand All @@ -88,13 +84,9 @@ protected string PreparePattern(string pattern)
int closeCount = pattern.Count(f => f == CloseBracket);

if (openCount > closeCount)
{
throw new FormatException($"Bad formatting - {OpenBracket} missing.");
}
if (openCount < closeCount)
{
throw new FormatException($"Bad formatting - {CloseBracket} missing.");
}

var matches = CurlyBracketsMatcher.Matches(pattern);
var variableNames = new List<string>();
Expand All @@ -114,9 +106,7 @@ protected string PreparePattern(string pattern)
{
variableNames.Add(currentVar);
if (typeof(T).GetField(currentVar, BindingFlags.Public | BindingFlags.Instance) == null)
{
throw new FormatException($"Unknown parameter \"{currentVar}\"");
}
}

string replace = currentVarIndex.ToString();
Expand Down
Loading

0 comments on commit a580bf4

Please sign in to comment.