Skip to content

Commit 2b8b01c

Browse files
authored
Merge pull request #4 from plainerman/development
Minor improvements and additions
2 parents 2a3e8c5 + 3e68105 commit 2b8b01c

21 files changed

Lines changed: 273 additions & 70 deletions

‎TicTacTubeCore/Pipelines/BaseDataPipelineBuilder.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,9 @@ protected BaseDataPipelineBuilder()
4242
public IDataPipelineBuilder Append(IDataProcessorOrBuilder dataProcessorOrBuilder)
4343
{
4444
if (dataProcessorOrBuilder == null)
45-
{
4645
throw new ArgumentNullException(nameof(dataProcessorOrBuilder));
47-
}
4846
if (IsLocked)
49-
{
5047
throw new PipelineStateException("The pipeline is locked and cannot be modified.");
51-
}
5248

5349
InternalPipeline.Add(dataProcessorOrBuilder);
5450

‎TicTacTubeCore/Pipelines/DataPipeline.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public DataPipeline(ICollection<IDataProcessor> dataProcessors)
4141
public DataPipeline(IEnumerable<IDataProcessorOrBuilder> dataProcessorsOrBuilder)
4242
{
4343
DataProcessors = dataProcessorsOrBuilder?.Select(d => d.Build()).ToList() ??
44-
throw new ArgumentNullException(nameof(dataProcessorsOrBuilder));
44+
throw new ArgumentNullException(nameof(dataProcessorsOrBuilder));
4545
}
4646

4747
/// <inheritdoc />

‎TicTacTubeCore/Processors/Filesystem/SourceCloner.cs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ public override IFileSource Execute(IFileSource fileSoure)
4545

4646
string directory = Path.GetDirectoryName(dest);
4747
if (!Directory.Exists(directory))
48-
{
4948
Directory.CreateDirectory(directory);
50-
}
5149

5250
fileSoure.FileInfo.CopyTo(dest);
5351

‎TicTacTubeCore/Processors/Filesystem/SourceMover.cs‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using TicTacTubeCore.Processors.Definitions;
34
using TicTacTubeCore.Sources.Files;
45

@@ -9,6 +10,7 @@ namespace TicTacTubeCore.Processors.Filesystem
910
/// </summary>
1011
public class SourceMover : BaseDataProcessor
1112
{
13+
private readonly Func<IFileSource, string> _processingFunction;
1214
private readonly string _destinationPath;
1315
private readonly bool _keepName;
1416

@@ -33,16 +35,35 @@ public SourceMover(string destinationFolder, bool keepName)
3335
_keepName = true;
3436
}
3537

38+
/// <summary>
39+
/// Create a source mover that moves a source to another directory. The full
40+
/// path to the new file is created by the processing function.
41+
/// </summary>
42+
/// <param name="processingFunction">The processing function returns for a given <see cref="IFileSource"/>
43+
/// a full path to the new file.
44+
/// </param>
45+
public SourceMover(Func<IFileSource, string> processingFunction)
46+
{
47+
_processingFunction = processingFunction ?? throw new ArgumentNullException(nameof(processingFunction));
48+
}
49+
3650
/// <inheritdoc />
3751
public override IFileSource Execute(IFileSource fileSoure)
3852
{
39-
string dest = _keepName ? Path.Combine(_destinationPath, fileSoure.FileInfo.Name) : _destinationPath;
53+
string dest = _destinationPath;
54+
55+
if (_processingFunction != null)
56+
{
57+
dest = _processingFunction(fileSoure);
58+
}
59+
else if (_keepName)
60+
{
61+
dest = Path.Combine(_destinationPath, fileSoure.FileInfo.Name);
62+
}
4063

4164
string directory = Path.GetDirectoryName(dest);
4265
if (!Directory.Exists(directory))
43-
{
4466
Directory.CreateDirectory(directory);
45-
}
4667

4768
fileSoure.FileInfo.MoveTo(dest);
4869

‎TicTacTubeCore/Processors/Logical/ConditionalProcessor.cs‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ public ConditionalProcessor(Func<IFileSource, bool> condition, IDataProcessorOrB
2727
IDataProcessorOrBuilder dataProcessorB)
2828
{
2929
if (dataProcessorA == null && dataProcessorB == null)
30-
{
3130
throw new ArgumentNullException(nameof(dataProcessorA), "Both parameters may not be null.");
32-
}
3331

3432
_condition = condition ?? throw new ArgumentNullException(nameof(condition));
3533
_dataProcessorA = dataProcessorA;
@@ -58,16 +56,12 @@ public override IFileSource Execute(IFileSource fileSoure)
5856
if (eval)
5957
{
6058
if (_dataProcessorA != null)
61-
{
6259
return _dataProcessorA.Build().Execute(fileSoure);
63-
}
6460
}
6561
else
6662
{
6763
if (_dataProcessorB != null)
68-
{
6964
return _dataProcessorB.Build().Execute(fileSoure);
70-
}
7165
}
7266

7367
return fileSoure;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using TicTacTubeCore.Processors.Definitions;
3+
using TicTacTubeCore.Sources.Files;
4+
5+
namespace TicTacTubeCore.Processors.Logical
6+
{
7+
/// <summary>
8+
/// A debug processor that wraps any given processor and may make debugging easier.
9+
/// </summary>
10+
public class DebugProcessor : BaseDataProcessor
11+
{
12+
/// <summary>
13+
/// The internally wrapped data processor.
14+
/// </summary>
15+
public IDataProcessorOrBuilder DataProcessor { get; }
16+
17+
/// <summary>
18+
/// The amount of calls on execute.
19+
/// </summary>
20+
public int ExecutionCount { get; protected set; }
21+
22+
/// <summary>
23+
/// Create a new debug processor that wraps the given data processor.
24+
/// </summary>
25+
/// <param name="dataProcessor">The data processor that will actually be executed.</param>
26+
public DebugProcessor(IDataProcessorOrBuilder dataProcessor)
27+
{
28+
DataProcessor = dataProcessor ?? throw new ArgumentNullException(nameof(dataProcessor));
29+
}
30+
31+
/// <inheritdoc/>
32+
public override IFileSource Execute(IFileSource fileSoure)
33+
{
34+
var newFileSource = DataProcessor.Build().Execute(fileSoure);
35+
ExecutionCount++;
36+
37+
return newFileSource;
38+
}
39+
}
40+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using TicTacTubeCore.Processors.Definitions;
5+
using TicTacTubeCore.Sources.Files;
6+
7+
namespace TicTacTubeCore.Processors.Logical
8+
{
9+
/// <summary>
10+
/// A processor that is like a nested pipeline and also aggregates the file sources.
11+
/// </summary>
12+
public class MultiProcessor : BaseDataProcessor
13+
{
14+
/// <summary>
15+
/// Internally stored processors that will be executed.
16+
/// </summary>
17+
protected readonly IEnumerable<IDataProcessorOrBuilder> Processors;
18+
19+
/// <summary>
20+
/// Create a new multi processor (that acts like a nested pipeline) with given processors.
21+
/// </summary>
22+
/// <param name="processors">The processors that will be managed and processed.</param>
23+
public MultiProcessor(IEnumerable<IDataProcessorOrBuilder> processors)
24+
{
25+
if (processors == null) throw new ArgumentNullException(nameof(processors));
26+
27+
var dataProcessorOrBuilders = processors as IDataProcessorOrBuilder[] ?? processors.ToArray();
28+
29+
if (!dataProcessorOrBuilders.Any()) throw new ArgumentException("May not be empty.", nameof(processors));
30+
31+
Processors = dataProcessorOrBuilders;
32+
}
33+
34+
/// <inheritdoc />
35+
public override IFileSource Execute(IFileSource fileSoure)
36+
{
37+
return Processors.Aggregate(fileSoure,
38+
(current, dataProcessorOrBuilder) => dataProcessorOrBuilder.Build().Execute(current));
39+
}
40+
}
41+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using TicTacTubeCore.Processors.Definitions;
4+
using TicTacTubeCore.Sources.Files;
5+
6+
namespace TicTacTubeCore.Processors.Logical
7+
{
8+
/// <summary>
9+
/// This source splitter is capable of applying multiple processors to one source.
10+
/// </summary>
11+
public class SourceSplitter : BaseDataProcessor
12+
{
13+
/// <summary>
14+
/// The processors that will be executed.
15+
/// </summary>
16+
protected readonly IEnumerable<IDataProcessorOrBuilder> Processors;
17+
18+
/// <summary>
19+
/// Create a new source splitter that passes the given file source (the one from execute) to multiple params.
20+
/// If there is a following data processor in the pipeline, it receives an unmodified version of the filesource.
21+
/// </summary>
22+
/// <param name="processors">The processors that will be executed.</param>
23+
public SourceSplitter(IEnumerable<IDataProcessorOrBuilder> processors)
24+
{
25+
Processors = processors ?? throw new ArgumentNullException(nameof(processors));
26+
}
27+
28+
/// <inheritdoc />
29+
public override IFileSource Execute(IFileSource fileSoure)
30+
{
31+
foreach (var dataProcessorOrBuilder in Processors)
32+
dataProcessorOrBuilder.Build().Execute(fileSoure);
33+
34+
return fileSoure;
35+
}
36+
}
37+
}

‎TicTacTubeCore/Schedulers/EventFiringScheduler.cs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,9 @@ protected override void ExecuteStop()
3333
public virtual void Fire(IFileSource fileSource)
3434
{
3535
if (IsRunning)
36-
{
3736
Execute(fileSource);
38-
}
3937
else
40-
{
4138
throw new SchedulerStateException("The scheduler is not running.");
42-
}
4339
}
4440

4541
/// <summary>

‎TicTacTubeCore/Schedulers/Events/SchedulerLifeCycleEventArgs.cs‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ public enum SchedulerLifeCycleEventType
2929
/// </summary>
3030
public class SchedulerLifeCycleEventArgs : SchedulerEventArgs
3131
{
32-
/// <summary>
33-
/// The running state.Determines whether the scheduler is currently active or not.
34-
/// </summary>
35-
public bool IsRunning { get; }
36-
37-
/// <summary>
38-
/// The current lifecycle type (i.e. method that caused the event).
39-
/// </summary>
40-
public SchedulerLifeCycleEventType EventType { get; }
41-
4232
/// <summary>
4333
/// Create given event args with the current running state and the event type.
4434
/// </summary>
@@ -47,12 +37,20 @@ public class SchedulerLifeCycleEventArgs : SchedulerEventArgs
4737
public SchedulerLifeCycleEventArgs(bool isRunning, SchedulerLifeCycleEventType eventType)
4838
{
4939
if (!Enum.IsDefined(typeof(SchedulerLifeCycleEventType), eventType))
50-
{
5140
throw new InvalidEnumArgumentException(nameof(eventType), (int) eventType, typeof(SchedulerLifeCycleEventType));
52-
}
5341

5442
IsRunning = isRunning;
5543
EventType = eventType;
5644
}
45+
46+
/// <summary>
47+
/// The running state.Determines whether the scheduler is currently active or not.
48+
/// </summary>
49+
public bool IsRunning { get; }
50+
51+
/// <summary>
52+
/// The current lifecycle type (i.e. method that caused the event).
53+
/// </summary>
54+
public SchedulerLifeCycleEventType EventType { get; }
5755
}
5856
}

0 commit comments

Comments
 (0)