Files
spark/src/DataStreamSuite/SharedStreams/NL/BlueOrbNLStream.cs
T
John Colvin ada7d4bed1 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.
2025-11-14 14:52:07 -05:00

46 lines
1.6 KiB
C#

namespace bts.BlueOrb {
using BCG;
using Bts.DataStreamCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
[DataStreamUserRespresentation(false)]
public class BlueOrbNLStream : ViewStream {
private readonly string _nl_prompt;
readonly IDataStreamFactory streamFactory;
private ViewStream _nl_to_dsl_stream, _dsl_stream;
private IDictionary<string, object> _dp_metadata = new Dictionary<string, object>();
public BlueOrbNLStream(string nl_prompt, IDataStreamFactory streamFactory) {
_nl_prompt = nl_prompt;
this.streamFactory = streamFactory;
}
protected override void myOnFirstSubscriber() {
_nl_to_dsl_stream = new BlueOrbNLToDSLStream(_nl_prompt);
_nl_to_dsl_stream.onChange += _handle_dsl_callback;
}
private void _handle_dsl_callback(object dp_obj) {
DataPacket dp = dp_obj as DataPacket;
var r = dp.newRows.to_list().ElementAt(0);
string dsl = r.get<string>("response");
_dp_metadata["dsl"] = dsl;
Log.Gen.info($"NLStream._handle_dsl_callback dsl: {dsl}");
_dsl_stream = new DSLStream(dsl, streamFactory);
_dsl_stream.onChange += _handle_data_cb;
}
private void _handle_data_cb(object dp_obj) {
var dp = dp_obj as DataPacket;
dp.meta_data = new Dictionary<string, object>(_dp_metadata);
DataPacket dp_out = BlueDataUtility.build_dp_inc(dp.newRows, myLastValue as DataPacket, true);
myFireEvent(dp_out);
}
}
}