49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using BCG;
|
|
|
|
using bts;
|
|
|
|
using System;
|
|
|
|
namespace BCG {
|
|
// this is a stream so we can run it from the DSQA (since dsqa can only load streams)
|
|
[DataStreamUserRespresentation("remoteQuery")]
|
|
public class RemoteQueryStream : ViewStream {
|
|
private readonly string _name, _stream_exp;
|
|
private PublisherCore _publisher_core = new PublisherCore();
|
|
private ViewStream _source_str;
|
|
|
|
public RemoteQueryStream(params string[] lines) {
|
|
_stream_exp = get_expression(lines);
|
|
_name = Guid.NewGuid().ToString();
|
|
_name = $"remotereq_{DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString()}";
|
|
//_name.Replace("-", "_");
|
|
|
|
}
|
|
|
|
protected override void myOnFirstSubscriber() {
|
|
RemoteRequest rem_req = new RemoteRequest(_stream_exp, _name);
|
|
byte[] rem_req_bytes = rem_req.serialize();
|
|
_publisher_core.publish("System", "RemoteRequest", rem_req_bytes);
|
|
_source_str = new TableStream(_name);
|
|
_source_str.onChange += new ChangeDelegate(_handle_data);
|
|
}
|
|
|
|
protected override void myOnLastSubscriber() {
|
|
//maybe there should be a way to turn remote requests off ?
|
|
_source_str.onChange -= new ChangeDelegate(_handle_data);
|
|
}
|
|
|
|
static string get_expression(params string[] lines) {
|
|
for (int i = 0; i < lines.Length; i++) {
|
|
// unescape quotes
|
|
lines[i] = lines[i].Replace("\\\"", "\"");
|
|
}
|
|
return string.Join("\n", lines);
|
|
}
|
|
|
|
private void _handle_data(object o) {
|
|
myFireEvent(o);
|
|
}
|
|
}
|
|
}
|