2021-02-08 16:51:19 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
namespace BililiveRecorder.Flv.Pipeline
|
|
|
|
{
|
|
|
|
public class ProcessingPipelineBuilder : IProcessingPipelineBuilder
|
|
|
|
{
|
|
|
|
public IServiceProvider ServiceProvider { get; }
|
|
|
|
|
|
|
|
private readonly List<Func<ProcessingDelegate, ProcessingDelegate>> rules = new List<Func<ProcessingDelegate, ProcessingDelegate>>();
|
|
|
|
|
|
|
|
public ProcessingPipelineBuilder(IServiceProvider serviceProvider)
|
|
|
|
{
|
|
|
|
this.ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
|
|
|
|
}
|
|
|
|
|
|
|
|
public IProcessingPipelineBuilder Add(Func<ProcessingDelegate, ProcessingDelegate> rule)
|
|
|
|
{
|
|
|
|
this.rules.Add(rule);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ProcessingDelegate Build()
|
2021-03-09 00:50:13 +08:00
|
|
|
=> this.rules.AsEnumerable().Reverse().Aggregate((ProcessingDelegate)(_ => { }), (i, o) => o(i));
|
2021-02-08 16:51:19 +08:00
|
|
|
}
|
|
|
|
}
|