So we can create ViewStreams that depend on other services, config, etc. Previously, the PrimitiveManager relied purely on static construction of types through reflection.
28 lines
916 B
C#
28 lines
916 B
C#
#nullable enable
|
|
namespace Bts.DataStreamCore;
|
|
|
|
using BCG;
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
public class CompositeDataStreamFactory : IDataStreamFactory {
|
|
readonly List<IDataStreamFactory> streamFactories;
|
|
|
|
public CompositeDataStreamFactory(IEnumerable<IDataStreamFactory> streamFactories) {
|
|
this.streamFactories = streamFactories.ToList();
|
|
foreach (var rsf in this.streamFactories.OfType<IRecursiveDataStreamFactory>()) {
|
|
rsf.OnCompositeFactory(this);
|
|
}
|
|
}
|
|
|
|
public IEnumerable<IDataStreamMetadata> GetSupportedStreams() =>
|
|
streamFactories.SelectMany(f => f.GetSupportedStreams());
|
|
|
|
public ViewStream? Create(string streamId, IEnumerable<(string? Name, int? Index, object? Value)> args) =>
|
|
streamFactories.Where(f => f.CanCreate(streamId))
|
|
.Select(f => f.Create(streamId, args))
|
|
.ExceptNull()
|
|
.FirstOrDefault();
|
|
}
|