Skip to content

Commit 1c9c594

Browse files
committed
* Pipeline events
* Conveyor events
1 parent ccd1440 commit 1c9c594

File tree

8 files changed

+95
-8
lines changed

8 files changed

+95
-8
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Simplify.Pipelines.Processing
2+
{
3+
/// <summary>
4+
/// Provides pipeline related action delegate
5+
/// </summary>
6+
/// <typeparam name="T"></typeparam>
7+
/// <param name="item">The item.</param>
8+
public delegate void PipelineAction<in T>(T item);
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace Simplify.Pipelines.Processing
4+
{
5+
/// <summary>
6+
/// Provides pipeline stage action delegate
7+
/// </summary>
8+
/// <typeparam name="T"></typeparam>
9+
/// <param name="stageType">Type of the stage.</param>
10+
/// <param name="item">The item.</param>
11+
/// <param name="stageResult">Current pipeline executing stage result.</param>
12+
public delegate void PipelineStageAction<in T>(Type stageType, T item, bool stageResult);
13+
}

src/Simplify.Pipelines/Processing/Pipeline{T}.cs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using System.Collections.Generic;
2-
using System.Linq;
32

43
namespace Simplify.Pipelines.Processing
54
{
65
/// <summary>
76
/// Provides default pipeline
87
/// </summary>
98
/// <typeparam name="T"></typeparam>
10-
/// <seealso cref="Processing.IPipeline{T}" />
9+
/// <seealso cref="IPipeline{T}" />
1110
public class Pipeline<T> : IPipeline<T>
1211
{
1312
private readonly IList<IPipelineStage<T>> _stages;
@@ -21,15 +20,43 @@ public Pipeline(IList<IPipelineStage<T>> stages)
2120
_stages = stages;
2221
}
2322

23+
/// <summary>
24+
/// Occurs when pipeline is about to execute.
25+
/// </summary>
26+
public event PipelineAction<T> OnPipelineStart;
27+
28+
/// <summary>
29+
/// Occurs when pipeline has finished it's execution.
30+
/// </summary>
31+
public event PipelineAction<T> OnPipelineEnd;
32+
33+
/// <summary>
34+
/// Occurs when pipeline stage has finished it's execution.
35+
/// </summary>
36+
public event PipelineStageAction<T> OnStageExecuted;
37+
2438
/// <summary>
2539
/// Process pipeline stages.
2640
/// </summary>
2741
/// <param name="item">The item for execution.</param>
2842
/// <returns></returns>
29-
3043
public virtual bool Execute(T item)
3144
{
32-
return _stages.All(stage => stage.Execute(item));
45+
OnPipelineStart?.Invoke(item);
46+
47+
foreach (var stage in _stages)
48+
{
49+
var result = !stage.Execute(item);
50+
51+
OnStageExecuted?.Invoke(stage.GetType(), item, result);
52+
53+
if (result == false)
54+
return false;
55+
}
56+
57+
OnPipelineEnd?.Invoke(item);
58+
59+
return true;
3360
}
3461
}
3562
}

src/Simplify.Pipelines/Processing/ResultingPipeline{T}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Simplify.Pipelines.Processing
77
/// </summary>
88
/// <typeparam name="T"></typeparam>
99
/// <typeparam name="TResult">The type of the result.</typeparam>
10-
/// <seealso cref="Simplify.Pipelines.Processing.IResultingPipeline{T, TResult}" />
10+
/// <seealso cref="IResultingPipeline{T, TResult}" />
1111
public class ResultingPipeline<T, TResult> : IResultingPipeline<T, TResult>
1212
{
1313
private readonly IList<IResultingPipelineStage<T, TResult>> _stages;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Simplify.Pipelines.ProductionLine
2+
{
3+
/// <summary>
4+
/// Provides conveyor related action delegate
5+
/// </summary>
6+
/// <typeparam name="T"></typeparam>
7+
/// <param name="item">The item.</param>
8+
public delegate void ConveyorAction<in T>(T item);
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace Simplify.Pipelines.ProductionLine
4+
{
5+
/// <summary>
6+
/// Provides conveyor stage action delegate
7+
/// </summary>
8+
/// <typeparam name="T"></typeparam>
9+
/// <param name="stageType">Type of the stage.</param>
10+
/// <param name="item">The item.</param>
11+
public delegate void ConveyorStageAction<in T>(Type stageType, T item);
12+
}

src/Simplify.Pipelines/ProductionLine/Conveyor{T}.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,30 @@ public Conveyor(IList<IConveyorStage<T>> stages)
2222
_stages = stages ?? throw new ArgumentNullException(nameof(stages));
2323
}
2424

25+
/// <summary>
26+
/// Occurs when conveyor is about to execute.
27+
/// </summary>
28+
public event ConveyorAction<T> OnConveyorStart;
29+
30+
/// <summary>
31+
/// Occurs when conveyor stage has finished it's execution.
32+
/// </summary>
33+
public event ConveyorStageAction<T> OnStageExecuted;
34+
2535
/// <summary>
2636
/// Executes the specified item thru conveyor.
2737
/// </summary>
2838
/// <param name="item">The item.</param>
2939
public void Execute(T item)
3040
{
41+
OnConveyorStart?.Invoke(item);
42+
3143
foreach (var stage in _stages)
44+
{
3245
stage.Execute(item);
46+
47+
OnStageExecuted?.Invoke(stage.GetType(), item);
48+
}
3349
}
3450
}
3551
}

src/Simplify.Pipelines/Simplify.Pipelines.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
<Product>Simplify</Product>
66
<Description>Pipelines processing, validation patterns</Description>
77
<Copyright>Licensed under LGPL</Copyright>
8-
<Version>0.5.1</Version>
8+
<Version>0.6</Version>
99
<PackageProjectUrl>https://github.com/SimplifyNet/Simplify</PackageProjectUrl>
1010
<PackageIconUrl>https://raw.githubusercontent.com/SimplifyNet/Images/master/Logo.png</PackageIconUrl>
1111
<RepositoryUrl>https://github.com/SimplifyNet/Simplify/tree/master/src/Simplify.Pipelines</RepositoryUrl>
1212
<RepositoryType>GIT</RepositoryType>
1313
<PackageTags>.NET pipelines</PackageTags>
1414
<PackageReleaseNotes>
15-
Updates
16-
* Names refactored
15+
New
16+
* Pipeline events
17+
* Conveyor events
1718
</PackageReleaseNotes>
1819
<OutputPath>bin\Any CPU\$(Configuration)\</OutputPath>
1920
<DocumentationFile>bin\Any CPU\$(Configuration)\$(TargetFramework)\Simplify.Pipelines.xml</DocumentationFile>

0 commit comments

Comments
 (0)