Operations pipeline start

This commit is contained in:
Mikhail Shabanov committed 2020-07-19 13:04:31 +02:00
1 parent 6c10c6c654
commit 7ffbeb6b17
19 files changed
+432 -5

No files matched your search

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace WotBlitzStatisticsPro.Logic.Pipeline
{
public class Pipeline<TContext>: IPipeline<TContext>
{
private readonly IOperationFactory _operationFactory;
private readonly List<Type> _operations = new List<Type>();
public Pipeline(IOperationFactory operationFactory)
{
_operationFactory = operationFactory;
}
public IOperation<TContext> Build()
{
var allOperationTypes = _operations.ToArray();
var lastOperationType = allOperationTypes.LastOrDefault();
if (lastOperationType == null)
{
return null;
}
var nextOperation = new OperationMediator<TContext>(_operationFactory.Create<TContext>(lastOperationType), null);
for (int i = allOperationTypes.Length - 2; i >= 0; i--)
{
nextOperation = new OperationMediator<TContext>(_operationFactory.Create<TContext>(allOperationTypes[i]), nextOperation);
}
return nextOperation;
}
public IPipeline<TContext> AddOperation<TOperation>() where TOperation : IOperation<TContext>
{
_operations.Add(typeof(TOperation));
return this;
}
}
}