cleanup: Fix indentation in PubsubHeartbeatStream.cs

This commit is contained in:
John Colvin committed 2026-02-21 14:10:11 -05:00
1 parent 5bc2e29096
commit 7f1154d70c
1 file changed
+67 -70
@@ -1,81 +1,78 @@
namespace bts {
using BCG;
using BCG.Utilities.General;
namespace bts;
using Bts.PubSub;
using Bts.SharedStreams.Tables;
using BCG;
using BCG.Utilities.General;
// TODO: Use dependency injection to instantiate this stream, and others like it that depend on
// ISubscriberCore(Factory). Until then, hide it from DSQA.
[DataStreamUserRespresentation(/*"pss_hb"*/ false)]
public class PubsubHeartbeatStream : ViewStream, IWorker {
private ViewStreamDatabase _vsd;
readonly ISubscriberCore _subcore;
PubSubHeartbeatRow? _row = null;
using Bts.PubSub;
using Bts.SharedStreams.Tables;
public PubsubHeartbeatStream(ISubscriberCoreFactory subscriberCore, ViewStreamDatabase vsd)
: this(subscriberCore.Create(), vsd) { }
// TODO: Use dependency injection to instantiate this stream, and others like it that depend on
// ISubscriberCore(Factory). Until then, hide it from DSQA.
[DataStreamUserRespresentation(/*"pss_hb"*/ false)]
public class PubsubHeartbeatStream : ViewStream, IWorker {
private ViewStreamDatabase _vsd;
readonly ISubscriberCore _subcore;
PubSubHeartbeatRow? _row = null;
PubsubHeartbeatStream(ISubscriberCore subscriberCore, ViewStreamDatabase vsd) {
_subcore = subscriberCore;
_vsd = vsd;
}
public PubsubHeartbeatStream(ISubscriberCoreFactory subscriberCore, ViewStreamDatabase vsd)
: this(subscriberCore.Create(), vsd) { }
static IBlueTableSchema _schema => PubSubHeartbeatRow.Schema;
PubsubHeartbeatStream(ISubscriberCore subscriberCore, ViewStreamDatabase vsd) {
_subcore = subscriberCore;
_vsd = vsd;
}
protected override void myOnFirstSubscriber() {
_subcore.subscribe("pss_hb");
_vsd.addWorker(this);
static IBlueTableSchema _schema => PubSubHeartbeatRow.Schema;
}
protected override void myOnFirstSubscriber() {
_subcore.subscribe("pss_hb");
_vsd.addWorker(this);
}
protected override void myOnLastSubscriber() {
_vsd.removeWorker(this);
_subcore.unsubscribe("pss_hb");
protected override void myOnLastSubscriber() {
_vsd.removeWorker(this);
_subcore.unsubscribe("pss_hb");
}
}
public void doWork() {
var updates = _subcore.get_updates(TimeSpan.FromMilliseconds(1));
if (updates.Count() > 0) {
foreach (var m in updates) {
if (m.data != null && m.data.Length > 0) {
BinaryReader br = new BinaryReader(new MemoryStream(m.data));
Int64 hb_sent_time = br.ReadInt64();
Int64 hb_recv_time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
// _row = _row == null ? new MutableBlueRow(_schema) : _row;
var now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
_row = new() {
Id = 0,
SendTime = hb_sent_time,
RecvTime = hb_recv_time,
Latency = hb_recv_time - hb_sent_time,
RecvElapsed = now - hb_recv_time,
};
// TODO, add to table and fire
}
}
} else {
if (_row != null) {
var now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
_row = new() {
Id = _row.Id,
SendTime = _row.SendTime,
RecvTime = _row.RecvTime,
Latency = _row.Latency,
RecvElapsed = now - _row.RecvTime,
};
// TODO, add to table and fire
}
// update the row
public void doWork() {
var updates = _subcore.get_updates(TimeSpan.FromMilliseconds(1));
if (updates.Count() > 0) {
foreach (var m in updates) {
if (m.data != null && m.data.Length > 0) {
BinaryReader br = new BinaryReader(new MemoryStream(m.data));
Int64 hb_sent_time = br.ReadInt64();
Int64 hb_recv_time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
// _row = _row == null ? new MutableBlueRow(_schema) : _row;
var now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
_row = new() {
Id = 0,
SendTime = hb_sent_time,
RecvTime = hb_recv_time,
Latency = hb_recv_time - hb_sent_time,
RecvElapsed = now - hb_recv_time,
};
// TODO, add to table and fire
}
if (_row != null) {
var bt = new BlueTable(_schema);
bt.addRow(_row);
var dp = BlueDataUtility.build_dp_inc(bt, myLastValue as IDataPacket, true);
myFireEvent(dp);
}
}
}
}
} else {
if (_row != null) {
var now = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
_row = new() {
Id = _row.Id,
SendTime = _row.SendTime,
RecvTime = _row.RecvTime,
Latency = _row.Latency,
RecvElapsed = now - _row.RecvTime,
};
// TODO, add to table and fire
}
// update the row
}
if (_row != null) {
var bt = new BlueTable(_schema);
bt.addRow(_row);
var dp = BlueDataUtility.build_dp_inc(bt, myLastValue as IDataPacket, true);
myFireEvent(dp);
}
}
}