refactor: Load IDataStreamFactory(s) with dependency injection

So we can create ViewStreams that depend on other services, config, etc.
Previously, the PrimitiveManager relied purely on static construction of
types through reflection.
This commit is contained in:
John Colvin committed 2025-11-19 13:53:18 -05:00
1 parent 7566b2560f
commit ea0a1fbcd3
59 files changed
+2124 -161

No files matched your search

@@ -0,0 +1,54 @@
#nullable enable
namespace Bts.DataStreamCore;
using BCG;
using bts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
public interface IDataStreamMetadata {
public string Name { get; }
public IEnumerable<string> AlternateNames { get; }
}
public class DataStreamMetadata : IDataStreamMetadata {
public string? Name { get; set; }
public List<string>? AlternateNames { get; set; }
string IDataStreamMetadata.Name => Name ?? string.Empty;
IEnumerable<string> IDataStreamMetadata.AlternateNames =>
AlternateNames ?? new(0);
public static DataStreamMetadata FromType(Type type) {
var friendlyName = type.GetCustomAttribute<DataStreamUserRespresentation>()?.friendlyName;
var rv = new DataStreamMetadata() {
Name = friendlyName ?? type.Name,
AlternateNames = new(2) {
Log.notnull(type.FullName)
}
};
if (friendlyName is not null) {
rv.AlternateNames.Add(type.Name);
}
return rv;
}
}
public static class DataStreamMetadataExtensions {
public static bool IsMatch(this IDataStreamMetadata dsm, string name, bool checkAlternateNames = true, bool ignoreCase = true, bool ignoreUnderscores = true) {
var strComp = ignoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture;
var nameWithoutUnderscores = new Lazy<string>(() => RemoveUnderscores(name));
return IsNameMatch(dsm.Name) || (checkAlternateNames && dsm.AlternateNames.Any(IsNameMatch));
static string RemoveUnderscores(string s) =>
s.Replace("_", "");
bool IsNameMatch(string otherName) =>
string.Equals(name, otherName, strComp)
|| (ignoreUnderscores && string.Equals(nameWithoutUnderscores.Value, RemoveUnderscores(otherName), strComp));
}
}