11using System . Collections . Generic ;
2- using System . Linq ;
32
43namespace 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}
0 commit comments