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-14 14:52:07 -05:00
1 parent f65b6b82f2
commit ada7d4bed1
64 files changed
+2399 -147

No files matched your search

@@ -19,6 +19,8 @@ using Newtonsoft.Json;
using BCG;
using System.Runtime.CompilerServices;
using bts;
using Spark.Core;
using System.Numerics;
namespace bts {
@@ -91,13 +93,13 @@ namespace BCG {
return BlueDataUtility.get_row_datetime_value(r, col_no, err_value);
}
public static double? GetDouble(this IBlueRow r, int colNo) =>
GetDouble(r[colNo]);
public static double? GetFloat64(this IBlueRow r, int colNo) =>
GetFloat64(r[colNo]);
public static double? GetDouble(this IBlueRow r, string colName) =>
GetDouble(r[colName]);
public static double? GetFloat64(this IBlueRow r, string colName) =>
GetFloat64(r[colName]);
public static double? GetDouble(object obj) {
public static double? GetFloat64(object obj) {
if (obj is double d) {
return d;
}
@@ -125,6 +127,127 @@ namespace BCG {
return null;
}
public static int? GetInt32(this IBlueRow r, int colNo) =>
GetInt32(r[colNo]);
public static int? GetInt32(this IBlueRow r, string colName) =>
GetInt32(r[colName]);
public static int? GetInt32(object obj) {
checked {
if (obj is double d) {
return (int)d;
}
if (obj is int i32) {
return i32;
}
if (obj is long i64) {
return (int)i64;
}
if (obj is string s) {
return double.TryParse(s, out d) ? (int)d : null;
}
if (obj is uint u32) {
return (int)u32;
}
if (obj is ulong u64) {
return (int)u64;
}
if (obj is short i16) {
return i16;
}
if (obj is ushort u16) {
return u16;
}
}
return null;
}
public static long? GetInt64(this IBlueRow r, int colNo) =>
GetInt64(r[colNo]);
public static long? GetInt64(this IBlueRow r, string colName) =>
GetInt64(r[colName]);
public static long? GetInt64(object obj) {
checked {
if (obj is double d) {
return (long)d;
}
if (obj is int i32) {
return i32;
}
if (obj is long i64) {
return i64;
}
if (obj is string s) {
return double.TryParse(s, out d) ? (long)d : null;
}
if (obj is uint u32) {
return u32;
}
if (obj is ulong u64) {
return (long)u64;
}
if (obj is short i16) {
return i16;
}
if (obj is ushort u16) {
return u16;
}
}
return null;
}
public static DateTime? GetUnixEpochDateTime(this IBlueRow row, string colName) =>
GetUnixEpochDateTime(row[colName]);
public static DateTime? GetUnixEpochDateTime(this IBlueRow row, int colNo) =>
GetUnixEpochDateTime(row[colNo]);
public static DateTime? GetUnixEpochDateTime(object obj) {
var tsNanos = GetInt64(obj);
return tsNanos.HasValue ? DateTime.UnixEpoch.Add(new TimeSpan(tsNanos.Value / 100)) : null;
}
public static DateTime? GetDateTime(object obj) {
var res = _get_datetime_value(obj, DateTime.MinValue);
if (res == DateTime.MinValue) {
return null;
}
return res;
}
public static object GetEnum(Type type, object o) {
try {
if (o is null || o == DBNull.Value) {
return null;
} else if (o is string str) {
return Enum.TryParse(type, str, true, out var res) ? res : null;
} else if (o is int || o is uint || o is long || o is ulong || o is short || o is ushort) {
return Convert.ChangeType(o, type);
}
} catch {
}
return null;
}
public static T? GetEnum<T>(object o) where T : struct, Enum {
try {
if (o is null || o == DBNull.Value) {
return null;
} else if (o is string str) {
return Enum.TryParse(str, true, out T res) ? res : null;
} else if (o is int || o is short || o is ushort || o is uint || o is long || o is ulong)
return (T)o;
else if (o is T t) {
return t;
}
} catch {
}
return null;
}
public static T get_enum<T>(this IBlueRow r, string col_name, T err_value = default(T)) where T : struct {
return BlueDataUtility.get_row_enum_value<T>(r, col_name, err_value);
}