52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using BCG;
|
|
|
|
using bts;
|
|
|
|
using System;
|
|
using System.IO;
|
|
using System.Runtime.Serialization;
|
|
|
|
namespace BCG {
|
|
public class TestPubItem : IPubItem {
|
|
int i = 100;
|
|
|
|
|
|
public static string test_tag = "TestTag";
|
|
public string getTag() {
|
|
return test_tag;
|
|
}
|
|
|
|
public void to_stream(Stream str) {
|
|
BinaryWriter bw = new BinaryWriter(str);
|
|
//bw.Write(d);
|
|
bw.Write(i);
|
|
}
|
|
}
|
|
public class TestPublisher {
|
|
TestPubItem _tbi = new TestPubItem();
|
|
IPublisherCore pcore = new StaticPublisherCore();
|
|
bool _hit_key_to_send = false;
|
|
public TestPublisher(bool hit_key_to_send) {
|
|
_hit_key_to_send = hit_key_to_send;
|
|
bts.Log.Gen.info($"Started TestPubliser _hit_key_to_send: {_hit_key_to_send}");
|
|
}
|
|
|
|
public void keep_publishing(TimeSpan wait_per, int n_pubs = System.Int32.MaxValue) {
|
|
TestPubItem pi = new TestPubItem();
|
|
for (int i = 0; i < n_pubs; i++) {
|
|
if (_hit_key_to_send) {
|
|
Console.WriteLine("Hit key to send data");
|
|
Console.ReadLine();
|
|
}
|
|
MemoryStream ms = new MemoryStream();
|
|
pi.to_stream(ms);
|
|
ms.Position = 0;
|
|
pcore.beginTransaction();
|
|
pcore.publish(TestPubItem.test_tag, ms);
|
|
pcore.commitTransaction();
|
|
if (!_hit_key_to_send)
|
|
System.Threading.Thread.Sleep(wait_per);
|
|
}
|
|
}
|
|
}
|
|
} |