| | 1 | | using Fluorite.Strainer.Exceptions; |
| | 2 | | using Fluorite.Strainer.Models; |
| | 3 | |
|
| | 4 | | namespace Fluorite.Strainer.Services.Pipelines; |
| | 5 | |
|
| | 6 | | public class StrainerPipeline : IStrainerPipeline |
| | 7 | | { |
| | 8 | | private readonly IEnumerable<IStrainerPipelineOperation> _operations; |
| | 9 | | private readonly IStrainerOptionsProvider _strainerOptionsProvider; |
| | 10 | |
|
| 10 | 11 | | public StrainerPipeline( |
| 10 | 12 | | IEnumerable<IStrainerPipelineOperation> operations, |
| 10 | 13 | | IStrainerOptionsProvider strainerOptionsProvider) |
| | 14 | | { |
| 10 | 15 | | Guard.Against.Null(operations); |
| 9 | 16 | | Guard.Against.Null(strainerOptionsProvider); |
| | 17 | |
|
| 8 | 18 | | _operations = operations; |
| 8 | 19 | | _strainerOptionsProvider = strainerOptionsProvider; |
| 8 | 20 | | } |
| | 21 | |
|
| | 22 | | public IQueryable<T> Run<T>(IStrainerModel model, IQueryable<T> source) |
| | 23 | | { |
| 7 | 24 | | Guard.Against.Null(model); |
| 6 | 25 | | Guard.Against.Null(source); |
| | 26 | |
|
| 5 | 27 | | var options = _strainerOptionsProvider.GetStrainerOptions(); |
| 5 | 28 | | var result = source; |
| | 29 | |
|
| | 30 | | try |
| | 31 | | { |
| 20 | 32 | | foreach (var operation in _operations) |
| | 33 | | { |
| 6 | 34 | | result = operation.Execute(model, result); |
| | 35 | | } |
| 3 | 36 | | } |
| 2 | 37 | | catch (StrainerException) when (!options.ThrowExceptions) |
| | 38 | | { |
| 1 | 39 | | return source; |
| | 40 | | } |
| | 41 | |
|
| 3 | 42 | | return result; |
| 1 | 43 | | } |
| | 44 | | } |